Search in sources :

Example 11 with ReportOutputFolder

use of org.jacoco.report.internal.ReportOutputFolder 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)

Aggregations

ReportOutputFolder (org.jacoco.report.internal.ReportOutputFolder)11 MemoryMultiReportOutput (org.jacoco.report.MemoryMultiReportOutput)7 Resources (org.jacoco.report.internal.html.resources.Resources)7 Before (org.junit.Before)7 HTMLDocument (org.jacoco.report.internal.html.HTMLDocument)5 HTMLSupport (org.jacoco.report.internal.html.HTMLSupport)5 ISourceFileLocator (org.jacoco.report.ISourceFileLocator)2 ILinkable (org.jacoco.report.internal.html.ILinkable)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 Reader (java.io.Reader)1 StringReader (java.io.StringReader)1 Collection (java.util.Collection)1 List (java.util.List)1 Locale (java.util.Locale)1 IBundleCoverage (org.jacoco.core.analysis.IBundleCoverage)1 IClassCoverage (org.jacoco.core.analysis.IClassCoverage)1 ISourceFileCoverage (org.jacoco.core.analysis.ISourceFileCoverage)1 PackageCoverageImpl (org.jacoco.core.internal.analysis.PackageCoverageImpl)1 SourceFileCoverageImpl (org.jacoco.core.internal.analysis.SourceFileCoverageImpl)1