Home | Forums

Sharing Report Formats

You can share report formats across a number of reports. This allows you to standardise on a set of report formats and use these for all your reports.

Standalone format elements are created using the <clover-format> type. Standalone formats elements are not compatible with Ant 1.4.1. You require at least Ant 1.5.1 to use this feature. These standalone types support the same attributes and elements as the internal <format> elements of the <clover-report> task. You name the format using the standard ant "id" attribute.

In order to make the standalone format element available for use in your project, you need to add a typedef first:

<typedef resource="clovertypes"/>

The following code declares two report formats

<clover-format id="std.format" srclevel="true" type="pdf"/>
<clover-format id="bw.format" bw="true" srclevel="true" type="pdf"/>

In this example, the first format is for source level, PDF reports. It is named "std.format". The second format, "bw.format", is essentially the same except it specifies black and white output.

Once the format is declared with an identifier, it can be used by reference with a "refid" attribute. This is shown in the following report example

<clover-report>
  <current summary="yes"  outfile="report-current.pdf"
           title="Ant Coverage">
    <format refid="std.format"/>
  </current>
</clover-report>

This report, a summary report, uses the "std.format" format defined above. The refid values in the <format> elements can be an Ant property allowing selection of the report format at build time. The following is a complete example

<target name="report">
 <clover-format id="std.format" srclevel="true" type="pdf"/>
 <clover-format id="bw.format" bw="true" srclevel="true" type="pdf"/>
 <property name="format" value="std.format"/>
 <clover-report>
   <current summary="yes"  outfile="report-current.pdf"
            title="Ant Coverage">
     <format refid="${format}"/>
   </current>
   <historical historydir="clover-hist" outfile="report-history.pdf"
               title="Ant Historical Coverage">
     <format refid="${format}"/>
   </historical>
 </clover-report>
</target>

Here, we are generating two reports, which share a format. The format defaults to the standard format, a colour report. This default can be overriden from the command line. To generate black and white reports you would use:

ant report -Dformat=bw.format