Search in sources :

Example 11 with IReportVisitor

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);
}
Also used : FileMultiReportOutput(org.jacoco.report.FileMultiReportOutput) MultiReportVisitor(org.jacoco.report.MultiReportVisitor) XMLFormatter(org.jacoco.report.xml.XMLFormatter) FileOutputStream(java.io.FileOutputStream) HTMLFormatter(org.jacoco.report.html.HTMLFormatter) ArrayList(java.util.ArrayList) CSVFormatter(org.jacoco.report.csv.CSVFormatter) IReportVisitor(org.jacoco.report.IReportVisitor)

Example 12 with IReportVisitor

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();
}
Also used : FileMultiReportOutput(org.jacoco.report.FileMultiReportOutput) DirectorySourceFileLocator(org.jacoco.report.DirectorySourceFileLocator) HTMLFormatter(org.jacoco.report.html.HTMLFormatter) IReportVisitor(org.jacoco.report.IReportVisitor)

Example 13 with IReportVisitor

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");
}
Also used : IReportVisitor(org.jacoco.report.IReportVisitor) Test(org.junit.Test)

Example 14 with IReportVisitor

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\""));
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) IReportVisitor(org.jacoco.report.IReportVisitor) Test(org.junit.Test)

Example 15 with IReportVisitor

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);
    }
}
Also used : IOException(java.io.IOException) IReportVisitor(org.jacoco.report.IReportVisitor) MavenReportException(org.apache.maven.reporting.MavenReportException)

Aggregations

IReportVisitor (org.jacoco.report.IReportVisitor)19 Test (org.junit.Test)6 IOException (java.io.IOException)4 Collection (java.util.Collection)4 List (java.util.List)4 ISourceFileLocator (org.jacoco.report.ISourceFileLocator)4 IBundleCoverage (org.jacoco.core.analysis.IBundleCoverage)3 FileMultiReportOutput (org.jacoco.report.FileMultiReportOutput)3 HTMLFormatter (org.jacoco.report.html.HTMLFormatter)3 BufferedReader (java.io.BufferedReader)2 FileOutputStream (java.io.FileOutputStream)2 InputStreamReader (java.io.InputStreamReader)2 ArrayList (java.util.ArrayList)2 SessionInfo (org.jacoco.core.data.SessionInfo)2 MultiReportVisitor (org.jacoco.report.MultiReportVisitor)2 CSVFormatter (org.jacoco.report.csv.CSVFormatter)2 File (java.io.File)1 FileWriter (java.io.FileWriter)1 OutputStreamWriter (java.io.OutputStreamWriter)1 PrintWriter (java.io.PrintWriter)1