Skip to content

Commit

Permalink
Merge pull request #16252 from stuartwdouglas/jacoco-multi-module
Browse files Browse the repository at this point in the history
Jacoco multi module fixes
  • Loading branch information
geoand authored Apr 6, 2021
2 parents b6d9783 + 6462613 commit ed2c339
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<AppArtifactKey, LocalProject> 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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<IReportVisitor> formatters = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String> savedData = new ArrayList<>();
public Set<String> sourceDirectories;
public Set<String> classFiles;
public String artifactId;
Expand Down

0 comments on commit ed2c339

Please sign in to comment.