Search in sources :

Example 1 with ReportElement

use of org.jacoco.report.internal.xml.ReportElement 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 {
    class RootVisitor implements IReportVisitor {

        private ReportElement report;

        private List<SessionInfo> sessionInfos;

        private XMLGroupVisitor groupVisitor;

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

        public void visitBundle(final IBundleCoverage bundle, final ISourceFileLocator locator) throws IOException {
            createRootElement(bundle.getName());
            XMLCoverageWriter.writeBundle(bundle, report);
        }

        public IReportGroupVisitor visitGroup(final String name) throws IOException {
            createRootElement(name);
            groupVisitor = new XMLGroupVisitor(report, name);
            return groupVisitor;
        }

        private void createRootElement(final String name) throws IOException {
            report = new ReportElement(name, output, outputEncoding);
            for (final SessionInfo i : sessionInfos) {
                report.sessioninfo(i);
            }
        }

        public void visitEnd() throws IOException {
            if (groupVisitor != null) {
                groupVisitor.visitEnd();
            }
            report.close();
        }
    }
    return new RootVisitor();
}
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) ReportElement(org.jacoco.report.internal.xml.ReportElement) List(java.util.List) ISourceFileLocator(org.jacoco.report.ISourceFileLocator) IReportVisitor(org.jacoco.report.IReportVisitor)

Aggregations

Collection (java.util.Collection)1 List (java.util.List)1 IBundleCoverage (org.jacoco.core.analysis.IBundleCoverage)1 SessionInfo (org.jacoco.core.data.SessionInfo)1 IReportVisitor (org.jacoco.report.IReportVisitor)1 ISourceFileLocator (org.jacoco.report.ISourceFileLocator)1 ReportElement (org.jacoco.report.internal.xml.ReportElement)1 XMLGroupVisitor (org.jacoco.report.internal.xml.XMLGroupVisitor)1