Reputation: 964
I am using Jacoco on a remote websphere server. I have it set up as a tcpsrver and I query the server to get the jacoco.exec
, using this file I can create reports for all my projects. What I want is a single report for all the projects. I have added each report to a list, but when I try to create a single report, I am only able to view the statistics for the last project.
Each project is in its own folder, each folder gets its own coveragereport
. I do it like this
File[] fList = directory.listFiles();
ReportGenerator rg = new ReportGenerator();
for(File file : fList)
{
if( file.getAbsolutePath().contains("BL") )
{
if( new File( file.getAbsolutePath() + "\\bin" ).isDirectory() )
{
rg = new ReportGenerator(file);
rg.setExecutionDataFile(directory);
rg.setClassesDirectory(file, "\\bin");
rg.setReportDirectory(directory);
rg.setTitle(file);
rg.create();
}
}
else
{
if( new File( file.getAbsolutePath() + "\\WebContent" ).isDirectory() )
{
rg = new ReportGenerator(file);
rg.setExecutionDataFile( directory );
rg.setClassesDirectory( file , "\\WebContent\\WEB-INF\\classes" );
rg.setReportDirectory(directory);
rg.setTitle(file);
rg.create();
}
}
Now I add them all to a list:
loadExecutionData();
final IBundleCoverage bundleCoverage = analyzeStructure();
reportsList.add(this);
at this point I want to call a method to generate the report, but it does not work. So far I am trying to use the examples provided on the jacoco website.
http://www.eclemma.org/jacoco/trunk/doc/examples/java/ReportGenerator.java
What I attempted to do was edit the createReport
method, I create an HTMLFormatter
and an IReportVisitor
, loop through the report list and add the visitInfo
and visitBundle
then at the very end, call a visitEnd()
which dumps the contents to a file. The problem is the problem is in setting visitInfo
and visitBundle
I overwrite the previous report.
I am hoping someone out there knows how to append reports to make one larger report for viewing.
Upvotes: 0
Views: 986
Reputation: 964
Luckily through reading and trial and error I found out how to programmatically create and merge jacoco code coverage reports.
The simple way is to create a list of bundle coverages, create a group and put it all together in a MultiReportVisitor
public void addToBundleCoverageList() throws IOException {
loadExecutionData();
bundleCoverage = analyzeStructure();
coverageList.add(bundleCoverage);
}
public void createCoverageList() throws IOException
{
for(int i=0; i<coverageList.size(); i++)
{
HTMLFormatter htmlFormatter = new HTMLFormatter();
IReportVisitor visitor = htmlFormatter
.createVisitor(new FileMultiReportOutput(reportDirectory));
visitor.visitInfo(execFileLoader.getSessionInfoStore().getInfos(),
execFileLoader.getExecutionDataStore().getContents());
visitors.add(visitor);
}
}
public void createReportFromList() throws IOException
{
MultiReportVisitor mrv = new MultiReportVisitor(visitors);
IReportGroupVisitor irgv = mrv.visitGroup("group");
for(int i=0; i<coverageList.size(); i++)
{
irgv.visitBundle(coverageList.get(i), indexHtml);
System.out.println("Processing: " + coverageList.get(i).getName());
}
mrv.visitEnd();
}
Upvotes: 1