Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[incubator-kie-issues#847] Include generated-resources to quarkus artifact #3427

Merged
merged 9 commits into from
Mar 8, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Object> executeScenario(KieContainer kieContainer,
ScenarioRunnerData scenarioRunnerData,
Expand Down Expand Up @@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -102,9 +107,10 @@ public class KogitoAssetsProcessor {
@BuildStep
public KogitoBuildContextBuildItem generateKogitoBuildContext(List<KogitoBuildContextAttributeBuildItem> 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()));
Expand Down Expand Up @@ -212,6 +218,28 @@ public EfestoGeneratedClassBuildItem reflectiveEfestoGeneratedClassBuildItem(Kog
return new EfestoGeneratedClassBuildItem(kogitoGeneratedSourcesBuildItem.getGeneratedFiles());
}

static PathCollection getRootPaths(PathCollection resolvedPaths) {
AtomicReference<PathCollection> toReturnRef = new AtomicReference<>(resolvedPaths);
if (resolvedPaths.stream().noneMatch(path -> path.endsWith(File.separator + "generated-resources"))) {
Optional<Path> 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<Path> prevPaths = toReturnRef.get().stream().collect(Collectors.toList());
prevPaths.add(toAdd);
toReturnRef.set(PathList.from(prevPaths));
});
}
return toReturnRef.get();
}

private Collection<GeneratedFile> collectGeneratedFiles(KogitoGeneratedSourcesBuildItem sources, List<KogitoAddonsPreGeneratedSourcesBuildItem> preSources,
List<KogitoAddonsPostGeneratedSourcesBuildItem> postSources) {
Map<String, GeneratedFile> map = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Path> 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<Path> 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)));
}
}
Loading