diff --git a/drools/kogito-scenario-simulation/src/main/java/org/kogito/scenariosimulation/runner/KogitoDMNScenarioRunnerHelper.java b/drools/kogito-scenario-simulation/src/main/java/org/kogito/scenariosimulation/runner/KogitoDMNScenarioRunnerHelper.java index ad301b25a50..9d6f96ef9eb 100644 --- a/drools/kogito-scenario-simulation/src/main/java/org/kogito/scenariosimulation/runner/KogitoDMNScenarioRunnerHelper.java +++ b/drools/kogito-scenario-simulation/src/main/java/org/kogito/scenariosimulation/runner/KogitoDMNScenarioRunnerHelper.java @@ -53,6 +53,9 @@ public class KogitoDMNScenarioRunnerHelper extends DMNScenarioRunnerHelper { private DMNRuntime dmnRuntime = initDmnRuntime(); + private static final String targetFolder = File.separator + "target" + File.separator; + private static final String generatedResourcesFolder = targetFolder + "generated-resources" + File.separator; + @Override protected Map executeScenario(KieContainer kieContainer, ScenarioRunnerData scenarioRunnerData, @@ -102,8 +105,9 @@ private DMNRuntime initDmnRuntime() { } private boolean filterResource(Path path, String extension) { - String targetFolder = File.separator + "target" + File.separator; - return path.toString().endsWith(extension) && !path.toString().contains(targetFolder) && Files.isRegularFile(path); + return path.toString().endsWith(extension) && + (path.toString().contains(generatedResourcesFolder) || !(path.toString().contains(targetFolder))) + && Files.isRegularFile(path); } } diff --git a/quarkus/extensions/kogito-quarkus-extension-common/kogito-quarkus-common-deployment/src/main/java/org/kie/kogito/quarkus/common/deployment/KogitoAssetsProcessor.java b/quarkus/extensions/kogito-quarkus-extension-common/kogito-quarkus-common-deployment/src/main/java/org/kie/kogito/quarkus/common/deployment/KogitoAssetsProcessor.java index c4c6079bd34..02a70d08d84 100644 --- a/quarkus/extensions/kogito-quarkus-extension-common/kogito-quarkus-common-deployment/src/main/java/org/kie/kogito/quarkus/common/deployment/KogitoAssetsProcessor.java +++ b/quarkus/extensions/kogito-quarkus-extension-common/kogito-quarkus-common-deployment/src/main/java/org/kie/kogito/quarkus/common/deployment/KogitoAssetsProcessor.java @@ -18,7 +18,9 @@ */ package org.kie.kogito.quarkus.common.deployment; +import java.io.File; import java.io.IOException; +import java.nio.file.Path; import java.util.Collection; import java.util.Collections; import java.util.HashMap; @@ -27,6 +29,7 @@ import java.util.Map; import java.util.Optional; import java.util.Set; +import java.util.concurrent.atomic.AtomicReference; import java.util.function.Function; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -64,6 +67,8 @@ import io.quarkus.deployment.pkg.builditem.OutputTargetBuildItem; import io.quarkus.maven.dependency.Dependency; import io.quarkus.maven.dependency.ResolvedDependency; +import io.quarkus.paths.PathCollection; +import io.quarkus.paths.PathList; import io.quarkus.resteasy.reactive.spi.GeneratedJaxRsResourceBuildItem; import io.quarkus.vertx.http.deployment.spi.AdditionalStaticResourceBuildItem; @@ -102,9 +107,10 @@ public class KogitoAssetsProcessor { @BuildStep public KogitoBuildContextBuildItem generateKogitoBuildContext(List attributes) { // configure the application generator + PathCollection rootPaths = getRootPaths( root.getResolvedPaths()); KogitoBuildContext context = kogitoBuildContext(outputTargetBuildItem.getOutputDirectory(), - root.getResolvedPaths(), + rootPaths, combinedIndexBuildItem.getIndex(), curateOutcomeBuildItem.getApplicationModel().getAppArtifact()); attributes.forEach(attribute -> context.addContextAttribute(attribute.getName(), attribute.getValue())); @@ -212,6 +218,28 @@ public EfestoGeneratedClassBuildItem reflectiveEfestoGeneratedClassBuildItem(Kog return new EfestoGeneratedClassBuildItem(kogitoGeneratedSourcesBuildItem.getGeneratedFiles()); } + static PathCollection getRootPaths(PathCollection resolvedPaths) { + AtomicReference toReturnRef = new AtomicReference<>(resolvedPaths); + if (resolvedPaths.stream().noneMatch(path -> path.endsWith(File.separator + "generated-resources"))) { + Optional optClassesPath = + resolvedPaths.stream().filter(path -> { + String fullPath = path.toString(); + String dir = fullPath.substring(fullPath.lastIndexOf(File.separator) + 1); + return dir.equals("classes"); + }).findFirst(); + optClassesPath.ifPresent(classesPath -> { + Path toAdd = Path.of(classesPath.toString().replace(File.separator + "classes", + File.separator + + "generated" + + "-resources")); + List prevPaths = toReturnRef.get().stream().collect(Collectors.toList()); + prevPaths.add(toAdd); + toReturnRef.set(PathList.from(prevPaths)); + }); + } + return toReturnRef.get(); + } + private Collection collectGeneratedFiles(KogitoGeneratedSourcesBuildItem sources, List preSources, List postSources) { Map map = new HashMap<>(); diff --git a/quarkus/extensions/kogito-quarkus-extension-common/kogito-quarkus-common-deployment/src/test/java/org/kie/kogito/quarkus/common/deployment/KogitoAssetsProcessorTest.java b/quarkus/extensions/kogito-quarkus-extension-common/kogito-quarkus-common-deployment/src/test/java/org/kie/kogito/quarkus/common/deployment/KogitoAssetsProcessorTest.java new file mode 100644 index 00000000000..1adeac2ce64 --- /dev/null +++ b/quarkus/extensions/kogito-quarkus-extension-common/kogito-quarkus-common-deployment/src/test/java/org/kie/kogito/quarkus/common/deployment/KogitoAssetsProcessorTest.java @@ -0,0 +1,46 @@ +package org.kie.kogito.quarkus.common.deployment; + +import java.io.File; +import java.nio.file.Path; +import java.util.Arrays; + +import io.quarkus.bootstrap.model.PathsCollection; +import io.quarkus.paths.PathCollection; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +class KogitoAssetsProcessorTest { + + @Test + void getRootPathsWithoutClasses() { + String projectDirPath = "projectDir"; + String outputTargetPath = "outputTarget"; + Path projectDir = Path.of(projectDirPath); + Path outputTarget = Path.of(outputTargetPath); + Iterable paths = Arrays.asList(projectDir, outputTarget); + + PathCollection resolvedPaths = PathsCollection.from(paths); + PathCollection retrieved = KogitoAssetsProcessor.getRootPaths(resolvedPaths); + assertEquals(resolvedPaths.size(), retrieved.size()); + paths.forEach(expected -> assertTrue(retrieved.contains(expected))); + } + + @Test + void getRootPathsWithClasses() { + String projectDirPath = "projectDir"; + String outputTargetPath = "outputTarget"; + String outputTargetPathClasses = String.format("%s/%s/classes", projectDirPath, outputTargetPath).replace("/", File.separator); + Path projectDir = Path.of(projectDirPath); + Path outputTarget = Path.of(outputTargetPathClasses); + Iterable paths = Arrays.asList(projectDir, outputTarget); + + PathCollection resolvedPaths = PathsCollection.from(paths); + PathCollection retrieved = KogitoAssetsProcessor.getRootPaths(resolvedPaths); + assertEquals(resolvedPaths.size() + 1, retrieved.size()); + paths.forEach(expected -> assertTrue(retrieved.contains(expected))); + String expectedPath = String.format("%s/%s/generated-resources", projectDirPath, outputTargetPath).replace("/", File.separator); + assertTrue(retrieved.contains(Path.of(expectedPath))); + } +} \ No newline at end of file