Skip to content

Commit

Permalink
Dump Jacoco XML reports for debug purposes (#7862)
Browse files Browse the repository at this point in the history
  • Loading branch information
nikita-tkachenko-datadog authored Nov 4, 2024
1 parent 37469ea commit 6eac0b8
Showing 1 changed file with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
Expand Down Expand Up @@ -43,6 +44,7 @@
import org.jacoco.report.IReportVisitor;
import org.jacoco.report.InputStreamSourceFileLocator;
import org.jacoco.report.html.HTMLFormatter;
import org.jacoco.report.xml.XMLFormatter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -290,12 +292,23 @@ private void dumpCoverageReport(IBundleCoverage coverageBundle, File reportFolde
}
try {
final HTMLFormatter htmlFormatter = new HTMLFormatter();
final IReportVisitor visitor =

final IReportVisitor htmlVisitor =
htmlFormatter.createVisitor(new FileMultiReportOutput(reportFolder));
visitor.visitInfo(Collections.emptyList(), Collections.emptyList());
visitor.visitBundle(
htmlVisitor.visitInfo(Collections.emptyList(), Collections.emptyList());
htmlVisitor.visitBundle(
coverageBundle, new RepoIndexFileLocator(repoIndexProvider.getIndex(), repoRoot));
visitor.visitEnd();
htmlVisitor.visitEnd();

File xmlReport = new File(reportFolder, "jacoco.xml");
try (FileOutputStream xmlReportStream = new FileOutputStream(xmlReport)) {
XMLFormatter xmlFormatter = new XMLFormatter();
IReportVisitor xmlVisitor = xmlFormatter.createVisitor(xmlReportStream);
xmlVisitor.visitInfo(Collections.emptyList(), Collections.emptyList());
xmlVisitor.visitBundle(
coverageBundle, new RepoIndexFileLocator(repoIndexProvider.getIndex(), repoRoot));
xmlVisitor.visitEnd();
}
} catch (Exception e) {
LOGGER.error("Error while creating report in {}", reportFolder, e);
}
Expand Down

0 comments on commit 6eac0b8

Please sign in to comment.