From 646261350068d72d0270d10ab0cfbd9de6078279 Mon Sep 17 00:00:00 2001 From: Stuart Douglas Date: Tue, 6 Apr 2021 11:56:09 +1000 Subject: [PATCH] Jacoco multi module fixes Load the class data from all modules --- .../quarkus/jacoco/deployment/JacocoProcessor.java | 3 ++- .../io/quarkus/jacoco/runtime/ReportCreator.java | 14 +++++++++++--- .../java/io/quarkus/jacoco/runtime/ReportInfo.java | 5 ++++- 3 files changed, 17 insertions(+), 5 deletions(-) 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 03aaee1039efa..e859e1a44566f 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 @@ -80,7 +80,7 @@ public byte[] apply(String className, byte[] bytes) { } if (config.report) { ReportInfo info = new ReportInfo(); - info.savedData = dataFile; + info.dataFile = dataFile; File targetdir = new File( outputTargetBuildItem.getOutputDirectory().toAbsolutePath().toString() + File.separator @@ -96,6 +96,7 @@ public byte[] apply(String className, byte[] bytes) { if (BuildToolHelper.isMavenProject(targetdir.toPath())) { LocalProject project = LocalProject.loadWorkspace(targetdir.toPath()); for (Map.Entry i : project.getWorkspace().getProjects().entrySet()) { + info.savedData.add(i.getValue().getOutputDir().resolve(config.dataFile).toAbsolutePath().toString()); sources.add(i.getValue().getSourcesSourcesDir().toFile().getAbsolutePath()); File classesDir = i.getValue().getClassesDir().toFile(); if (classesDir.isDirectory()) { diff --git a/test-framework/jacoco/runtime/src/main/java/io/quarkus/jacoco/runtime/ReportCreator.java b/test-framework/jacoco/runtime/src/main/java/io/quarkus/jacoco/runtime/ReportCreator.java index 5960feb5bc519..be2ec2bd09a5e 100644 --- a/test-framework/jacoco/runtime/src/main/java/io/quarkus/jacoco/runtime/ReportCreator.java +++ b/test-framework/jacoco/runtime/src/main/java/io/quarkus/jacoco/runtime/ReportCreator.java @@ -42,7 +42,7 @@ public void run() { //the jacoco data is also generated by a shutdown hook //we need to wait for the file. We wait at most 10s long abortTime = System.currentTimeMillis() + 10000; - Path datafile = Paths.get(reportInfo.savedData); + Path datafile = Paths.get(reportInfo.dataFile); while (System.currentTimeMillis() < abortTime) { if (Files.exists(datafile)) { break; @@ -65,12 +65,20 @@ public void run() { } } ExecFileLoader loader = new ExecFileLoader(); - loader.load(datafile.toFile()); + for (String i : reportInfo.savedData) { + File file = new File(i); + if (file.exists()) { + loader.load(file); + } + } final CoverageBuilder builder = new CoverageBuilder(); final Analyzer analyzer = new Analyzer( loader.getExecutionDataStore(), builder); for (String i : reportInfo.classFiles) { - analyzer.analyzeAll(new File(i)); + File file = new File(i); + if (file.exists()) { + analyzer.analyzeAll(file); + } } List formatters = new ArrayList<>(); diff --git a/test-framework/jacoco/runtime/src/main/java/io/quarkus/jacoco/runtime/ReportInfo.java b/test-framework/jacoco/runtime/src/main/java/io/quarkus/jacoco/runtime/ReportInfo.java index 5250e54e7f0c4..76a21cbf969c8 100644 --- a/test-framework/jacoco/runtime/src/main/java/io/quarkus/jacoco/runtime/ReportInfo.java +++ b/test-framework/jacoco/runtime/src/main/java/io/quarkus/jacoco/runtime/ReportInfo.java @@ -1,11 +1,14 @@ package io.quarkus.jacoco.runtime; +import java.util.ArrayList; +import java.util.List; import java.util.Set; public class ReportInfo { public String reportDir; - public String savedData; + public String dataFile; + public final List savedData = new ArrayList<>(); public Set sourceDirectories; public Set classFiles; public String artifactId;