use of org.kie.kogito.codegen.api.GeneratedFile in project kogito-runtimes by kiegroup.
the class PersistenceGenerator method kafkaBasedPersistence.
protected Collection<GeneratedFile> kafkaBasedPersistence() {
ClassOrInterfaceDeclaration persistenceProviderClazz = new ClassOrInterfaceDeclaration().setName(KOGITO_PROCESS_INSTANCE_FACTORY_IMPL).setModifiers(Modifier.Keyword.PUBLIC).addExtendedType(KOGITO_PROCESS_INSTANCE_FACTORY_PACKAGE);
if (context().hasDI()) {
context().getDependencyInjectionAnnotator().withApplicationComponent(persistenceProviderClazz);
}
Collection<GeneratedFile> generatedFiles = new ArrayList<>();
TemplatedGenerator generator = TemplatedGenerator.builder().withTemplateBasePath(CLASS_TEMPLATES_PERSISTENCE).withFallbackContext(JavaKogitoBuildContext.CONTEXT_NAME).withPackageName(KOGITO_PROCESS_INSTANCE_PACKAGE).build(context(), "KafkaStreamsTopologyProducer");
CompilationUnit parsedClazzFile = generator.compilationUnitOrThrow();
ClassOrInterfaceDeclaration producer = parsedClazzFile.findFirst(ClassOrInterfaceDeclaration.class).orElseThrow(() -> new InvalidTemplateException(generator, "Failed to find template for KafkaStreamsTopologyProducer"));
MethodCallExpr asListOfProcesses = new MethodCallExpr(new NameExpr("java.util.Arrays"), "asList");
protoGenerator.getProcessIds().forEach(p -> asListOfProcesses.addArgument(new StringLiteralExpr(p)));
producer.getFieldByName("processes").orElseThrow(() -> new InvalidTemplateException(generator, "Failed to find field 'processes' in KafkaStreamsTopologyProducer template")).getVariable(0).setInitializer(asListOfProcesses);
String clazzName = KOGITO_PROCESS_INSTANCE_PACKAGE + "." + producer.getName().asString();
generatedFiles.add(new GeneratedFile(GeneratedFileType.SOURCE, clazzName.replace('.', '/') + JAVA, parsedClazzFile.toString()));
CompilationUnit compilationUnit = new CompilationUnit(KOGITO_PROCESS_INSTANCE_PACKAGE);
compilationUnit.getTypes().add(persistenceProviderClazz);
generatePersistenceProviderClazz(persistenceProviderClazz, compilationUnit).ifPresent(generatedFiles::add);
return generatedFiles;
}
use of org.kie.kogito.codegen.api.GeneratedFile in project kogito-runtimes by kiegroup.
the class KieSessionModelBuilder method generate.
List<GeneratedFile> generate() {
ModelSourceClass modelSourceClass = new ModelSourceClass(DroolsModelBuilder.DUMMY_RELEASE_ID, kieBaseModels, modelByKBase);
ProjectRuntimeGenerator projectRuntimeGenerator = new ProjectRuntimeGenerator(modelSourceClass.getModelMethod(), context);
return List.of(new GeneratedFile(RuleCodegen.RULE_TYPE, modelSourceClass.getName(), modelSourceClass.generate()), new GeneratedFile(RuleCodegen.RULE_TYPE, projectRuntimeGenerator.getName(), projectRuntimeGenerator.generate()));
}
use of org.kie.kogito.codegen.api.GeneratedFile in project kogito-runtimes by kiegroup.
the class KogitoAssetsProcessor method generateSources.
@BuildStep
public KogitoGeneratedSourcesBuildItem generateSources(Capabilities capabilities, KogitoBuildContextBuildItem contextBuildItem) {
final KogitoBuildContext context = contextBuildItem.getKogitoBuildContext();
validateAvailableCapabilities(context, capabilities);
Collection<GeneratedFile> generatedFiles = generateFiles(context);
// During actual hot reloads it will be regenerated by the compilation providers in order to retrigger this build step
if (!liveReload.isLiveReload()) {
generatedFiles.add(new GeneratedFile(GeneratedFileType.SOURCE, HOT_RELOAD_SUPPORT_PATH + ".java", getHotReloadSupportSource()));
}
return new KogitoGeneratedSourcesBuildItem(generatedFiles);
}
use of org.kie.kogito.codegen.api.GeneratedFile in project kogito-runtimes by kiegroup.
the class ProcessesAssetsProcessor method postGenerationProcessing.
/**
* Main entry point of the Quarkus extension
*/
@BuildStep
public void postGenerationProcessing(List<KogitoGeneratedClassesBuildItem> generatedKogitoClasses, BuildProducer<GeneratedBeanBuildItem> generatedBeans, BuildProducer<AdditionalStaticResourceBuildItem> staticResProducer, BuildProducer<NativeImageResourceBuildItem> resource, BuildProducer<NativeImageResourcePatternsBuildItem> resourcePatterns, BuildProducer<GeneratedResourceBuildItem> genResBI, BuildProducer<RunTimeConfigurationDefaultBuildItem> runTimeConfiguration, CombinedIndexBuildItem combinedIndexBuildItem, KogitoBuildContextBuildItem kogitoBuildContextBuildItem, Capabilities capabilities) throws IOException {
// merge project index with classes generated by Kogito
IndexView aggregatedIndex = generateAggregatedIndex(combinedIndexBuildItem.getComputingIndex(), generatedKogitoClasses);
// configure the application generator
KogitoBuildContext context = kogitoBuildContextBuildItem.getKogitoBuildContext();
Collection<GeneratedFile> generatedFiles = new ArrayList<>();
if (capabilities.isCapabilityWithPrefixPresent(PERSISTENCE_CAPABILITY)) {
generatedFiles.addAll(generatePersistenceInfo(context, aggregatedIndex, generatedBeans, resourcePatterns, runTimeConfiguration, liveReload.isLiveReload()));
}
Map<String, byte[]> classes = new HashMap<>();
for (KogitoGeneratedClassesBuildItem generatedKogitoClass : generatedKogitoClasses) {
classes.putAll(generatedKogitoClass.getGeneratedClasses());
}
// Json schema files
generatedFiles.addAll(generateJsonSchema(context, aggregatedIndex, classes));
// Write files to disk
dumpFilesToDisk(context.getAppPaths(), generatedFiles);
// register resources to the Quarkus environment
registerResources(generatedFiles, staticResProducer, resource, genResBI);
registerProcessSVG(context, resource);
}
use of org.kie.kogito.codegen.api.GeneratedFile in project kogito-runtimes by kiegroup.
the class PersistenceGenerator method jdbcBasedPersistence.
private Collection<GeneratedFile> jdbcBasedPersistence() {
ClassOrInterfaceDeclaration persistenceProviderClazz = new ClassOrInterfaceDeclaration().setName(KOGITO_PROCESS_INSTANCE_FACTORY_IMPL).setModifiers(Modifier.Keyword.PUBLIC).addExtendedType(KOGITO_PROCESS_INSTANCE_FACTORY_PACKAGE);
Collection<GeneratedFile> generatedFiles = new ArrayList<>();
if (context().hasDI()) {
context().getDependencyInjectionAnnotator().withApplicationComponent(persistenceProviderClazz);
final String datasourceClass = "javax.sql.DataSource";
ConstructorDeclaration constructor = persistenceProviderClazz.addConstructor(Keyword.PUBLIC).addParameter(datasourceClass, "dataSource").addParameter(StaticJavaParser.parseClassOrInterfaceType(Boolean.class.getName()), AUTO_DDL).setBody(new BlockStmt().addStatement(new ExplicitConstructorInvocationStmt().setThis(false).addArgument(new NameExpr("dataSource")).addArgument(AUTO_DDL)));
Optional<Parameter> autoDDL = constructor.getParameterByName(AUTO_DDL);
autoDDL.ifPresent(parameter -> context().getDependencyInjectionAnnotator().withConfigInjection(parameter, KOGITO_PERSISTENCE_AUTO_DDL, Boolean.TRUE.toString()));
context().getDependencyInjectionAnnotator().withInjection(constructor);
// empty constructor for DI
persistenceProviderClazz.addConstructor(Keyword.PROTECTED);
}
addOptimisticLockFlag(persistenceProviderClazz);
Optional<GeneratedFile> generatedPgClientFile = generatePersistenceProviderClazz(persistenceProviderClazz, new CompilationUnit(KOGITO_PROCESS_INSTANCE_PACKAGE).addType(persistenceProviderClazz));
generatedPgClientFile.ifPresent(generatedFiles::add);
return generatedFiles;
}
Aggregations