From b979e9d9e863bf8b4aa53e89361c2637fb65091b Mon Sep 17 00:00:00 2001 From: Speiger Date: Tue, 28 Sep 2021 04:36:57 +0200 Subject: [PATCH] new features. -Added: Documentation -Added: Function hooks that run before/while/after the process ran --- .../builder/processor/TemplateProcessor.java | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/src/main/java/speiger/src/builder/processor/TemplateProcessor.java b/src/main/java/speiger/src/builder/processor/TemplateProcessor.java index a773e51..25a7d8b 100644 --- a/src/main/java/speiger/src/builder/processor/TemplateProcessor.java +++ b/src/main/java/speiger/src/builder/processor/TemplateProcessor.java @@ -33,16 +33,61 @@ public abstract class TemplateProcessor this.dataFolder = dataFolder; } + /** + * Function that is called before the initial run of the template processor. + * It is only called once to basically initialize the program and then run as needed. + */ protected abstract void init(); + /** + * Function that decides which file is going to be used and which not. Basically black/white list as needed + * @param fileName FileName without folder structure. Since this is designed to have 0 duplicated file names. + * @return true if it is valid to be processed or false if it isn't + */ protected abstract boolean isFileValid(Path fileName); + /** + * Main function that processes a filename to its target + * @param fileName name of the file that should be processed without the type of file. (.template or .json etc etc) + * @param process all modifications to the file that should be executed + */ public abstract void createProcesses(String fileName, Consumer process); + /** + * Function that asks if the folder structure on the source folder should be kept or not + * @return true if the source-structure should be kept or flattened. + */ protected abstract boolean relativePackages(); + /** + * Function that tests if a Mapper was used or not. Useful for small scale projects that barely have any mappers + * but sadly more like to cause not needed warnings for large scale projects. + * @return true if it should be enabled + */ protected abstract boolean debugUnusedMappers(); + /** + * Function called before the Template Processor runs. + * But after init is called and All files are loaded in and the task queue is already ready. + */ + protected void beforeStart() {} + + /** + * Function that is called while the template generation is running and all after the File hashes for the memory are being generated. + * If you have anything to do while the processor is running this would be the ideal time to do it. + */ + protected void whileProcessing() {} + + /** + * Function that is being called after the template processor is called and after the file cache has been updated + * Basically just before "Saved Changes" is called. + */ + protected void afterFinish() {} + + protected Path getSourceFolder() { return sourceFolder; } + protected Path getOutputFolder() { return outputFolder; } + protected Path getDataFolder() { return dataFolder; } + public final boolean process(boolean force) throws IOException, InterruptedException { if(!init) @@ -63,6 +108,7 @@ public abstract class TemplateProcessor ThreadPoolExecutor service = (ThreadPoolExecutor)Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()); service.setKeepAliveTime(10, TimeUnit.MILLISECONDS); service.allowCoreThreadTimeOut(true); + beforeStart(); service.submit(() -> { for(int i = 0,m=pathsLeft.size();i 0) { Thread.sleep(10); @@ -102,6 +149,7 @@ public abstract class TemplateProcessor } 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); + afterFinish(); System.out.print("Saved Changes"); return true; }