use of org.jacoco.report.IReportVisitor in project jacoco by jacoco.
the class CheckMojo method executeCheck.
private void executeCheck() throws MojoExecutionException {
violations = false;
final ReportSupport support = new ReportSupport(getLog());
final List<Rule> checkerrules = new ArrayList<Rule>();
for (final RuleConfiguration r : rules) {
checkerrules.add(r.rule);
}
support.addRulesChecker(checkerrules, this);
try {
final IReportVisitor visitor = support.initRootVisitor();
support.loadExecutionData(dataFile);
support.processProject(visitor, getProject(), this.getIncludes(), this.getExcludes());
visitor.visitEnd();
} catch (final IOException e) {
throw new MojoExecutionException("Error while checking code coverage: " + e.getMessage(), e);
}
if (violations) {
if (this.haltOnFailure) {
throw new MojoExecutionException(CHECK_FAILED);
} else {
this.getLog().warn(CHECK_FAILED);
}
} else {
this.getLog().info(CHECK_SUCCESS);
}
}
use of org.jacoco.report.IReportVisitor in project jacoco by jacoco.
the class CSVFormatter 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 DelimitedWriter writer = new DelimitedWriter(new OutputStreamWriter(output, outputEncoding));
final ClassRowWriter rowWriter = new ClassRowWriter(writer, languageNames);
class Visitor extends CSVGroupHandler implements IReportVisitor {
Visitor() {
super(rowWriter);
}
public void visitInfo(final List<SessionInfo> sessionInfos, final Collection<ExecutionData> executionData) throws IOException {
// Info not used for CSV report
}
public void visitEnd() throws IOException {
writer.close();
}
}
return new Visitor();
}
use of org.jacoco.report.IReportVisitor 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();
}
};
}
use of org.jacoco.report.IReportVisitor 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);
}
Aggregations