Variouse BugFixes and additions.
-Fixed: Bugs in Mappers causing problems when parsing library. -Fixed: IConditon should throw a error with 0 arguments. -Added: CacheFile is now sorted so you can remove caches easier. -Removed: Unnessesary code. -Added: Counters. -Added: Gitignore
This commit is contained in:
parent
0f00ad1771
commit
54e66d7f53
|
@ -1,5 +1,6 @@
|
|||
# ---> Gradle
|
||||
.gradle
|
||||
settings.gradle
|
||||
**/build/
|
||||
!src/**/build/
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ public class ConditionedSegment
|
|||
ConditionedSegment segment = new ConditionedSegment(startIndex);
|
||||
ICondition condition = ICondition.parse(currentLine);
|
||||
List<ConditionedSegment> childSegments = new ArrayList<>();
|
||||
StringJoiner segmentText = new StringJoiner("\n", "\n", "");
|
||||
StringJoiner segmentText = new StringJoiner("\n", (currentIndex <= 0 || includeStartNewLine(lines.get(currentIndex-1).trim())) ? "\n" : "", "");
|
||||
for(int i = currentIndex+1;i<lines.size();i++)
|
||||
{
|
||||
String s = lines.get(i);
|
||||
|
@ -80,4 +80,8 @@ public class ConditionedSegment
|
|||
throw new IllegalStateException("Unclosed #If found in ["+fileName+"] at line ["+startIndex+"]");
|
||||
}
|
||||
|
||||
static boolean includeStartNewLine(String s)
|
||||
{
|
||||
return !s.startsWith("#") || s.equalsIgnoreCase("#endif");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ public interface ICondition
|
|||
}
|
||||
switch(conditions.size())
|
||||
{
|
||||
case 0: return ALWAYS_TRUE;
|
||||
case 0: throw new IllegalStateException("Empty Conditions are not allowed");
|
||||
case 1: return conditions.get(0);
|
||||
default: return new OrCondition(conditions);
|
||||
}
|
||||
|
|
|
@ -50,11 +50,14 @@ public class ArgumentMapper implements IMapper
|
|||
public String apply(String t)
|
||||
{
|
||||
Matcher matcher = pattern.matcher(t);
|
||||
try
|
||||
{
|
||||
if(matcher.find())
|
||||
{
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
do
|
||||
{
|
||||
if(matcher.end() < RegexUtil.getLastAppendPosition(matcher)) return apply(matcher.appendTail(buffer).toString());
|
||||
String text = RegexUtil.searchUntil(t, matcher.end()-1, braces.charAt(0), braces.charAt(1));
|
||||
if(!text.isEmpty())
|
||||
{
|
||||
|
@ -66,6 +69,11 @@ public class ArgumentMapper implements IMapper
|
|||
matcher.appendTail(buffer);
|
||||
return buffer.toString();
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
|
|
|
@ -48,11 +48,14 @@ public class InjectMapper implements IMapper
|
|||
public String apply(String t)
|
||||
{
|
||||
Matcher matcher = pattern.matcher(t);
|
||||
try
|
||||
{
|
||||
if(matcher.find())
|
||||
{
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
do
|
||||
{
|
||||
if(matcher.end() < RegexUtil.getLastAppendPosition(matcher)) return apply(matcher.appendTail(buffer).toString());
|
||||
String text = RegexUtil.searchUntil(t, matcher.end()-1, braces.charAt(0), braces.charAt(1));
|
||||
if(!text.isEmpty())
|
||||
{
|
||||
|
@ -63,6 +66,11 @@ public class InjectMapper implements IMapper
|
|||
matcher.appendTail(buffer);
|
||||
return buffer.toString();
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
|
|
|
@ -6,9 +6,10 @@ import java.io.InputStream;
|
|||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.security.MessageDigest;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
public class FileUtils
|
||||
{
|
||||
|
@ -40,9 +41,11 @@ public class FileUtils
|
|||
{
|
||||
try(BufferedWriter writer = Files.newBufferedWriter(dataFolder.resolve("cache.bin")))
|
||||
{
|
||||
for(Entry<String, String> entry : mappings.entrySet())
|
||||
List<String> keys = new ArrayList<String>(mappings.keySet());
|
||||
keys.sort(String.CASE_INSENSITIVE_ORDER);
|
||||
for(String s : keys)
|
||||
{
|
||||
writer.write(entry.getKey()+"="+entry.getValue());
|
||||
writer.write(s+"="+mappings.get(s));
|
||||
writer.newLine();
|
||||
}
|
||||
writer.flush();
|
||||
|
|
|
@ -20,6 +20,18 @@ public class RegexUtil
|
|||
return matcher;
|
||||
}
|
||||
|
||||
public static int getLastAppendPosition(Matcher matcher)
|
||||
{
|
||||
try
|
||||
{
|
||||
return LAST_POS.getInt(matcher);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static String searchUntil(String text, int startIndex, char increase, char decrease)
|
||||
{
|
||||
if(text.charAt(startIndex + 1) != increase)
|
||||
|
|
|
@ -11,6 +11,7 @@ import java.util.Set;
|
|||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
@ -56,6 +57,7 @@ public abstract class TemplateProcessor
|
|||
System.out.println("Nothing has changed");
|
||||
return false;
|
||||
}
|
||||
AtomicLong[] counters = new AtomicLong[]{new AtomicLong(), new AtomicLong(), new AtomicLong()};
|
||||
final boolean relative = relativePackages();
|
||||
Set<IMapper>[] mappers = debugUnusedMappers() ? new Set[]{Collections.synchronizedSet(new HashSet<IMapper>()), Collections.synchronizedSet(new HashSet<IMapper>())} : null;
|
||||
ThreadPoolExecutor service = (ThreadPoolExecutor)Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
|
||||
|
@ -67,8 +69,11 @@ public abstract class TemplateProcessor
|
|||
Path path = pathsLeft.get(i);
|
||||
try
|
||||
{
|
||||
long startTime = System.currentTimeMillis();
|
||||
Template template = Template.parse(path);
|
||||
createProcesses(FileUtils.getFileName(path), T -> service.execute(new BuildTask(relative ? outputFolder.resolve(sourceFolder.relativize(path).getParent()) : outputFolder, template, T, mappers)));
|
||||
counters[2].addAndGet(System.currentTimeMillis() - startTime);
|
||||
counters[1].addAndGet(1);
|
||||
createProcesses(FileUtils.getFileName(path), T -> {service.execute(new BuildTask(relative ? outputFolder.resolve(sourceFolder.relativize(path).getParent()) : outputFolder, template, T, mappers));counters[0].addAndGet(1);});
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
|
@ -95,7 +100,7 @@ public abstract class TemplateProcessor
|
|||
System.out.println("Mapper ["+mapper.getSearchValue()+"] is not used in the Entire Build Process");
|
||||
}
|
||||
}
|
||||
System.out.println("Finished Tasks: "+(System.currentTimeMillis() - start)+"ms");
|
||||
System.out.println("Finished Building ["+counters[0].get()+"] Files from ["+counters[1].get()+"] in "+(System.currentTimeMillis() - start)+"ms (Template Parsing: "+counters[2].get()+"ms (avg: "+((counters[2].get() / Math.max(1D, counters[1].get())))+"ms)");
|
||||
FileUtils.saveMappings(existing, dataFolder);
|
||||
System.out.print("Saved Changes");
|
||||
return true;
|
||||
|
|
Loading…
Reference in New Issue