Adapt the report format
In this section, you learn how to make CodeCover write the reports the way you like them.
To generate a report, CodeCover uses two components:
- A Java class derived from
org.codecover.report.ReportGenerator
, and - a template file selecting this
ReportGenerator
and providing all the information it needs.
ReportGenerator
The ReportGenerator
prepares all data and combines it with the (chiefly layout-) information of the template. In general you could say: whenever you need a new file format for the reports, you have to write a new ReportGenerator
(which shouldn't happen that often.)
Template
The template is the part easier to change, responsible mainly for the layout of the report. The shipped templates can be found in the eclipse/plugins/org.codecover.report.*/report-templates/
directorys (if you've installed CodeCover using Eclipse's update mechanism; otherwise, you may already have found them). Each template file has to use the following structure:
<?xml version="1.0" encoding="UTF-8"?>
<report version="1.0" xmlns="http://www.codecover.org/xml/report-template">
<class> classname of the ReportGenerator </class>
<name xml:lang="en"> name, can be repeated for different languages </name>
<description xml:lang="en"> description, can be repeated, too </description>
<template version="1"
xmlns="http://www.codecover.org/xml/report-template/html-hierarchic">
information for the ReportGenerator
</template>
</report>
Which information is needed and possible between the <template>
tags depends on the ReportGenerator
chosen in the template.
CodeCover is shipped with a CSV (comma seperated values) ReportGenerator
using a simple syntax (see below) and two HTML ReportGenerator
s using Apache Velocity to give you a huge flexibility how the reports should look like. Velocity-Statements starting with # control the generated output using (data)objects starting with $. These concepts are explained in the Velocity User Guide which you should read before you continue with this document. Afterwards, see the Velocity Context Reference for an survey of the objects you can access from the template.
SingleFileHTMLReportGenerator
With this template, you create, as the name tells, a report in one single HTML-file. Directly within the <template>
tag, surroundes by
<![CDATA[
html and Velocity code
]]>
is the HTML-Code for this page and are the velocity commands which are executed while the output is, line for line, written.
HierarchicalHTMLReportGenerator
This file is more difficult to understand, as more files (even of different types) are and may be created. The <template>
tags contain the following parts:
Required sections
<title-page><![CDATA[
html and Velocity code
]]></title-page>
This file is created in the path and with the filename the user selects while creating a report. It should give a survey of the report and link to the other files. These other files are created in subfolders according to the name of their corresponding HierarchyLevel
.
The other tags create files in a subdirectory. If the index file's name is INDEXFILE, the files are stored in the directory INDEXFILE-files
.
<selection-page><![CDATA[
html and Velocity code
]]></selection-page>
For each HierarchyLevel
that is neither the topmost (this uses title-page) nor a method (this uses code-page), a selection-page with the name "index.html" is created in a folder with the name of the HierarchyLevel
which lies in the folder of the levels parent. A selection-page should link to all its children.
<code-page><![CDATA[
html and Velocity code
]]></code-page>
For each method a code-page is created. Again, it is stored in a file with the name "index.html" in a subfolder with same name as the method. It could, as the name tells, contain code (but the other files could, of course, contain code, too. It depends on the data you access via the objects in the Velocity Context).
Optional sections
To use a language other than English (if available), you can use:
<language>
two letter abbreviation for language
</language>
Use
<text-file filename="NAME" content-type="MIMETYPE"><![CDATA[
plain text and Velocity code
]]></text-file>
to create text-files with the name NAME in the INDEXFILE-files directory.
Use
<binary-file filename="NAME" content-type="MIMETYPE"><![CDATA[
base64 encoded data
]]></binary-file>
to create binary-files with the name NAME in that directory.
CSVReport Template
A template file for the CSV export look that way:
<?xml version="1.0" encoding="UTF-8"?>
<report version="1.0" xmlns="http://www.codecover.org/xml/report-template">
<plugin>org.codecover.report.csv</plugin>
<generator>org.codecover.report.csv.CSVReportGenerator</generator>
<name xml:lang="en">CSV Report</name>
<description xml:lang="en">
Generates a report with comma separated values.
</description>
<template version="1"
xmlns="http://www.codecover.org/xml/report-template/csv">
tags defining the csv table
</template>
</report>
Between the template-tags, there are two different kinds of tags allowed, each as often as you wish:
<column>
STRING</column>
or<column header="HEADER">
STRING</column>
for each column the output should have, where HEADER is the value in the first line of the csv file (or an empty cell, if HEADER is not set) and STRING is the content of each cell in this column<columnsPerMetric>
several columns(see 1.)</columnsPerMetric>
for columns that shall be created for each available coverage metric.
HEADER and STRING can contain placeholders that are replaced by the values you want to report. These placehlders can't occur everywhere:
In HEADERs of columns that are part of a columnsPerMetric
area, you can use %1$s
which will be replaced by the name of the metric.
Each STRING can contain %2$s
which will be replaced by the name of the HierarchyLevel this line belongs to.
Only STRINGS of columns that are part of a columnsPerMetric
area can contain:
%1$s
= the name of the metric%2$s
= the name of the HierarchyLevel%3$d
= the number of covered items this metric counts for this HierarchyLevel%4$d
= the number of uncovered items this metric counts for this HierarchyLevel%5$d
= the total number of coverable items of this HierarchyLevel for this metric (=%3$d
+%4$d
)%6$f
= the quotient of covered and total items =%3$d
/%5$d
%7$f
= the 100 *%6$f
which is the coverage in percent as you are used to read it