CodeCover

Create a new report generator

Creating a new plugin

First of all, you will want wo create a plugin for your new report generator so you have it separeted from the core of CodeCover. To do so, create a new java project and in it a child class of org.codecover.model.extensions.AbstractPlugin which implements a new constructor without any parameters. This constructor calls one of the two super constructors


AbstractPlugin(String name
               String description, 
               Set<Extension<?>> extensions)

or


AbstractPlugin(String name,
               String description,
               Extension<?>[] extensions)

where name is the name of the plugin, description is its description and extensions are Extensions this plugin provides.

Such an extension could be child of org.codecover.model.extensions.AbstractExtension<ReportGenerator>.

Example:


package org.codecover.report.velocity;

import org.codecover.report.Report;
import org.codecover.report.ReportGenerator;
import org.codecover.report.exceptions.ReportException;
import org.codecover.report.exceptions.ReportIOException;

public class VelocityReportPlugin extends AbstractPlugin {

    public VelocityReportPlugin() {
        super("Velocity Report",
              "This plugin contains a velocity generator",
              new Extension<?>[] {new AbstractExtension<ReportGenerator>(
                      ReportGenerator.class,
                      "org.codecover.report.velocity.VelocityReportGenerator")
                          {
                              public ReportGenerator getObject() {
                                  return new VelocityReportGenerator();
                              }
                          }
               });
        }
}

where org.codecover.report.velocity.VelocityReportGenerator implements ReportGenerator (see below).

The last thing you need is a codecover-plugin.xml file. The one for our example would be


<plugin xmlns="http://www.codecover.org/xml/plugin-descriptor-1.0"
        name="org.codecover.report.velocity"
        version="0.1"
        class="org.codecover.report.velocity.VelocityReportPlugin">
  <depends name="org.codecover" version="0.1" />
</plugin>

where you, of course, have to change the name of the package and class to the ones you have chosen. The XML-file must in on the topmost folder of the project. When you are ready, save the project as a jar and store it in the plugin-folder of CodeCover, specified via batch interface or in the CodeCover preferences in Eclipse.

ReportGenerator

As mentioned above, your report generator has to implement the interface ReportGenerator which requires the two methods

String getContentType()

void generateReport(Report report) throws ReportException, ReportIOException

where getContentType returns a MIME content-type, e.g. "text/html", and gerenerateReport does the work. Each report is created with a template file (see "Adapt the report format"). This template file names the ReportGenerator (in the example above, it would be org.codecover.report.velocity.VelocityReportGenerator) that should do the work. A Report is created, filled with the data from the template and the options the user set by commanding to generate a report. Not all of these data has to be set, so first of all it's recommended to check if the members of report you need are set. Then you can use these information (which can be - via the template - whatever you want) to create the report. The implementation of generateReport depends on the kind of report you want to create. Report gives you access to all data you may need; see the JavaDoc or the code of org.codecover.report.Report or its shipped implementations for details.