use of org.jacoco.report.IReportVisitor in project buck by facebook.
the class ReportGenerator method createReport.
private void createReport(final IBundleCoverage bundleCoverage) throws IOException {
// Create a concrete report visitor based on some supplied
// configuration. In this case we use the defaults
IReportVisitor visitor;
switch(reportFormat) {
case "csv":
reportDirectory.mkdirs();
CSVFormatter csvFormatter = new CSVFormatter();
visitor = csvFormatter.createVisitor(new FileOutputStream(new File(reportDirectory, "coverage.csv")));
break;
case "html":
HTMLFormatter htmlFormatter = new HTMLFormatter();
visitor = htmlFormatter.createVisitor(new FileMultiReportOutput(reportDirectory));
break;
case "xml":
reportDirectory.mkdirs();
XMLFormatter xmlFormatter = new XMLFormatter();
visitor = xmlFormatter.createVisitor(new FileOutputStream(new File(reportDirectory, "coverage.xml")));
break;
default:
throw new RuntimeException("Unable to parse format: " + reportFormat);
}
// Initialize the report with all of the execution and session
// information. At this point the report doesn't know about the
// structure of the report being created
visitor.visitInfo(execFileLoader.getSessionInfoStore().getInfos(), execFileLoader.getExecutionDataStore().getContents());
// Populate the report structure with the bundle coverage information.
// Call visitGroup if you need groups in your report.
visitor.visitBundle(bundleCoverage, createSourceFileLocator());
// Signal end of structure information to allow report to write all
// information out
visitor.visitEnd();
}
use of org.jacoco.report.IReportVisitor in project jacoco by jacoco.
the class ReportSupport method initRootVisitor.
public IReportVisitor initRootVisitor() throws IOException {
final IReportVisitor visitor = new MultiReportVisitor(formatters);
visitor.visitInfo(loader.getSessionInfoStore().getInfos(), loader.getExecutionDataStore().getContents());
return visitor;
}
use of org.jacoco.report.IReportVisitor in project jacoco by jacoco.
the class XMLFormatterTest method testStructureWithNestedGroups.
@Test
public void testStructureWithNestedGroups() throws Exception {
final IReportVisitor visitor = formatter.createVisitor(output);
visitor.visitInfo(infos, data);
driver.sendNestedGroups(visitor);
assertPathMatches("report", "/report/@name");
assertPathMatches("group1", "/report/group[1]/@name");
assertPathMatches("group", "/report/group[1]/group[1]/@name");
assertPathMatches("bundle", "/report/group[1]/group[1]/group[1]/@name");
assertPathMatches("bundle", "/report/group[2]/@name");
}
use of org.jacoco.report.IReportVisitor in project jacoco by jacoco.
the class XMLFormatterTest method testSessionInfo.
@Test
public void testSessionInfo() throws Exception {
infos.add(new SessionInfo("session-1", 12345, 67890));
infos.add(new SessionInfo("session-2", 1, 2));
infos.add(new SessionInfo("session-3", 1, 2));
final IReportVisitor visitor = formatter.createVisitor(output);
visitor.visitInfo(infos, data);
visitor.visitGroup("foo");
visitor.visitEnd();
assertPathMatches("session-1", "/report/sessioninfo[1]/@id");
assertPathMatches("12345", "/report/sessioninfo[1]/@start");
assertPathMatches("67890", "/report/sessioninfo[1]/@dump");
assertPathMatches("session-2", "/report/sessioninfo[2]/@id");
assertPathMatches("session-3", "/report/sessioninfo[3]/@id");
}
use of org.jacoco.report.IReportVisitor in project jacoco by jacoco.
the class XMLFormatterTest method testDefaultEncoding.
@Test
public void testDefaultEncoding() throws Exception {
final IReportVisitor visitor = formatter.createVisitor(output);
visitor.visitInfo(infos, data);
driver.sendBundle(visitor);
final BufferedReader reader = new BufferedReader(new InputStreamReader(output.getContentsAsStream(), "UTF-8"));
final String line = reader.readLine();
assertTrue(line, line.startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\""));
}
Aggregations