Search in sources :

Example 6 with ISourceFileLocator

use of org.jacoco.report.ISourceFileLocator 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

ISourceFileLocator (org.jacoco.report.ISourceFileLocator)6 IReportVisitor (org.jacoco.report.IReportVisitor)4 IOException (java.io.IOException)3 Reader (java.io.Reader)3 Collection (java.util.Collection)3 List (java.util.List)3 IBundleCoverage (org.jacoco.core.analysis.IBundleCoverage)3 IClassCoverage (org.jacoco.core.analysis.IClassCoverage)2 ISourceFileCoverage (org.jacoco.core.analysis.ISourceFileCoverage)2 ReportOutputFolder (org.jacoco.report.internal.ReportOutputFolder)2 Before (org.junit.Before)2 FileWriter (java.io.FileWriter)1 PrintWriter (java.io.PrintWriter)1 StringReader (java.io.StringReader)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 ICounter (org.jacoco.core.analysis.ICounter)1 IMethodCoverage (org.jacoco.core.analysis.IMethodCoverage)1 IPackageCoverage (org.jacoco.core.analysis.IPackageCoverage)1 SessionInfo (org.jacoco.core.data.SessionInfo)1