From 6eac0b846561b366c58f80137196b7903abaa4fe Mon Sep 17 00:00:00 2001 From: Nikita Tkachenko <121111529+nikita-tkachenko-datadog@users.noreply.github.com> Date: Mon, 4 Nov 2024 15:37:45 +0100 Subject: [PATCH] Dump Jacoco XML reports for debug purposes (#7862) --- .../percentage/JacocoCoverageCalculator.java | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/coverage/percentage/JacocoCoverageCalculator.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/coverage/percentage/JacocoCoverageCalculator.java index aba4c12551e..fa97538b40e 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/coverage/percentage/JacocoCoverageCalculator.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/coverage/percentage/JacocoCoverageCalculator.java @@ -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; @@ -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; @@ -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); }