new features.
-Added: Documentation -Added: Function hooks that run before/while/after the process ran
This commit is contained in:
parent
6f3f45d718
commit
b979e9d9e8
|
@ -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<TemplateProcess> 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<m;i++)
|
||||
{
|
||||
|
@ -88,6 +134,7 @@ public abstract class TemplateProcessor
|
|||
Path path = pathsLeft.get(i);
|
||||
existing.put(FileUtils.getFileName(path), FileUtils.getMD5String(path));
|
||||
}
|
||||
whileProcessing();
|
||||
while(service.getActiveCount() > 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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue