use of org.jacoco.core.analysis.IBundleCoverage in project jacoco by jacoco.
the class ReportTask method createReport.
private void createReport(final IReportGroupVisitor visitor, final GroupElement group) throws IOException {
if (group.name == null) {
throw new BuildException("Group name must be supplied", getLocation());
}
if (group.children.isEmpty()) {
final IBundleCoverage bundle = createBundle(group);
final SourceFilesElement sourcefiles = group.sourcefiles;
final AntResourcesLocator locator = new AntResourcesLocator(sourcefiles.encoding, sourcefiles.tabWidth);
locator.addAll(sourcefiles.iterator());
if (!locator.isEmpty()) {
checkForMissingDebugInformation(bundle);
}
visitor.visitBundle(bundle, locator);
} else {
final IReportGroupVisitor groupVisitor = visitor.visitGroup(group.name);
for (final GroupElement child : group.children) {
createReport(groupVisitor, child);
}
}
}
use of org.jacoco.core.analysis.IBundleCoverage in project jacoco by jacoco.
the class ReportTask method createBundle.
private IBundleCoverage createBundle(final GroupElement group) throws IOException {
final CoverageBuilder builder = new CoverageBuilder();
final Analyzer analyzer = new Analyzer(executionDataStore, builder);
for (final Iterator<?> i = group.classfiles.iterator(); i.hasNext(); ) {
final Resource resource = (Resource) i.next();
if (resource.isDirectory() && resource instanceof FileResource) {
analyzer.analyzeAll(((FileResource) resource).getFile());
} else {
final InputStream in = resource.getInputStream();
analyzer.analyzeAll(in, resource.getName());
in.close();
}
}
final IBundleCoverage bundle = builder.getBundle(group.name);
logBundleInfo(bundle, builder.getNoMatchClasses());
return bundle;
}
use of org.jacoco.core.analysis.IBundleCoverage in project jacoco by jacoco.
the class ReportSupport method processProject.
private void processProject(final IReportGroupVisitor visitor, final String bundeName, final MavenProject project, final List<String> includes, final List<String> excludes, final ISourceFileLocator locator) throws IOException {
final CoverageBuilder builder = new CoverageBuilder();
final File classesDir = new File(project.getBuild().getOutputDirectory());
if (classesDir.isDirectory()) {
final Analyzer analyzer = new Analyzer(loader.getExecutionDataStore(), builder);
final FileFilter filter = new FileFilter(includes, excludes);
for (final File file : filter.getFiles(classesDir)) {
analyzer.analyzeAll(file);
}
}
final IBundleCoverage bundle = builder.getBundle(bundeName);
logBundleInfo(bundle, builder.getNoMatchClasses());
visitor.visitBundle(bundle, locator);
}
use of org.jacoco.core.analysis.IBundleCoverage 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.core.analysis.IBundleCoverage 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