Search in sources :

Example 1 with Analyzer

use of org.jacoco.core.analysis.Analyzer in project buck by facebook.

the class ReportGenerator method analyzeStructure.

private IBundleCoverage analyzeStructure() throws IOException {
    final CoverageBuilder coverageBuilder = new CoverageBuilder();
    final Analyzer analyzer = new Analyzer(execFileLoader.getExecutionDataStore(), coverageBuilder);
    String[] classesDirs = classesPath.split(":");
    for (String classesDir : classesDirs) {
        File classesDirFile = new File(classesDir);
        if (classesDirFile.exists()) {
            for (File clazz : FileUtils.getFiles(classesDirFile, coverageIncludes, coverageExcludes)) {
                analyzer.analyzeAll(clazz);
            }
        }
    }
    return coverageBuilder.getBundle(title);
}
Also used : CoverageBuilder(org.jacoco.core.analysis.CoverageBuilder) Analyzer(org.jacoco.core.analysis.Analyzer) File(java.io.File)

Example 2 with Analyzer

use of org.jacoco.core.analysis.Analyzer in project sonar-java by SonarSource.

the class JacocoReportReader method analyzeFiles.

/**
 * Caller must guarantee that {@code classFiles} are actually class file.
 */
public CoverageBuilder analyzeFiles(ExecutionDataStore executionDataStore, Collection<File> classFiles) {
    CoverageBuilder coverageBuilder = new CoverageBuilder();
    if (useCurrentBinaryFormat) {
        Analyzer analyzer = new Analyzer(executionDataStore, coverageBuilder);
        for (File classFile : classFiles) {
            analyzeClassFile(analyzer, classFile);
        }
    } else {
        org.jacoco.previous.core.analysis.Analyzer analyzer = new org.jacoco.previous.core.analysis.Analyzer(executionDataStore, coverageBuilder);
        for (File classFile : classFiles) {
            analyzeClassFile(analyzer, classFile);
        }
    }
    logNoMatchClasses(coverageBuilder.getNoMatchClasses());
    return coverageBuilder;
}
Also used : CoverageBuilder(org.jacoco.core.analysis.CoverageBuilder) Analyzer(org.jacoco.core.analysis.Analyzer) File(java.io.File)

Example 3 with Analyzer

use of org.jacoco.core.analysis.Analyzer in project dspot by STAMP-project.

the class JacocoListener method coverageResults.

