From a486cba8bce371da388ba79459e71aae55a4de95 Mon Sep 17 00:00:00 2001 From: Dmitri Bourlatchkov Date: Thu, 26 Aug 2021 21:13:00 -0400 Subject: [PATCH] Add config property for reusing jacoco data files This is to allow aggregating coverage results from multiple test JVMs, for example when using the Surefire property reuseForks = false JaCoCo itself has configuration settings to allow appending coverage data to an existing file (which is its default behaviour). The Quarkus default behaviour is unchanged (the jacoco data file is deleted before each run). --- .../java/io/quarkus/jacoco/deployment/JacocoProcessor.java | 4 +++- .../main/java/io/quarkus/jacoco/runtime/JacocoConfig.java | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) 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 fa90e3beb8208..2f825a126f179 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 @@ -61,7 +61,9 @@ void transformerBuildItem(BuildProducer transforme + config.dataFile; System.setProperty("jacoco-agent.destfile", dataFile); - Files.deleteIfExists(Paths.get(dataFile)); + if (!config.reuseDataFile) { + Files.deleteIfExists(Paths.get(dataFile)); + } Instrumenter instrumenter = new Instrumenter(new OfflineInstrumentationAccessGenerator()); Set seen = new HashSet<>(); 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 971402a6c5da5..67a5bda9385ac 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 @@ -16,6 +16,13 @@ public class JacocoConfig { @ConfigItem(defaultValue = "jacoco-quarkus.exec") public String dataFile; + /** + * Whether to reuse ({@code true}) or delete ({@code false}) the jacoco + * data file on each run. + */ + @ConfigItem(defaultValue = "false") + public boolean reuseDataFile; + /** * If Quarkus should generate the Jacoco report */