Search in sources :

Example 6 with IBundleCoverage

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

the class ReportTask method createReport.

private void createReport(final IReportGroupVisitor visitor, final GroupElement group) throws IOException {
    if (group.name == null) {
        throw new BuildException("Group name must be supplied", getLocation());
    }
    if (group.children.isEmpty()) {
        final IBundleCoverage bundle = createBundle(group);
        final SourceFilesElement sourcefiles = group.sourcefiles;
        final AntResourcesLocator locator = new AntResourcesLocator(sourcefiles.encoding, sourcefiles.tabWidth);
        locator.addAll(sourcefiles.iterator());
        if (!locator.isEmpty()) {
            checkForMissingDebugInformation(bundle);
        }
        visitor.visitBundle(bundle, locator);
    } else {
        final IReportGroupVisitor groupVisitor = visitor.visitGroup(group.name);
        for (final GroupElement child : group.children) {
            createReport(groupVisitor, child);
        }
    }
}
Also used : IBundleCoverage(org.jacoco.core.analysis.IBundleCoverage) IReportGroupVisitor(org.jacoco.report.IReportGroupVisitor) BuildException(org.apache.tools.ant.BuildException)

Example 7 with IBundleCoverage

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

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

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

the class HTMLFormatter method createVisitor.

/**
 * Creates a new visitor to write a report to the given output.
 *
 * @param output
 *            output to write the report to
 * @return visitor to emit the report data to
 * @throws IOException
 *             in case of problems with the output stream
 */
public IReportVisitor createVisitor(final IMultiReportOutput output) throws IOException {
    final ReportOutputFolder root = new ReportOutputFolder(output);
    resources = new Resources(root);
    resources.copyResources();
    index = new ElementIndex(root);
    return new IReportVisitor() {

        private List<SessionInfo> sessionInfos;

        private Collection<ExecutionData> executionData;

        private HTMLGroupVisitor groupHandler;

        public void visitInfo(final List<SessionInfo> sessionInfos, final Collection<ExecutionData> executionData) throws IOException {
            this.sessionInfos = sessionInfos;
            this.executionData = executionData;
        }

        public void visitBundle(final IBundleCoverage bundle, final ISourceFileLocator locator) throws IOException {
            final BundlePage page = new BundlePage(bundle, null, locator, root, HTMLFormatter.this);
            createSessionsPage(page);
            page.render();
        }

        public IReportGroupVisitor visitGroup(final String name) throws IOException {
            groupHandler = new HTMLGroupVisitor(null, root, HTMLFormatter.this, name);
            createSessionsPage(groupHandler.getPage());
            return groupHandler;
        }

        private void createSessionsPage(final ReportPage rootpage) {
            sessionsPage = new SessionsPage(sessionInfos, executionData, index, rootpage, root, HTMLFormatter.this);
        }

        public void visitEnd() throws IOException {
            if (groupHandler != null) {
                groupHandler.visitEnd();
            }
            sessionsPage.render();
            output.close();
        }
    };
}
Also used : ReportOutputFolder(org.jacoco.report.internal.ReportOutputFolder) SessionsPage(org.jacoco.report.internal.html.page.SessionsPage) ISourceFileLocator(org.jacoco.report.ISourceFileLocator) ReportPage(org.jacoco.report.internal.html.page.ReportPage) IReportVisitor(org.jacoco.report.IReportVisitor) HTMLGroupVisitor(org.jacoco.report.internal.html.HTMLGroupVisitor) BundlePage(org.jacoco.report.internal.html.page.BundlePage) Collection(java.util.Collection) IBundleCoverage(org.jacoco.core.analysis.IBundleCoverage) List(java.util.List) Resources(org.jacoco.report.internal.html.resources.Resources) ElementIndex(org.jacoco.report.internal.html.index.ElementIndex)

Example 10 with IBundleCoverage

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

the class XMLFormatter method createVisitor.

/**
 * Creates a new visitor to write a report to the given stream.
 *
 * @param output
 *            output stream to write the report to
 * @return visitor to emit the report data to
 * @throws IOException
 *             in case of problems with the output stream
 */
public IReportVisitor createVisitor(final OutputStream output) throws IOException {
    final XMLElement root = new XMLDocument("report", PUBID, SYSTEM, outputEncoding, true, output);
    class RootVisitor extends XMLGroupVisitor implements IReportVisitor {

        RootVisitor(final XMLElement element) throws IOException {
            super(element, null);
        }

        private List<SessionInfo> sessionInfos;

        public void visitInfo(final List<SessionInfo> sessionInfos, final Collection<ExecutionData> executionData) throws IOException {
            this.sessionInfos = sessionInfos;
        }

        @Override
        protected void handleBundle(final IBundleCoverage bundle, final ISourceFileLocator locator) throws IOException {
            writeHeader(bundle.getName());
            XMLCoverageWriter.writeBundle(bundle, element);
        }

        @Override
        protected AbstractGroupVisitor handleGroup(final String name) throws IOException {
            writeHeader(name);
            return new XMLGroupVisitor(element, name);
        }

        private void writeHeader(final String name) throws IOException {
            element.attr("name", name);
            for (final SessionInfo i : sessionInfos) {
                final XMLElement sessioninfo = root.element("sessioninfo");
                sessioninfo.attr("id", i.getId());
                sessioninfo.attr("start", i.getStartTimeStamp());
                sessioninfo.attr("dump", i.getDumpTimeStamp());
            }
        }

        @Override
        protected void handleEnd() throws IOException {
            element.close();
        }
    }
    return new RootVisitor(root);
}
Also used : XMLGroupVisitor(org.jacoco.report.internal.xml.XMLGroupVisitor) Collection(java.util.Collection) IBundleCoverage(org.jacoco.core.analysis.IBundleCoverage) SessionInfo(org.jacoco.core.data.SessionInfo) List(java.util.List) XMLElement(org.jacoco.report.internal.xml.XMLElement) ISourceFileLocator(org.jacoco.report.ISourceFileLocator) XMLDocument(org.jacoco.report.internal.xml.XMLDocument) IReportVisitor(org.jacoco.report.IReportVisitor)

Aggregations

IBundleCoverage (org.jacoco.core.analysis.IBundleCoverage)10 Collection (java.util.Collection)3 List (java.util.List)3 IReportVisitor (org.jacoco.report.IReportVisitor)3 ISourceFileLocator (org.jacoco.report.ISourceFileLocator)3 Analyzer (org.jacoco.core.analysis.Analyzer)2 CoverageBuilder (org.jacoco.core.analysis.CoverageBuilder)2 ExecFileLoader (org.jacoco.core.tools.ExecFileLoader)2 File (java.io.File)1 FileWriter (java.io.FileWriter)1 InputStream (java.io.InputStream)1 PrintWriter (java.io.PrintWriter)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 BuildException (org.apache.tools.ant.BuildException)1 Resource (org.apache.tools.ant.types.Resource)1 FileResource (org.apache.tools.ant.types.resources.FileResource)1 IClassCoverage (org.jacoco.core.analysis.IClassCoverage)1 ICounter (org.jacoco.core.analysis.ICounter)1 IMethodCoverage (org.jacoco.core.analysis.IMethodCoverage)1