Search in sources :

Example 1 with IReportVisitor

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

Example 2 with IReportVisitor

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

Example 3 with IReportVisitor

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

Example 4 with IReportVisitor

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

Example 5 with IReportVisitor

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

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