Why JSON?
The JSON format is supported as an output type in Clover specifically to create integration opportunities with other applications. The JSON data from Clover is easy to manipulate programmatically, allowing innovative developers to use it for displaying or processing their coverage data in novel ways.
Clover-Ant code for JSON output
<target name="report.json" depends="with.clover">
<clover-report>
<current outfile="clover_json">
<format type="json"/>
<columns>
<lineCount/>
<ncLineCount/>
</columns>
</current>
</clover-report>
</target>
Examples of JSON report usage
JSON for a file page:
processClover ( {
"lines": ["", "", "10", "10", "10", "", "", "16", "1", "1", "1", "", "", "", "", "22", "22", "5678", "5678", "1", "1"],
"stats": {
"Complexity": 22,
"TotalPercentageCovered": 100,
"CoveredElements": 63,
"UncoveredElements": 0
},
"id": "org_apache_commons_codec_net_BCodec_java"
}
);
The "lines" array contains the hit counts for each line in the BCodec.java file.
JSON in an HTML page:
<!-- Define the callback function before including the java.js for the file you wish to process. -->
<script type="text/javascript">
function processClover(obj) {
alert(obj.id);
alert(obj.stats.CoveredElements);
alert(obj.stats.Complexity);
alert(obj.lines);
}
</script>
<!-- Now, include as many java.js files as you wish. Each will call your "processClover" callback function above. -->
<script type="text/javascript"
src="http://downloads.atlassian.com/software/clover/samples/codec/org/apache/commons/codec/StringEncoderAbstractTest.java.js">
</script>
<script type="text/javascript"
src="http://downloads.atlassian.com/software/clover/samples/codec/org/apache/commons/codec/net/BCode.java.js">
</script>
JSON live demo
This example uses JavaScript alerts to display the JSON data. Click here to run the live demo.