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();
}
Aggregations