private CoverageResults coverageResults(ExecutionDataStore executionData) {
    final CoverageBuilder coverageBuilder = new CoverageBuilder();
    final Analyzer analyzer = new Analyzer(executionData, coverageBuilder);
    try {
        analyzer.analyzeAll(new File(classesDirectory));
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return new CoverageResults(coverageBuilder);
}
Also used : CoverageBuilder(org.jacoco.core.analysis.CoverageBuilder) IOException(java.io.IOException) Analyzer(org.jacoco.core.analysis.Analyzer) File(java.io.File)

Example 4 with Analyzer

use of org.jacoco.core.analysis.Analyzer in project jacoco by jacoco.

the class ReportGenerator method analyzeStructure.

private IBundleCoverage analyzeStructure() throws IOException {
    final CoverageBuilder coverageBuilder = new CoverageBuilder();
    final Analyzer analyzer = new Analyzer(execFileLoader.getExecutionDataStore(), coverageBuilder);
    analyzer.analyzeAll(classesDirectory);
    return coverageBuilder.getBundle(title);
}
Also used : CoverageBuilder(org.jacoco.core.analysis.CoverageBuilder) Analyzer(org.jacoco.core.analysis.Analyzer)

Example 5 with Analyzer

use of org.jacoco.core.analysis.Analyzer in project jacoco by jacoco.

the class CoreTutorial method execute.

/**
 * Run this example.
 *
 * @throws Exception
 *             in case of errors
 */
public void execute() throws Exception {
    final String targetName = TestTarget.class.getName();
    // For instrumentation and runtime we need a IRuntime instance
    // to collect execution data:
    final IRuntime runtime = new LoggerRuntime();
    // The Instrumenter creates a modified version of our test target class
    // that contains additional probes for execution data recording:
    final Instrumenter instr = new Instrumenter(runtime);
    InputStream original = getTargetClass(targetName);
    final byte[] instrumented = instr.instrument(original, targetName);
    original.close();
    // Now we're ready to run our instrumented class and need to startup the
    // runtime first:
    final RuntimeData data = new RuntimeData();
    runtime.startup(data);
    // In this tutorial we use a special class loader to directly load the
    // instrumented class definition from a byte[] instances.
    final MemoryClassLoader memoryClassLoader = new MemoryClassLoader();
    memoryClassLoader.addDefinition(targetName, instrumented);
    final Class<?> targetClass = memoryClassLoader.loadClass(targetName);
    // Here we execute our test target class through its Runnable interface:
    final Runnable targetInstance = (Runnable) targetClass.newInstance();
    targetInstance.run();
    // At the end of test execution we collect execution data and shutdown
    // the runtime:
    final ExecutionDataStore executionData = new ExecutionDataStore();
    final SessionInfoStore sessionInfos = new SessionInfoStore();
    data.collect(executionData, sessionInfos, false);
    runtime.shutdown();
    // Together with the original class definition we can calculate coverage
    // information:
    final CoverageBuilder coverageBuilder = new CoverageBuilder();
    final Analyzer analyzer = new Analyzer(executionData, coverageBuilder);
    original = getTargetClass(targetName);
    analyzer.analyzeClass(original, targetName);
    original.close();
    // Let's dump some metrics and line coverage information:
    for (final IClassCoverage cc : coverageBuilder.getClasses()) {
        out.printf("Coverage of class %s%n", cc.getName());
        printCounter("instructions", cc.getInstructionCounter());
        printCounter("branches", cc.getBranchCounter());
        printCounter("lines", cc.getLineCounter());
        printCounter("methods", cc.getMethodCounter());
        printCounter("complexity", cc.getComplexityCounter());
        for (int i = cc.getFirstLine(); i <= cc.getLastLine(); i++) {
            out.printf("Line %s: %s%n", Integer.valueOf(i), getColor(cc.getLine(i).getStatus()));
        }
    }
}
Also used : RuntimeData(org.jacoco.core.runtime.RuntimeData) LoggerRuntime(org.jacoco.core.runtime.LoggerRuntime) InputStream(java.io.InputStream) CoverageBuilder(org.jacoco.core.analysis.CoverageBuilder) Analyzer(org.jacoco.core.analysis.Analyzer) IRuntime(org.jacoco.core.runtime.IRuntime) ExecutionDataStore(org.jacoco.core.data.ExecutionDataStore) IClassCoverage(org.jacoco.core.analysis.IClassCoverage) Instrumenter(org.jacoco.core.instr.Instrumenter) SessionInfoStore(org.jacoco.core.data.SessionInfoStore)

Aggregations

Analyzer (org.jacoco.core.analysis.Analyzer)15 CoverageBuilder (org.jacoco.core.analysis.CoverageBuilder)14 File (java.io.File)7 IClassCoverage (org.jacoco.core.analysis.IClassCoverage)4 ExecutionDataStore (org.jacoco.core.data.ExecutionDataStore)4 SessionInfoStore (org.jacoco.core.data.SessionInfoStore)3 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 IBundleCoverage (org.jacoco.core.analysis.IBundleCoverage)2 IMethodCoverage (org.jacoco.core.analysis.IMethodCoverage)2 Callable (java.util.concurrent.Callable)1 Resource (org.apache.tools.ant.types.Resource)1 FileResource (org.apache.tools.ant.types.resources.FileResource)1 ICoverageVisitor (org.jacoco.core.analysis.ICoverageVisitor)1 ExecutionData (org.jacoco.core.data.ExecutionData)1 Instrumenter (org.jacoco.core.instr.Instrumenter)1 IRuntime (org.jacoco.core.runtime.IRuntime)1 LoggerRuntime (org.jacoco.core.runtime.LoggerRuntime)1 RuntimeData (org.jacoco.core.runtime.RuntimeData)1