org.jacoco.core.tools.ExecFileLoader Java Examples

The following examples show how to use org.jacoco.core.tools.ExecFileLoader. 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: JacocoDump.java    From gradle-plugins with MIT License 6 votes vote down vote up
@Override
public void execute() {

    ExecDumpClient client = new ExecDumpClient();

    client.setDump(getParameters().getDump().getOrElse(false));
    client.setReset(getParameters().getReset().getOrElse(false));
    client.setRetryCount(getParameters().getRetryCount().getOrElse(0));

    try {
        ExecFileLoader loader = client.dump(getParameters().getAddress().get(), getParameters().getPort().get());
        if (getParameters().getDump().getOrElse(false)) {
            loader.save(getParameters().getDestfile().get().getAsFile(), getParameters().getAppend().get());
        }
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
 
Example #2
Source File: JacocoDump.java    From gradle-plugins with MIT License 6 votes vote down vote up
@Override
public void execute() {

    ExecDumpClient client = new ExecDumpClient();

    client.setDump(getParameters().getDump().getOrElse(false));
    client.setReset(getParameters().getReset().getOrElse(false));
    client.setRetryCount(getParameters().getRetryCount().getOrElse(0));

    try {
        ExecFileLoader loader = client.dump(getParameters().getAddress().get(), getParameters().getPort().get());
        if (getParameters().getDump().getOrElse(false)) {
            loader.save(getParameters().getDestfile().get().getAsFile(), getParameters().getAppend().get());
        }
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
 
Example #3
Source File: JacocoNBModuleReportGenerator.java    From tikione-jacocoverage with MIT License 6 votes vote down vote up
public JacocoNBModuleReportGenerator(File executationDataFile, File reportdir, boolean xmlReport) throws IOException {
	this.executionDataFile = executationDataFile;
	execFileLoader = new ExecFileLoader();
	execFileLoader.load(executionDataFile);

	if (xmlReport) {
		XMLFormatter xmlformatter = new XMLFormatter();
		xmlformatter.setOutputEncoding(DEF_ENCODING);
		visitor = xmlformatter.createVisitor(new FileOutputStream(reportdir));
	} else {
		HTMLFormatter htmlFormater = new HTMLFormatter();
		visitor = htmlFormater.createVisitor(new FileMultiReportOutput(reportdir));
	}
	visitor.visitInfo(execFileLoader.getSessionInfoStore().getInfos(), execFileLoader.getExecutionDataStore().getContents());
	groupVisitor = visitor.visitGroup("JaCoCo Coverage Report");
}
 
Example #4
Source File: ReportGenerator.java    From buck with Apache License 2.0 6 votes vote down vote up
/** Create a new generator based for the given project. */
public ReportGenerator(Properties properties) {
  String jacocoOutputDir = properties.getProperty("jacoco.output.dir");
  this.title = properties.getProperty("jacoco.title");
  this.executionDataFile =
      new File(jacocoOutputDir, properties.getProperty("jacoco.exec.data.file"));
  this.execFileLoader = new ExecFileLoader();
  this.classesPath = properties.getProperty("classes.dir");
  this.sourcesPath = properties.getProperty("src.dir");
  this.reportDirectory = new File(jacocoOutputDir, "code-coverage");
  this.reportFormats =
      new HashSet<>(
          Splitter.on(",").splitToList(properties.getProperty("jacoco.format", "html")));
  this.coverageIncludes = properties.getProperty("jacoco.includes", "**");
  this.coverageExcludes = properties.getProperty("jacoco.excludes", "");
}
 
Example #5
Source File: ReproGuidance.java    From JQF with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void jacocoCheckpoint(File classFile, File csvDir) {
    int idx = nextFileIdx;
    csvDir.mkdirs();
    try {
        // Get exec data by dynamically calling RT.getAgent().getExecutionData()
        Class RT = Class.forName("org.jacoco.agent.rt.RT");
        Method getAgent = RT.getMethod("getAgent");
        Object agent = getAgent.invoke(null);
        Method dump = agent.getClass().getMethod("getExecutionData", boolean.class);
        byte[] execData = (byte[]) dump.invoke(agent, false);

        // Analyze exec data
        ExecFileLoader loader = new ExecFileLoader();
        loader.load(new ByteArrayInputStream(execData));
        final CoverageBuilder builder = new CoverageBuilder();
        Analyzer analyzer = new Analyzer(loader.getExecutionDataStore(), builder);
        analyzer.analyzeAll(classFile);

        // Generate CSV
        File csv = new File(csvDir, String.format("cov-%05d.csv", idx));
        try (FileOutputStream out = new FileOutputStream(csv)) {
            IReportVisitor coverageVisitor = new CSVFormatter().createVisitor(out);
            coverageVisitor.visitBundle(builder.getBundle("JQF"), null);
            coverageVisitor.visitEnd();
            out.flush();
        }


    } catch (Exception e) {
        System.err.println(e);
    }
}
 
Example #6
Source File: JacocoCoverageRunner.java    From bazel with Apache License 2.0 5 votes vote down vote up
public void create() throws IOException {
  // Read the jacoco.exec file. Multiple data files could be merged at this point
  execFileLoader = new ExecFileLoader();
  execFileLoader.load(executionData);

  // Run the structure analyzer on a single class folder or jar file to build up the coverage
  // model. Typically you would create a bundle for each class folder and each jar you want in
  // your report. If you have more than one bundle you may need to add a grouping node to the
  // report. The lcov formatter doesn't seem to care, and we're only using one bundle anyway.
  final IBundleCoverage bundleCoverage = analyzeStructure();

  final Map<String, BranchCoverageDetail> branchDetails = analyzeBranch();
  createReport(bundleCoverage, branchDetails);
}