use of org.jacoco.report.IReportVisitor in project jacoco by jacoco.
the class Report method createReportVisitor.
private IReportVisitor createReportVisitor() throws IOException, IOException {
final List<IReportVisitor> visitors = new ArrayList<IReportVisitor>();
if (xml != null) {
final XMLFormatter formatter = new XMLFormatter();
visitors.add(formatter.createVisitor(new FileOutputStream(xml)));
}
if (csv != null) {
final CSVFormatter formatter = new CSVFormatter();
visitors.add(formatter.createVisitor(new FileOutputStream(csv)));
}
if (html != null) {
final HTMLFormatter formatter = new HTMLFormatter();
visitors.add(formatter.createVisitor(new FileMultiReportOutput(html)));
}
return new MultiReportVisitor(visitors);
}
use of org.jacoco.report.IReportVisitor in project jacoco by jacoco.
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
final HTMLFormatter htmlFormatter = new HTMLFormatter();
final IReportVisitor visitor = htmlFormatter.createVisitor(new FileMultiReportOutput(reportDirectory));
// 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, new DirectorySourceFileLocator(sourceDirectory, "utf-8", 4));
// 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 XMLFormatterTest method testStructureWithBundleOnly.
@Test
public void testStructureWithBundleOnly() throws Exception {
final IReportVisitor visitor = formatter.createVisitor(output);
visitor.visitInfo(infos, data);
driver.sendBundle(visitor);
assertPathMatches("bundle", "/report/@name");
assertPathMatches("org/jacoco/example", "/report/package/@name");
assertPathMatches("org/jacoco/example/FooClass", "/report/package/class/@name");
assertPathMatches("fooMethod", "/report/package/class/method/@name");
assertPathMatches("1", "count(/report/counter[@type='INSTRUCTION'])");
assertPathMatches("10", "report/counter[@type='INSTRUCTION']/@missed");
assertPathMatches("15", "report/counter[@type='INSTRUCTION']/@covered");
assertPathMatches("1", "count(/report/counter[@type='BRANCH'])");
assertPathMatches("1", "report/counter[@type='BRANCH']/@missed");
assertPathMatches("2", "report/counter[@type='BRANCH']/@covered");
assertPathMatches("1", "count(/report/counter[@type='COMPLEXITY'])");
assertPathMatches("1", "report/counter[@type='COMPLEXITY']/@missed");
assertPathMatches("2", "report/counter[@type='COMPLEXITY']/@covered");
assertPathMatches("1", "count(/report/counter[@type='LINE'])");
assertPathMatches("0", "report/counter[@type='LINE']/@missed");
assertPathMatches("3", "report/counter[@type='LINE']/@covered");
assertPathMatches("1", "count(/report/counter[@type='METHOD'])");
assertPathMatches("0", "report/counter[@type='METHOD']/@missed");
assertPathMatches("1", "report/counter[@type='METHOD']/@covered");
assertPathMatches("1", "count(/report/counter[@type='CLASS'])");
assertPathMatches("0", "report/counter[@type='CLASS']/@missed");
assertPathMatches("1", "report/counter[@type='CLASS']/@covered");
}
use of org.jacoco.report.IReportVisitor in project jacoco by jacoco.
the class XMLFormatterTest method testSetEncoding.
@Test
public void testSetEncoding() throws Exception {
formatter.setOutputEncoding("UTF-16");
final IReportVisitor visitor = formatter.createVisitor(output);
visitor.visitInfo(infos, data);
driver.sendBundle(visitor);
final BufferedReader reader = new BufferedReader(new InputStreamReader(output.getContentsAsStream(), "UTF-16"));
final String line = reader.readLine();
assertTrue(line, line.startsWith("<?xml version=\"1.0\" encoding=\"UTF-16\""));
}
use of org.jacoco.report.IReportVisitor in project jacoco by jacoco.
the class AbstractReportMojo method executeReport.
@Override
protected void executeReport(final Locale locale) throws MavenReportException {
try {
final ReportSupport support = new ReportSupport(getLog());
loadExecutionData(support);
addFormatters(support, locale);
final IReportVisitor visitor = support.initRootVisitor();
createReport(visitor, support);
visitor.visitEnd();
} catch (final IOException e) {
throw new MavenReportException("Error while creating report: " + e.getMessage(), e);
}
}
Aggregations