org.jacoco.core.data.ExecutionDataStore Java Examples

The following examples show how to use org.jacoco.core.data.ExecutionDataStore. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BranchDetailAnalyzer.java    From bazel with Apache License 2.0 5 votes vote down vote up
public BranchDetailAnalyzer(final ExecutionDataStore executionData) {
  super(
      executionData,
      new ICoverageVisitor() {
        @Override
        public void visitCoverage(IClassCoverage coverage) {}
      });
  this.executionData = executionData;
  this.branchDetails = new TreeMap<String, BranchCoverageDetail>();
}
 
Example #2
Source File: JaCoCoReportAnalyzer.java    From tikione-jacocoverage with MIT License 5 votes vote down vote up
/**
 * Load a JaCoCo binary report and convert it to HTML.
 * <br/>See <a href="http://www.eclemma.org/jacoco/trunk/doc/examples/java/ReportGenerator.java">report generator example code</a>.
 *
 * @param jacocoexec the JaCoCo binary report.
 * @param reportdir the folder to store HTML report.
 * @param prjClassesDir the directory containing project's compiled classes.
 * @param prjSourcesDir the directory containing project's Java source files.
 * @param projectName the project's name.
 * @return the absolute path of HTML report's {@code index.html} file.
 * @throws FileNotFoundException if the JaCoCo binary report, compiled classes or Java sources files directory can't be found.
 * @throws IOException if an I/O error occurs.
 */
public static String toHtmlReport(File jacocoexec, File reportdir, File prjClassesDir, File prjSourcesDir, String projectName)
        throws FileNotFoundException,
               IOException {
    // Load the JaCoCo binary report.
    FileInputStream fis = new FileInputStream(jacocoexec);
    ExecutionDataStore executionDataStore = new ExecutionDataStore();
    SessionInfoStore sessionInfoStore = new SessionInfoStore();
    try {
        ExecutionDataReader executionDataReader = new ExecutionDataReader(fis);
        executionDataReader.setExecutionDataVisitor(executionDataStore);
        executionDataReader.setSessionInfoVisitor(sessionInfoStore);
        while (executionDataReader.read()) {
        }
    } finally {
        fis.close();
    }

    // Convert the binary report to HTML.
    CoverageBuilder coverageBuilder = new CoverageBuilder();
    Analyzer analyzer = new Analyzer(executionDataStore, coverageBuilder);
    analyzer.analyzeAll(prjClassesDir);
    IBundleCoverage bundleCoverage = coverageBuilder.getBundle("JaCoCoverage analysis of project \"" + projectName
            + "\" (powered by JaCoCo from EclEmma)");
    HTMLFormatter htmlformatter = new HTMLFormatter();
    IReportVisitor visitor = htmlformatter.createVisitor(new FileMultiReportOutput(reportdir));
    visitor.visitInfo(sessionInfoStore.getInfos(), executionDataStore.getContents());
    visitor.visitBundle(bundleCoverage, new DirectorySourceFileLocator(prjSourcesDir, DEF_ENCODING, 4));
    visitor.visitEnd();
    return new File(reportdir, "index.html").getAbsolutePath();
}
 
Example #3
Source File: JaCoCoReportAnalyzer.java    From tikione-jacocoverage with MIT License 5 votes vote down vote up
/**
 * Load a JaCoCo binary report and convert it to XML.
 * <br/>See <a href="http://www.eclemma.org/jacoco/trunk/doc/examples/java/ReportGenerator.java">report generator example code</a>.
 *
 * @param jacocoexec the JaCoCo binary report.
 * @param xmlreport the XML file to generate.
 * @param prjClassesDir the directory containing project's compiled classes.
 * @param prjSourcesDir the directory containing project's Java source files.
 * @throws FileNotFoundException if the JaCoCo binary report, compiled classes or Java sources files directory can't be found.
 * @throws IOException if an I/O error occurs.
 */
public static void toXmlReport(File jacocoexec, File xmlreport, File prjClassesDir, File prjSourcesDir)
        throws FileNotFoundException,
               IOException {
    // Load the JaCoCo binary report.
    FileInputStream fis = new FileInputStream(jacocoexec);
    ExecutionDataStore executionDataStore = new ExecutionDataStore();
    SessionInfoStore sessionInfoStore = new SessionInfoStore();
    try {
        ExecutionDataReader executionDataReader = new ExecutionDataReader(fis);
        executionDataReader.setExecutionDataVisitor(executionDataStore);
        executionDataReader.setSessionInfoVisitor(sessionInfoStore);
        while (executionDataReader.read()) {
        }
    } finally {
        fis.close();
    }

    // Convert the binary report to XML.
    CoverageBuilder coverageBuilder = new CoverageBuilder();
    Analyzer analyzer = new Analyzer(executionDataStore, coverageBuilder);
    analyzer.analyzeAll(prjClassesDir);
    IBundleCoverage bundleCoverage = coverageBuilder.getBundle("JaCoCoverage analysis (powered by JaCoCo from EclEmma)");
    XMLFormatter xmlformatter = new XMLFormatter();
    xmlformatter.setOutputEncoding(DEF_ENCODING);
    IReportVisitor visitor = xmlformatter.createVisitor(new FileOutputStream(xmlreport));
    visitor.visitInfo(sessionInfoStore.getInfos(), executionDataStore.getContents());
    visitor.visitBundle(bundleCoverage, new DirectorySourceFileLocator(prjSourcesDir, DEF_ENCODING, 4));
    visitor.visitEnd();
}