use of ilargia.entitas.codeGeneration.interfaces.ICodeGeneratorDataProvider 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);
}
use of ilargia.entitas.codeGeneration.interfaces.ICodeGeneratorDataProvider in project Entitas-Java by Rubentxu.
the class CodeGeneratorOld method generate.
public List<CodeGenFile> generate(ICodeGeneratorDataProvider provider, String destinyDirectory, List<ICodeGenerator> codeGenerators) {
List<String> scrDir = new ArrayList<String>() {
{
add("main/java");
add("test/java");
add("main\\java");
add("test\\java");
add("src");
}
};
Optional<String> sourcePackage = scrDir.stream().filter((base) -> destinyDirectory.lastIndexOf(base) != -1).map((base) -> destinyDirectory.substring(destinyDirectory.lastIndexOf(base) + base.length() + 1)).map((base) -> base.replaceAll("/", ".").replaceAll("\\\\", ".")).findFirst();
ArrayList<CodeGenFile> generatedFiles = new ArrayList<CodeGenFile>();
List<JavaClassSource> files = new ArrayList<>();
// if (sourcePackage.isPresent()) {
// for (ICodeGenerator generator : generators) {
// if (generator instanceof IContextCodeGenerator) {
// for (JavaClassSource javaClassSource : ((IContextCodeGenerator) generator).generate(provider.poolNames(), sourcePackage.get())) {
// files.add(javaClassSource);
// generatedFiles.add(new CodeGenFile(javaClassSource.getCanonicalName(), javaClassSource, generator.getClass().getName()));
// }
//
// }
// if (generator instanceof IComponentCodeGenerator) {
// for (JavaClassSource javaClassSource : ((IComponentCodeGenerator) generator).generate(provider.componentInfos(), sourcePackage.get())) {
// files.add(javaClassSource);
// generatedFiles.add(new CodeGenFile(javaClassSource.getCanonicalName(), javaClassSource, generator.getClass().getName()));
// }
//
// }
// if (generator instanceof IBlueprintsCodeGenerator) {
// for (JavaClassSource javaClassSource : ((IBlueprintsCodeGenerator) generator).generate(provider.blueprintNames(), sourcePackage.get())) {
// files.add(javaClassSource);
// generatedFiles.add(new CodeGenFile(javaClassSource.getCanonicalName(), javaClassSource, generator.getClass().getName()));
// }
//
// }
// }
// }
CodeGenFile entitas = generatedFiles.get(generatedFiles.size() - 1);
for (CodeGenFile generatedFile : generatedFiles) {
if (!generatedFile.fileName.endsWith("Matcher") && !entitas.fileContent.getPackage().equals(generatedFile.fileContent.getPackage())) {
entitas.fileContent.addImport(generatedFile.fileName);
}
}
writeFiles(destinyDirectory, files);
return generatedFiles;
}
use of ilargia.entitas.codeGeneration.interfaces.ICodeGeneratorDataProvider 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;
}
Aggregations