Skip to content

Commit

Permalink
fix handling of custom package for generated resources as config para…
Browse files Browse the repository at this point in the history
…meter
  • Loading branch information
mswiderski committed Sep 20, 2024
1 parent 107aceb commit d70baf4
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public Collection<GeneratedFile> generate() {
}

if (context != null) {
CompilationUnit cp = context.write(DEFAULT_PACKAGE_NAME);
CompilationUnit cp = context.write();

String packageName = cp.getPackageDeclaration().map(pd -> pd.getName().toString()).orElse("");
String clazzName = packageName + "."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ public static GeneratorContext ofResourcePath(File resourcePath, File classesPat
private File resourcePath;
private File classesPath;

private Optional<String> packageName = Optional.empty();

private Properties applicationProperties = new Properties();
private Map<String, String> modifiedApplicationProperties = new LinkedHashMap<String, String>();

Expand Down Expand Up @@ -114,12 +116,12 @@ public void setApplicationProperty(String property, String value) {
}
}

public CompilationUnit write(String packageName) {
public CompilationUnit write() {

CompilationUnit clazz = parse(
this.getClass().getResourceAsStream("/class-templates/config/ConfigPropertiesTemplate.java"));

clazz.setPackageDeclaration(packageName);
clazz.setPackageDeclaration("io.automatiko.application.app");
ClassOrInterfaceDeclaration template = clazz.findFirst(ClassOrInterfaceDeclaration.class).get();

BlockStmt constructorBody = new BlockStmt();
Expand Down Expand Up @@ -284,6 +286,14 @@ public List<String> getInstructions() {
return this.instructions;
}

public Optional<String> getPackageName() {
return packageName;
}

public void withPackageName(String packageName) {
this.packageName = Optional.of(packageName);
}

public void logInstructions() {
if (!instructions.isEmpty()) {
LOGGER.info("****************** Automatiko Instructions *********************");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ public DecisionCodegen(List<DMNResource> resources) {
this.resources = resources;

// set default package name
setPackageName(ApplicationGenerator.DEFAULT_PACKAGE_NAME);
setPackageName(context == null ? ApplicationGenerator.DEFAULT_PACKAGE_NAME
: context.getPackageName().orElse(ApplicationGenerator.DEFAULT_PACKAGE_NAME));
this.moduleGenerator = new DecisionContainerGenerator(applicationCanonicalName, resources);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,8 @@ public ProcessCodegen(Collection<? extends Process> processes) {
}

// set default package name
setPackageName(ApplicationGenerator.DEFAULT_PACKAGE_NAME);
setPackageName(context == null ? ApplicationGenerator.DEFAULT_PACKAGE_NAME
: context.getPackageName().orElse(ApplicationGenerator.DEFAULT_PACKAGE_NAME));
contextClassLoader = Thread.currentThread().getContextClassLoader();

resourceGeneratorFactory = new DefaultResourceGeneratorFactory();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,8 @@ private MethodDeclaration internalConfigure(ProcessMetaData processMetaData) {

processMetaData.getGeneratedHandlers().forEach((name, descriptor) -> {

CompilationUnit handler = descriptor.generateHandlerClassForService();
CompilationUnit handler = descriptor
.generateHandlerClassForService(context.getPackageName().orElse("io.automatiko.engine.app.handlers"));
ClassOrInterfaceDeclaration clazz = handler.findFirst(ClassOrInterfaceDeclaration.class).get();
if (useInjection()) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,8 @@ public void runtimeInitializationRegistrationStep(BuildProducer<RuntimeInitializ
}

@BuildStep
public void serviceProviderRegistrationStep(BuildProducer<ServiceProviderBuildItem> providerProducer) {
public void serviceProviderRegistrationStep(AutomatikoBuildTimeConfig config,
BuildProducer<ServiceProviderBuildItem> providerProducer) {

providerProducer.produce(new ServiceProviderBuildItem(AutomatikoConfigProperties.class.getCanonicalName(),
"io.automatiko.application.app.GeneratedAutomatikoConfigProperties"));
Expand Down Expand Up @@ -712,7 +713,7 @@ private void addProcessGenerator(AppPaths appPaths, boolean usePersistence, Appl

WorkflowBuilder builder = (WorkflowBuilder) method.invoke(workflowsBuilderInstance);
ExecutableProcess process = builder.get();
process.setPackageName(builderClass.getPackageName());
process.setPackageName(builderClass.getPackageName() + ".generated");

// sets the category from annotation if not already set workflow
if (process.getMetaData("category") == null && !category.isBlank()) {
Expand Down Expand Up @@ -827,6 +828,7 @@ private GeneratorContext buildContext(Capabilities capabilities, AutomatikoBuild
IndexView index) {
GeneratorContext generationContext = QuarkusGeneratorContext.ofResourcePath(appPaths.getResourceFiles()[0],
appPaths.getFirstClassesPath().toFile());
generationContext.withPackageName(config.packageName().orElse(DEFAULT_PACKAGE_NAME));

generationContext
.withBuildContext(new QuarkusApplicationBuildContext(config, className -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ private String mangledHandlerName(String processId, String interfaceName, String
return String.format("%s_%s_%s_%s_Handler", interfaceName, operationName, processId, nodeName);
}

public CompilationUnit generateHandlerClassForService() {
CompilationUnit compilationUnit = new CompilationUnit("io.automatiko.engine.app.handlers");
public CompilationUnit generateHandlerClassForService(String packageName) {
CompilationUnit compilationUnit = new CompilationUnit(packageName);

compilationUnit.getTypes().add(classDeclaration());

Expand Down

0 comments on commit d70baf4

Please sign in to comment.