Search in sources :

Example 6 with ExecFileLoader

use of org.jacoco.core.tools.ExecFileLoader in project bazel by bazelbuild.

the class JacocoCoverageRunner method create.

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);
}
Also used : IBundleCoverage(org.jacoco.core.analysis.IBundleCoverage) ExecFileLoader(org.jacoco.core.tools.ExecFileLoader)

Example 7 with ExecFileLoader

use of org.jacoco.core.tools.ExecFileLoader in project jacoco by jacoco.

the class DumpTask method execute.

@Override
public void execute() throws BuildException {
    if (port <= 0) {
        throw new BuildException("Invalid port value", getLocation());
    }
    if (dump && destfile == null) {
        throw new BuildException("Destination file is required when dumping execution data", getLocation());
    }
    final ExecDumpClient client = new ExecDumpClient() {

        @Override
        protected void onConnecting(final InetAddress address, final int port) {
            log(format("Connecting to %s:%s", address, Integer.valueOf(port)));
        }

        @Override
        protected void onConnectionFailure(final IOException exception) {
            log(exception.getMessage());
        }
    };
    client.setDump(dump);
    client.setReset(reset);
    client.setRetryCount(retryCount);
    try {
        final ExecFileLoader loader = client.dump(address, port);
        if (dump) {
            log(format("Dumping execution data to %s", destfile.getAbsolutePath()));
            loader.save(destfile, append);
        }
    } catch (final IOException e) {
        throw new BuildException("Unable to dump coverage data", e, getLocation());
    }
}
Also used : ExecDumpClient(org.jacoco.core.tools.ExecDumpClient) BuildException(org.apache.tools.ant.BuildException) IOException(java.io.IOException) InetAddress(java.net.InetAddress) ExecFileLoader(org.jacoco.core.tools.ExecFileLoader)

Example 8 with ExecFileLoader

use of org.jacoco.core.tools.ExecFileLoader in project jacoco by jacoco.

the class ReportTask method loadExecutionData.

private void loadExecutionData() {
    final ExecFileLoader loader = new ExecFileLoader();
    for (final Iterator<?> i = executiondataElement.iterator(); i.hasNext(); ) {
        final Resource resource = (Resource) i.next();
        log(format("Loading execution data file %s", resource));
        InputStream in = null;
        try {
            in = resource.getInputStream();
            loader.load(in);
        } catch (final IOException e) {
            throw new BuildException(format("Unable to read execution data file %s", resource), e, getLocation());
        } finally {
            FileUtils.close(in);
        }
    }
    sessionInfoStore = loader.getSessionInfoStore();
    executionDataStore = loader.getExecutionDataStore();
}
Also used : InputStream(java.io.InputStream) FileResource(org.apache.tools.ant.types.resources.FileResource) Resource(org.apache.tools.ant.types.Resource) IOException(java.io.IOException) BuildException(org.apache.tools.ant.BuildException) ExecFileLoader(org.jacoco.core.tools.ExecFileLoader)

Example 9 with ExecFileLoader

use of org.jacoco.core.tools.ExecFileLoader in project jacoco by jacoco.

the class Dump method execute.

@Override
public int execute(final PrintWriter out, final PrintWriter err) throws Exception {
    final ExecDumpClient client = new ExecDumpClient() {

        @Override
        protected void onConnecting(final InetAddress address, final int port) {
            out.printf("[INFO] Connecting to %s:%s.%n", address, Integer.valueOf(port));
        }

        @Override
        protected void onConnectionFailure(final IOException exception) {
            err.printf("[WARN] %s.%n", exception.getMessage());
        }
    };
    client.setReset(reset);
    client.setRetryCount(retrycount);
    final ExecFileLoader loader = client.dump(address, port);
    out.printf("[INFO] Writing execution data to %s.%n", destfile.getAbsolutePath());
    loader.save(destfile, true);
    return 0;
}
Also used : ExecDumpClient(org.jacoco.core.tools.ExecDumpClient) IOException(java.io.IOException) InetAddress(java.net.InetAddress) ExecFileLoader(org.jacoco.core.tools.ExecFileLoader)

Example 10 with ExecFileLoader

use of org.jacoco.core.tools.ExecFileLoader in project jacoco by jacoco.

the class Merge method loadExecutionData.

private ExecFileLoader loadExecutionData(final PrintWriter out) throws IOException {
    final ExecFileLoader loader = new ExecFileLoader();
    if (execfiles.isEmpty()) {
        out.println("[WARN] No execution data files provided.");
    } else {
        for (final File file : execfiles) {
            out.printf("[INFO] Loading execution data file %s.%n", file.getAbsolutePath());
            loader.load(file);
        }
    }
    return loader;
}
Also used : File(java.io.File) ExecFileLoader(org.jacoco.core.tools.ExecFileLoader)

Aggregations

ExecFileLoader (org.jacoco.core.tools.ExecFileLoader)14 IOException (java.io.IOException)4 InetAddress (java.net.InetAddress)3 BuildException (org.apache.tools.ant.BuildException)3 ExecDumpClient (org.jacoco.core.tools.ExecDumpClient)3 File (java.io.File)2 IBundleCoverage (org.jacoco.core.analysis.IBundleCoverage)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 HashSet (java.util.HashSet)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 Resource (org.apache.tools.ant.types.Resource)1 FileResource (org.apache.tools.ant.types.resources.FileResource)1 ExecutionData (org.jacoco.core.data.ExecutionData)1 Test (org.junit.Test)1