Search in sources :

Example 11 with Analyzer

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

the class ReportTask method createBundle.

private IBundleCoverage createBundle(final GroupElement group) throws IOException {
    final CoverageBuilder builder = new CoverageBuilder();
    final Analyzer analyzer = new Analyzer(executionDataStore, builder);
    for (final Iterator<?> i = group.classfiles.iterator(); i.hasNext(); ) {
        final Resource resource = (Resource) i.next();
        if (resource.isDirectory() && resource instanceof FileResource) {
            analyzer.analyzeAll(((FileResource) resource).getFile());
        } else {
            final InputStream in = resource.getInputStream();
            analyzer.analyzeAll(in, resource.getName());
            in.close();
        }
    }
    final IBundleCoverage bundle = builder.getBundle(group.name);
    logBundleInfo(bundle, builder.getNoMatchClasses());
    return bundle;
}
Also used : InputStream(java.io.InputStream) FileResource(org.apache.tools.ant.types.resources.FileResource) Resource(org.apache.tools.ant.types.Resource) FileResource(org.apache.tools.ant.types.resources.FileResource) IBundleCoverage(org.jacoco.core.analysis.IBundleCoverage) CoverageBuilder(org.jacoco.core.analysis.CoverageBuilder) Analyzer(org.jacoco.core.analysis.Analyzer)

Example 12 with Analyzer

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

the class CyclomaticComplexityTest method analyze.

private ICounter analyze() throws IOException {
    final CoverageBuilder builder = new CoverageBuilder();
    final ExecutionDataStore store = new ExecutionDataStore();
    data.collect(store, new SessionInfoStore(), false);
    final Analyzer analyzer = new Analyzer(store, builder);
    analyzer.analyzeClass(bytes, "TestTarget");
    final Collection<IClassCoverage> classes = builder.getClasses();
    assertEquals(1, classes.size(), 0.0);
    final IClassCoverage classCoverage = classes.iterator().next();
    for (final IMethodCoverage m : classCoverage.getMethods()) {
        if (m.getName().equals("test")) {
            return m.getComplexityCounter();
        }
    }
    throw new AssertionError("No test() method.");
}
Also used : IMethodCoverage(org.jacoco.core.analysis.IMethodCoverage) ExecutionDataStore(org.jacoco.core.data.ExecutionDataStore) IClassCoverage(org.jacoco.core.analysis.IClassCoverage) CoverageBuilder(org.jacoco.core.analysis.CoverageBuilder) Analyzer(org.jacoco.core.analysis.Analyzer) SessionInfoStore(org.jacoco.core.data.SessionInfoStore)

Example 13 with Analyzer

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

the class ReportSupport method processProject.

private void processProject(final IReportGroupVisitor visitor, final String bundeName, final MavenProject project, final List<String> includes, final List<String> excludes, final ISourceFileLocator locator) throws IOException {
    final CoverageBuilder builder = new CoverageBuilder();
    final File classesDir = new File(project.getBuild().getOutputDirectory());
    if (classesDir.isDirectory()) {
        final Analyzer analyzer = new Analyzer(loader.getExecutionDataStore(), builder);
        final FileFilter filter = new FileFilter(includes, excludes);
        for (final File file : filter.getFiles(classesDir)) {
            analyzer.analyzeAll(file);
        }
    }
    final IBundleCoverage bundle = builder.getBundle(bundeName);
    logBundleInfo(bundle, builder.getNoMatchClasses());
    visitor.visitBundle(bundle, locator);
}
Also used : IBundleCoverage(org.jacoco.core.analysis.IBundleCoverage) CoverageBuilder(org.jacoco.core.analysis.CoverageBuilder) Analyzer(org.jacoco.core.analysis.Analyzer) File(java.io.File)

Example 14 with Analyzer

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

the class JacocoExecutor method coverageResults.

private CoverageResults coverageResults(ExecutionDataStore executionData) {
    final String classesDirectory = this.program.getProgramDir() + "/" + this.program.getClassesDir();
    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)

Aggregations

Analyzer (org.jacoco.core.analysis.Analyzer)14 CoverageBuilder (org.jacoco.core.analysis.CoverageBuilder)13 File (java.io.File)7 IClassCoverage (org.jacoco.core.analysis.IClassCoverage)3 ExecutionDataStore (org.jacoco.core.data.ExecutionDataStore)3 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 IBundleCoverage (org.jacoco.core.analysis.IBundleCoverage)2 SessionInfoStore (org.jacoco.core.data.SessionInfoStore)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 IMethodCoverage (org.jacoco.core.analysis.IMethodCoverage)1 ISourceFileCoverage (org.jacoco.core.analysis.ISourceFileCoverage)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