diff --git a/test-framework/jacoco/deployment/src/main/java/io/quarkus/jacoco/deployment/JacocoProcessor.java b/test-framework/jacoco/deployment/src/main/java/io/quarkus/jacoco/deployment/JacocoProcessor.java index faa34417fa478..71737b32cc254 100644 --- a/test-framework/jacoco/deployment/src/main/java/io/quarkus/jacoco/deployment/JacocoProcessor.java +++ b/test-framework/jacoco/deployment/src/main/java/io/quarkus/jacoco/deployment/JacocoProcessor.java @@ -7,6 +7,7 @@ import java.nio.file.Paths; import java.util.Collections; import java.util.HashSet; +import java.util.Optional; import java.util.Set; import java.util.function.BiFunction; @@ -35,6 +36,9 @@ public class JacocoProcessor { + public static final String JACOCO_QUARKUS_EXEC = "jacoco-quarkus.exec"; + public static final String JACOCO_REPORT = "jacoco-report"; + @BuildStep(onlyIf = IsTest.class) FeatureBuildItem feature() { return new FeatureBuildItem("jacoco"); @@ -53,10 +57,8 @@ void transformerBuildItem(BuildProducer transforme return; } - String dataFile = outputTargetBuildItem.getOutputDirectory().toAbsolutePath().toString() + File.separator - + config.dataFile; - System.setProperty("jacoco-agent.destfile", - dataFile); + String dataFile = getFilePath(config.dataFile, outputTargetBuildItem.getOutputDirectory(), JACOCO_QUARKUS_EXEC); + System.setProperty("jacoco-agent.destfile", dataFile); if (!config.reuseDataFile) { Files.deleteIfExists(Paths.get(dataFile)); } @@ -95,8 +97,7 @@ public byte[] apply(String className, byte[] bytes) { info.dataFile = dataFile; File targetdir = new File( - outputTargetBuildItem.getOutputDirectory().toAbsolutePath().toString() + File.separator - + config.reportLocation); + getFilePath(config.reportLocation, outputTargetBuildItem.getOutputDirectory(), JACOCO_REPORT)); info.reportDir = targetdir.getAbsolutePath(); String includes = String.join(",", config.includes); String excludes = String.join(",", config.excludes.orElse(Collections.emptyList())); @@ -122,7 +123,8 @@ public byte[] apply(String className, byte[] bytes) { private void addProjectModule(ResolvedDependency module, JacocoConfig config, ReportInfo info, String includes, String excludes, Set classes, Set sources) throws Exception { - info.savedData.add(new File(module.getWorkspaceModule().getBuildDir(), config.dataFile).getAbsolutePath()); + String dataFile = getFilePath(config.dataFile, module.getWorkspaceModule().getBuildDir().toPath(), JACOCO_QUARKUS_EXEC); + info.savedData.add(new File(dataFile).getAbsolutePath()); if (module.getSources() == null) { return; } @@ -140,4 +142,8 @@ private void addProjectModule(ResolvedDependency module, JacocoConfig config, Re } } } + + private String getFilePath(Optional path, Path outputDirectory, String defaultRelativePath) { + return path.orElse(outputDirectory.toAbsolutePath() + File.separator + defaultRelativePath); + } } diff --git a/test-framework/jacoco/runtime/src/main/java/io/quarkus/jacoco/runtime/JacocoConfig.java b/test-framework/jacoco/runtime/src/main/java/io/quarkus/jacoco/runtime/JacocoConfig.java index 0caf97b1d1582..4e5738cdd9288 100644 --- a/test-framework/jacoco/runtime/src/main/java/io/quarkus/jacoco/runtime/JacocoConfig.java +++ b/test-framework/jacoco/runtime/src/main/java/io/quarkus/jacoco/runtime/JacocoConfig.java @@ -11,10 +11,11 @@ public class JacocoConfig { /** - * The jacoco data file + * The jacoco data file. By default this will be target/jacoco-quarkus.exec. + * The path can be relative (to the module) or absolute. */ - @ConfigItem(defaultValue = "jacoco-quarkus.exec") - public String dataFile; + @ConfigItem + public Optional dataFile; /** * Whether to reuse ({@code true}) or delete ({@code false}) the jacoco @@ -82,8 +83,9 @@ public class JacocoConfig { public Optional> excludes; /** - * The location of the report files. + * The location of the report files. By default this will be target/jacoco-report. + * The path can be relative (to the module) or absolute. */ - @ConfigItem(defaultValue = "jacoco-report") - public String reportLocation; + @ConfigItem + public Optional reportLocation; }