diff --git a/build.gradle b/build.gradle index 5f8ea61..e8be383 100644 --- a/build.gradle +++ b/build.gradle @@ -1,24 +1,24 @@ -apply plugin: 'java-library' - -repositories { - jcenter() -} - -archivesBaseName = 'Simple Code Generator' -version = '1.0' - -tasks.withType(JavaCompile) { - options.encoding = 'UTF-8' -} - -dependencies { -} - -task srcJar(type: Jar) { - from sourceSets.main.allSource - classifier = 'sources' -} - -artifacts { - archives srcJar +apply plugin: 'java-library' + +repositories { + jcenter() +} + +archivesBaseName = 'Simple Code Generator' +version = '1.0.1' + +tasks.withType(JavaCompile) { + options.encoding = 'UTF-8' +} + +dependencies { +} + +task srcJar(type: Jar) { + from sourceSets.main.allSource + classifier = 'sources' +} + +artifacts { + archives srcJar } \ No newline at end of file diff --git a/src/main/java/speiger/src/builder/base/Template.java b/src/main/java/speiger/src/builder/base/Template.java index f1698ef..05567ea 100644 --- a/src/main/java/speiger/src/builder/base/Template.java +++ b/src/main/java/speiger/src/builder/base/Template.java @@ -7,8 +7,8 @@ import java.util.ArrayList; import java.util.List; import java.util.Set; import java.util.StringJoiner; -import java.util.function.UnaryOperator; +import speiger.src.builder.mappers.IMapper; import speiger.src.builder.misc.FileUtils; public class Template @@ -29,7 +29,7 @@ public class Template return fileName; } - public String build(Set parsePool, List> mappers) + public String build(Set parsePool, List mappers, boolean printNoWork, Set done) { StringBuilder builder = new StringBuilder(textFile); for(int i = 0,offset=0,m=segments.size();i +public class ArgumentMapper implements IMapper { + String searchValue; Pattern pattern; String replacement; String argumentBreaker; @@ -16,6 +16,12 @@ public class ArgumentMapper implements UnaryOperator public ArgumentMapper(String pattern, String replacement, String argumentBreaker) { + this(pattern, pattern, replacement, argumentBreaker); + } + + public ArgumentMapper(String searchValue, String pattern, String replacement, String argumentBreaker) + { + this.searchValue = searchValue; this.pattern = Pattern.compile(pattern); this.replacement = replacement; this.argumentBreaker = argumentBreaker; @@ -34,6 +40,12 @@ public class ArgumentMapper implements UnaryOperator return this; } + @Override + public String getSearchValue() + { + return searchValue; + } + @Override public String apply(String t) { diff --git a/src/main/java/speiger/src/builder/mappers/IMapper.java b/src/main/java/speiger/src/builder/mappers/IMapper.java new file mode 100644 index 0000000..787fc90 --- /dev/null +++ b/src/main/java/speiger/src/builder/mappers/IMapper.java @@ -0,0 +1,8 @@ +package speiger.src.builder.mappers; + +import java.util.function.UnaryOperator; + +public interface IMapper extends UnaryOperator +{ + public String getSearchValue(); +} diff --git a/src/main/java/speiger/src/builder/mappers/InjectMapper.java b/src/main/java/speiger/src/builder/mappers/InjectMapper.java index b80ff22..842d567 100644 --- a/src/main/java/speiger/src/builder/mappers/InjectMapper.java +++ b/src/main/java/speiger/src/builder/mappers/InjectMapper.java @@ -1,13 +1,13 @@ package speiger.src.builder.mappers; -import java.util.function.UnaryOperator; import java.util.regex.Matcher; import java.util.regex.Pattern; import speiger.src.builder.misc.RegexUtil; -public class InjectMapper implements UnaryOperator +public class InjectMapper implements IMapper { + String searchValue; Pattern pattern; String replacement; String braces = "()"; @@ -15,6 +15,12 @@ public class InjectMapper implements UnaryOperator public InjectMapper(String pattern, String replacement) { + this(pattern, pattern, replacement); + } + + public InjectMapper(String searchValue, String pattern, String replacement) + { + this.searchValue = searchValue; this.pattern = Pattern.compile(pattern); this.replacement = replacement; } @@ -32,6 +38,12 @@ public class InjectMapper implements UnaryOperator return this; } + @Override + public String getSearchValue() + { + return searchValue; + } + @Override public String apply(String t) { diff --git a/src/main/java/speiger/src/builder/mappers/LineMapper.java b/src/main/java/speiger/src/builder/mappers/LineMapper.java index d908b61..58cf750 100644 --- a/src/main/java/speiger/src/builder/mappers/LineMapper.java +++ b/src/main/java/speiger/src/builder/mappers/LineMapper.java @@ -1,20 +1,32 @@ package speiger.src.builder.mappers; -import java.util.function.UnaryOperator; import java.util.regex.Matcher; import java.util.regex.Pattern; import speiger.src.builder.misc.RegexUtil; -public class LineMapper implements UnaryOperator +public class LineMapper implements IMapper { + String searchValue; Pattern pattern; - + public LineMapper(String pattern) { + this(pattern, pattern); + } + + public LineMapper(String searchValue, String pattern) + { + this.searchValue = searchValue; this.pattern = Pattern.compile(pattern, Pattern.LITERAL); } - + + @Override + public String getSearchValue() + { + return searchValue; + } + @Override public String apply(String t) { diff --git a/src/main/java/speiger/src/builder/mappers/SimpleMapper.java b/src/main/java/speiger/src/builder/mappers/SimpleMapper.java index e63c489..d6532e6 100644 --- a/src/main/java/speiger/src/builder/mappers/SimpleMapper.java +++ b/src/main/java/speiger/src/builder/mappers/SimpleMapper.java @@ -1,19 +1,31 @@ package speiger.src.builder.mappers; -import java.util.function.UnaryOperator; import java.util.regex.Pattern; -public class SimpleMapper implements UnaryOperator +public class SimpleMapper implements IMapper { + String searchValue; Pattern pattern; String replacement; - + public SimpleMapper(String pattern, String replacement) { + this(pattern, pattern, replacement); + } + + public SimpleMapper(String searchValue, String pattern, String replacement) + { + this.searchValue = searchValue; this.pattern = Pattern.compile(pattern, Pattern.LITERAL); this.replacement = replacement; } + @Override + public String getSearchValue() + { + return searchValue; + } + @Override public String apply(String t) { diff --git a/src/main/java/speiger/src/builder/processor/BuildTask.java b/src/main/java/speiger/src/builder/processor/BuildTask.java index b06e6fd..c4114cc 100644 --- a/src/main/java/speiger/src/builder/processor/BuildTask.java +++ b/src/main/java/speiger/src/builder/processor/BuildTask.java @@ -3,26 +3,34 @@ package speiger.src.builder.processor; import java.io.BufferedWriter; import java.nio.file.Files; import java.nio.file.Path; +import java.util.Set; import speiger.src.builder.base.Template; +import speiger.src.builder.mappers.IMapper; public class BuildTask implements Runnable { Path basePath; Template template; TemplateProcess process; + Set[] mappers; - public BuildTask(Path basePath, Template template, TemplateProcess process) + public BuildTask(Path basePath, Template template, TemplateProcess process, Set[] mappers) { this.basePath = basePath; this.template = template; this.process = process; + this.mappers = mappers; } @Override public void run() { - String s = template.build(process.parsePool, process.mappers); + String s = template.build(process.parsePool, process.mappers, mappers != null, mappers[1]); + if(mappers != null) + { + mappers[0].addAll(process.mappers); + } Path path = (process.pathBuilder != null ? process.pathBuilder.apply(basePath) : basePath).resolve(process.fileName); try { @@ -42,5 +50,4 @@ public class BuildTask implements Runnable e.printStackTrace(); } } - } diff --git a/src/main/java/speiger/src/builder/processor/TemplateProcess.java b/src/main/java/speiger/src/builder/processor/TemplateProcess.java index 567364b..cdca589 100644 --- a/src/main/java/speiger/src/builder/processor/TemplateProcess.java +++ b/src/main/java/speiger/src/builder/processor/TemplateProcess.java @@ -9,12 +9,14 @@ import java.util.List; import java.util.Set; import java.util.function.UnaryOperator; +import speiger.src.builder.mappers.IMapper; + public class TemplateProcess { UnaryOperator pathBuilder; String fileName; Set parsePool = new HashSet<>(); - List> mappers = new ArrayList<>(); + List mappers = new ArrayList<>(); public TemplateProcess(String fileName) { @@ -36,12 +38,12 @@ public class TemplateProcess parsePool.addAll(flags); } - public void addMapper(UnaryOperator mapper) + public void addMapper(IMapper mapper) { mappers.add(mapper); } - public void addMappers(Collection> mappers) + public void addMappers(Collection mappers) { this.mappers.addAll(mappers); } diff --git a/src/main/java/speiger/src/builder/processor/TemplateProcessor.java b/src/main/java/speiger/src/builder/processor/TemplateProcessor.java index 4c67276..01ae413 100644 --- a/src/main/java/speiger/src/builder/processor/TemplateProcessor.java +++ b/src/main/java/speiger/src/builder/processor/TemplateProcessor.java @@ -3,8 +3,11 @@ package speiger.src.builder.processor; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; +import java.util.Collections; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.concurrent.Executors; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; @@ -12,6 +15,7 @@ import java.util.function.Consumer; import java.util.stream.Collectors; import speiger.src.builder.base.Template; +import speiger.src.builder.mappers.IMapper; import speiger.src.builder.misc.FileUtils; public abstract class TemplateProcessor @@ -36,6 +40,8 @@ public abstract class TemplateProcessor protected abstract boolean relativePackages(); + protected abstract boolean debugUnusedMappers(); + public final boolean process(boolean force) throws IOException, InterruptedException { if(!init) @@ -51,6 +57,7 @@ public abstract class TemplateProcessor return false; } final boolean relative = relativePackages(); + Set[] mappers = debugUnusedMappers() ? new Set[]{Collections.synchronizedSet(new HashSet()), Collections.synchronizedSet(new HashSet())} : null; ThreadPoolExecutor service = (ThreadPoolExecutor)Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()); service.setKeepAliveTime(10, TimeUnit.MILLISECONDS); service.allowCoreThreadTimeOut(true); @@ -61,7 +68,7 @@ public abstract class TemplateProcessor try { Template template = Template.parse(path); - createProcesses(FileUtils.getFileName(path), T -> service.execute(new BuildTask(relative ? outputFolder.resolve(sourceFolder.relativize(path).getParent()) : outputFolder, template, T))); + createProcesses(FileUtils.getFileName(path), T -> service.execute(new BuildTask(relative ? outputFolder.resolve(sourceFolder.relativize(path).getParent()) : outputFolder, template, T, mappers))); } catch(Exception e) { @@ -80,6 +87,14 @@ public abstract class TemplateProcessor { Thread.sleep(10); } + if(mappers != null && mappers[0].size() != mappers[1].size()) + { + mappers[0].removeAll(mappers[1]); + for(IMapper mapper : mappers[0]) + { + System.out.println("Mapper ["+mapper.getSearchValue()+"] is not used in the Entire Build Process"); + } + } System.out.println("Finished Tasks: "+(System.currentTimeMillis() - start)+"ms"); FileUtils.saveMappings(existing, dataFolder); System.out.print("Saved Changes");