Search in sources :

Example 1 with ICodeGenFilePostProcessor

use of ilargia.entitas.codeGeneration.interfaces.ICodeGenFilePostProcessor in project Entitas-Java by Rubentxu.

the class EntitasGradleProject method getCodeGenerator.

@Override
public CodeGenerator getCodeGenerator() {
    Properties properties = loadProperties();
    CodeGeneratorConfig config = new CodeGeneratorConfig();
    config.configure(properties);
    List<Class> types = loadTypesFromPlugins(properties);
    List<ICodeGeneratorDataProvider> dataProviders = getEnabledInstances(types, config.getDataProviders(), ICodeGeneratorDataProvider.class);
    List<ICodeGenerator> codeGenerators = getEnabledInstances(types, config.getCodeGenerators(), ICodeGenerator.class);
    List<ICodeGenFilePostProcessor> postProcessors = getEnabledInstances(types, config.getPostProcessors(), ICodeGenFilePostProcessor.class);
    configure(dataProviders, properties);
    configure(codeGenerators, properties);
    configure(postProcessors, properties);
    return new CodeGenerator(dataProviders, codeGenerators, postProcessors);
}
Also used : CodeGeneratorConfig(ilargia.entitas.codeGeneration.config.CodeGeneratorConfig) ICodeGenerator(ilargia.entitas.codeGeneration.interfaces.ICodeGenerator) ICodeGeneratorDataProvider(ilargia.entitas.codeGeneration.interfaces.ICodeGeneratorDataProvider) ICodeGenFilePostProcessor(ilargia.entitas.codeGeneration.interfaces.ICodeGenFilePostProcessor) CodeGenerator(ilargia.entitas.codeGeneration.CodeGenerator) ICodeGenerator(ilargia.entitas.codeGeneration.interfaces.ICodeGenerator) Properties(java.util.Properties)

Example 2 with ICodeGenFilePostProcessor

use of ilargia.entitas.codeGeneration.interfaces.ICodeGenFilePostProcessor in project Entitas-Java by Rubentxu.

the class CodeGenerator method generate.

List<CodeGenFile> generate(String messagePrefix, List<ICodeGeneratorDataProvider> dataProviders, List<ICodeGenerator> codeGenerators, List<ICodeGenFilePostProcessor> postProcessors) {
    _cancel = false;
    List<CodeGeneratorData> data = new ArrayList<>();
    int total = dataProviders.size() + codeGenerators.size() + postProcessors.size();
    int progress = 0;
    for (ICodeGeneratorDataProvider dataProvider : dataProviders) {
        if (_cancel) {
            return new ArrayList<>();
        }
        progress += 1;
        if (OnProgress != null) {
            OnProgress.exec(messagePrefix + "Creating model", dataProvider.getName(), (float) progress / total);
        }
        data.addAll(dataProvider.getData());
    }
    List<CodeGenFile> files = new ArrayList<>();
    for (ICodeGenerator generator : codeGenerators) {
        if (_cancel) {
            return new ArrayList<>();
        }
        progress += 1;
        if (OnProgress != null) {
            OnProgress.exec(messagePrefix + "Creating files", generator.getName(), (float) progress / total);
        }
        files.addAll(generator.generate(data));
    }
    for (ICodeGenFilePostProcessor postProcessor : postProcessors) {
        if (_cancel) {
            return new ArrayList<>();
        }
        progress += 1;
        if (OnProgress != null) {
            OnProgress.exec(messagePrefix + "Processing files", postProcessor.getName(), (float) progress / total);
        }
        files = postProcessor.postProcess(files);
    }
    return files;
}
Also used : ICodeGenerator(ilargia.entitas.codeGeneration.interfaces.ICodeGenerator) ICodeGeneratorDataProvider(ilargia.entitas.codeGeneration.interfaces.ICodeGeneratorDataProvider) CodeGeneratorData(ilargia.entitas.codeGeneration.data.CodeGeneratorData) CodeGenFile(ilargia.entitas.codeGeneration.data.CodeGenFile) ArrayList(java.util.ArrayList) ICodeGenFilePostProcessor(ilargia.entitas.codeGeneration.interfaces.ICodeGenFilePostProcessor)

Aggregations

ICodeGenFilePostProcessor (ilargia.entitas.codeGeneration.interfaces.ICodeGenFilePostProcessor)2 ICodeGenerator (ilargia.entitas.codeGeneration.interfaces.ICodeGenerator)2 ICodeGeneratorDataProvider (ilargia.entitas.codeGeneration.interfaces.ICodeGeneratorDataProvider)2 CodeGenerator (ilargia.entitas.codeGeneration.CodeGenerator)1 CodeGeneratorConfig (ilargia.entitas.codeGeneration.config.CodeGeneratorConfig)1 CodeGenFile (ilargia.entitas.codeGeneration.data.CodeGenFile)1 CodeGeneratorData (ilargia.entitas.codeGeneration.data.CodeGeneratorData)1 ArrayList (java.util.ArrayList)1 Properties (java.util.Properties)1