Search in sources :

Example 11 with CoverageBuilder

use of org.jacoco.core.analysis.CoverageBuilder in project powermock by powermock.

the class JacocoCoverageTest method collectCoverage.

private CoverageBuilder collectCoverage(ExecutionDataStore executionData) throws IOException {
    final CoverageBuilder coverageBuilder = new CoverageBuilder();
    final Analyzer analyzer = new Analyzer(executionData, coverageBuilder);
    for (String className : TARGET) {
        analyzer.analyzeClass(getClass().getResourceAsStream(classNameToFileName(className)), className);
    }
    return coverageBuilder;
}
Also used : CoverageBuilder(org.jacoco.core.analysis.CoverageBuilder) Analyzer(org.jacoco.core.analysis.Analyzer)

Example 12 with CoverageBuilder

use of org.jacoco.core.analysis.CoverageBuilder in project powermock by powermock.

the class JacocoCoverageTest method jacocoOfflineInstShouldCalculateCoverageAfterPowerMockTransformation.

@Test
public void jacocoOfflineInstShouldCalculateCoverageAfterPowerMockTransformation() throws Exception {
    final RuntimeData data = new RuntimeData();
    runTargetTest(data);
    final CoverageBuilder coverageBuilder = collectCoverage(getExecutionDataStore(data));
    assertCodeCoverage(coverageBuilder);
}
Also used : RuntimeData(org.jacoco.core.runtime.RuntimeData) CoverageBuilder(org.jacoco.core.analysis.CoverageBuilder) Test(org.junit.Test)

Example 13 with CoverageBuilder

use of org.jacoco.core.analysis.CoverageBuilder 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 14 with CoverageBuilder

use of org.jacoco.core.analysis.CoverageBuilder 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 15 with CoverageBuilder

use of org.jacoco.core.analysis.CoverageBuilder 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)

Aggregations

CoverageBuilder (org.jacoco.core.analysis.CoverageBuilder)16 Analyzer (org.jacoco.core.analysis.Analyzer)13 File (java.io.File)8 ISourceFileCoverage (org.jacoco.core.analysis.ISourceFileCoverage)3 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 IBundleCoverage (org.jacoco.core.analysis.IBundleCoverage)2 IClassCoverage (org.jacoco.core.analysis.IClassCoverage)2 ExecutionDataStore (org.jacoco.core.data.ExecutionDataStore)2 SessionInfoStore (org.jacoco.core.data.SessionInfoStore)2 RuntimeData (org.jacoco.core.runtime.RuntimeData)2 InputFile (org.sonar.api.batch.fs.InputFile)2 Resource (org.apache.tools.ant.types.Resource)1 FileResource (org.apache.tools.ant.types.resources.FileResource)1 IMethodCoverage (org.jacoco.core.analysis.IMethodCoverage)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 Test (org.junit.Test)1