Search in sources :

Example 1 with CodeGeneratorConfig

use of ilargia.entitas.codeGeneration.config.CodeGeneratorConfig 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 CodeGeneratorConfig

use of ilargia.entitas.codeGeneration.config.CodeGeneratorConfig in project Entitas-Java by Rubentxu.

the class FixConfig method run.

@Override
public void run(String[] args) {
    System.out.println("Entitas Code Generator version " + 1);
    if (assertProperties()) {
        try {
            //loadProperties();
            Properties properties = null;
            CodeGeneratorConfig config = new CodeGeneratorConfig();
            config.configure(properties);
            forceAddKeys(config.getDefaultProperties(), properties);
            List<Class> Classs = null;
            try {
                Classs = CodeGeneratorUtil.loadTypesFromPlugins(properties);
                getConfigurables(Classs, config);
            } catch (Exception ex) {
                throw ex;
            }
            Set<String> askedRemoveKeys = new HashSet<String>();
            Set<String> askedAddKeys = new HashSet<String>();
            while (fix(askedRemoveKeys, askedAddKeys, Classs, config, properties)) {
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
Also used : CodeGeneratorConfig(ilargia.entitas.codeGeneration.config.CodeGeneratorConfig)

Example 3 with CodeGeneratorConfig

use of ilargia.entitas.codeGeneration.config.CodeGeneratorConfig in project Entitas-Java by Rubentxu.

the class NewConfig method run.

@Override
public void run(String[] args) {
    Path currentRelativePath = Paths.get("");
    String currentDir = currentRelativePath.toAbsolutePath().toString();
    File path = new File(currentDir + "/");
    if (ArgsExtension.isForce(Arrays.asList(args)) || !path.exists()) {
        CodeGeneratorConfig defaultConfig = new CodeGeneratorConfig();
        Properties properties = new Properties(defaultConfig.getDefaultProperties());
        defaultConfig.configure(properties);
        saveProperties(properties, path.getAbsolutePath());
        new EditConfig().run(args);
    } else {
        System.out.println(path + " already exists!");
        System.out.println("Use entitas new -f to overwrite the exiting file.");
        System.out.println("Use entitas edit to open the exiting file.");
    }
}
Also used : Path(java.nio.file.Path) CodeGeneratorConfig(ilargia.entitas.codeGeneration.config.CodeGeneratorConfig) Properties(java.util.Properties) File(java.io.File)

Example 4 with CodeGeneratorConfig

use of ilargia.entitas.codeGeneration.config.CodeGeneratorConfig in project Entitas-Java by Rubentxu.

the class CodeGeneratorUtil method loadTypesFromPlugins.

public static List<Class> loadTypesFromPlugins(Properties properties) {
    CodeGeneratorConfig config = new CodeGeneratorConfig();
    config.configure(properties);
    return config.getPlugins().stream().flatMap(s -> ClassFinder.findRecursive(s).stream()).sorted((typeA, typeB) -> typeA.getCanonicalName().compareTo(typeB.getCanonicalName())).collect(Collectors.toList());
}
Also used : CodeGeneratorConfig(ilargia.entitas.codeGeneration.config.CodeGeneratorConfig) List(java.util.List) Properties(java.util.Properties) Stream(java.util.stream.Stream) BufferedWriter(java.io.BufferedWriter) Modifier(java.lang.reflect.Modifier) Map(java.util.Map) FileWriter(java.io.FileWriter) ilargia.entitas.codeGeneration.interfaces(ilargia.entitas.codeGeneration.interfaces) IOException(java.io.IOException) CodeGeneratorConfig(ilargia.entitas.codeGeneration.config.CodeGeneratorConfig) Collectors(java.util.stream.Collectors) File(java.io.File)

Example 5 with CodeGeneratorConfig

use of ilargia.entitas.codeGeneration.config.CodeGeneratorConfig in project Entitas-Java by Rubentxu.

the class Status method run.

@Override
public void run(String[] args) {
    System.out.println("Entitas Code Generator version " + 1);
    if (assertProperties()) {
        Properties properties = null;
        try {
            properties = loadProperties();
            CodeGeneratorConfig config = new CodeGeneratorConfig();
            config.configure(properties);
            System.out.println(config.toString());
            List<Class> types = null;
            Map<String, String> configurables = null;
            try {
                types = CodeGeneratorUtil.loadTypesFromPlugins(properties);
                configurables = CodeGeneratorUtil.getConfigurables(CodeGeneratorUtil.getUsed(types, config.getDataProviders(), ICodeGeneratorDataProvider.class), CodeGeneratorUtil.getUsed(types, config.getCodeGenerators(), ICodeGenerator.class), CodeGeneratorUtil.getUsed(types, config.getPostProcessors(), ICodeGenFilePostProcessor.class));
            } catch (Exception ex) {
                printKeyStatus(config.getDefaultProperties().keySet(), properties);
                throw ex;
            }
            config.getDefaultProperties().putAll(configurables);
            Set<Object> requiredKeys = config.getDefaultProperties().keySet();
            printKeyStatus(requiredKeys, properties);
            printPluginStatus(types, config);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
Also used : CodeGeneratorConfig(ilargia.entitas.codeGeneration.config.CodeGeneratorConfig) Properties(java.util.Properties)

Aggregations

CodeGeneratorConfig (ilargia.entitas.codeGeneration.config.CodeGeneratorConfig)5 Properties (java.util.Properties)4 File (java.io.File)2 CodeGenerator (ilargia.entitas.codeGeneration.CodeGenerator)1 ilargia.entitas.codeGeneration.interfaces (ilargia.entitas.codeGeneration.interfaces)1 ICodeGenFilePostProcessor (ilargia.entitas.codeGeneration.interfaces.ICodeGenFilePostProcessor)1 ICodeGenerator (ilargia.entitas.codeGeneration.interfaces.ICodeGenerator)1 ICodeGeneratorDataProvider (ilargia.entitas.codeGeneration.interfaces.ICodeGeneratorDataProvider)1 BufferedWriter (java.io.BufferedWriter)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 Modifier (java.lang.reflect.Modifier)1 Path (java.nio.file.Path)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1