The sensor for the Clover coverage tool is implemented using the XmlData sensor, and sends Coverage data (documented in Section 25.8, “Coverage”) to the Hackystat server.
The Clover sensor requires Java 1.5.0 or later and the XmlData sensor.
Follow the instructions in Chapter 2, Client-side configuration: Tool sensor installation to set your Hackystat host and user key.
Follow the instructions for installation of either the Ant or command-line interfaces to the XmlData sensor in Section 26.34, “XmlData”.
To begin, invoke Clover with its XML output enabled. Example 26.16, “An Ant task for generating Clover coverage data in XML format” illustrates an Ant file that runs JUnit over a sample system with Clover (and its XML output) enabled. Of course, there are many different ways to invoke Clover, what matters is that you generate the coverage XML file.
Example 26.16. An Ant task for generating Clover coverage data in XML format
<taskdef resource="clovertasks"/>
<clover-setup initString="mycoverage.db"/>
<target name="clover" depends="clean, compile"
description="Cleans, compiles, instruments byte codes, runs unit tests, generates clover report.">
<mkdir dir="${clover.dir}" />
<mkdir dir="${junit.dir}" />
<junit printsummary="withOutAndErr" fork="yes">
<classpath path="${build.dir}/classes;${java.class.path}">
<pathelement location="${ant.home}/lib/clover.jar" />
<path refid="compile.classpath"/>
</classpath>
<formatter type="xml" />
<batchtest todir="${junit.dir}">
<fileset dir="${src.dir}">
<include name="**/Test*.java" />
</fileset>
</batchtest>
</junit>
<clover-report>
<current outfile="${clover.dir}/coverage.xml">
<format type="xml"/>
</current>
</clover-report>
</target>
The next step is to convert the XML data generated by Clover into a format acceptable to the XmlData sensor. The easiest way is to use XSLT. Example 26.17, “The CloverToHackystat.xsl file” shows the contents of a file called CloverToHackystat.xsl, which extracts the statement-level coverage from the Clover coverage report and puts it into a form appropriate for the XmlData sensor.
Example 26.17. The CloverToHackystat.xsl file
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<xmldata>
<xsl:apply-templates select="coverage/project/package/file"/>
</xmldata>
</xsl:template>
<xsl:template match="file">
<xsl:variable name="uncovered" select="class/metrics/@statements - class/metrics/@coveredstatements" />
<entry sdt="Coverage" tool="Clover" granularity="statement" fileName="{@name}" covered="{class/metrics/@coveredstatements}" uncovered="{$uncovered}"/>
</xsl:template>
</xsl:stylesheet>
You can use this code unchanged, or modify it to extract other kinds of coverage data.
Example 26.18, “The clover.xslt ant task” shows a simple Ant task that uses the CloverToHackystat.xsl file listed above to generate a file called hackystat.xml, containing the coverage data in a form suitable for input to the XmlData sensor.
Example 26.18. The clover.xslt ant task
<target name="clover.xslt"
description="Transforms the XML file produced by Clover into the hackystat.xml file.">
<xslt style="CloverToHackystat.xsl"
in="${clover.dir}/coverage.xml" out="${clover.dir}/hackystat.xml" />
</target>
Example 26.19, “The hackystat.xml file produced by the CloverToHackystat.xsl transform” shows the data file produced by this Ant task for a simple Java system.
Example 26.19. The hackystat.xml file produced by the CloverToHackystat.xsl transform
<?xml version="1.0" encoding="UTF-8"?> <xmldata> <entry sdt="Coverage" tool="Clover" granularity="statement" fileName="/Users/johnson/svn-csdl/StackyHack/src/edu/hawaii/stack/ClearStack.java" covered="1" uncovered="1"/> <entry sdt="Coverage" tool="Clover" granularity="statement" fileName="/Users/johnson/svn-csdl/StackyHack/src/edu/hawaii/stack/EmptyStackException.java" covered="1" uncovered="0"/> <entry sdt="Coverage" tool="Clover" granularity="statement" fileName="/Users/johnson/svn-csdl/StackyHack/src/edu/hawaii/stack/TestStack.java" covered="13" uncovered="1"/> <entry sdt="Coverage" tool="Clover" granularity="statement" fileName="/Users/johnson/svn-csdl/StackyHack/src/edu/hawaii/stack/TestClearStack.java" covered="11" uncovered="0"/> <entry sdt="Coverage" tool="Clover" granularity="statement" fileName="/Users/johnson/svn-csdl/StackyHack/src/edu/hawaii/stack/Stack.java" covered="16" uncovered="3"/> <entry sdt="UnitTest" tool="JUnit" path="/Users/johnson/svn-csdl/StackyHack/src/edu/hawaii/stack/Stack.java" result="pass" name="foo"/> </xmldata>
Example 26.20, “XmlData CLI invocation” shows a simple command line invocation of the XmlData sensor and the resulting output.
Example 26.20. XmlData CLI invocation
admin01:~/svn-csdl/StackyHack johnson$ java -jar ~/java/sensor.xmldata-cli.jar -file /Users/johnson/svn-csdl/StackyHack/build/clover/hackystat.xml -createRunTime runTime -verbose true Verbose mode on: true Runtime name is: runTime, value is: 1168192491004 Sensor enabled: true Processing file: /Users/johnson/svn-csdl/StackyHack/build/clover/hackystat.xml Sending to sensorshell: Coverage [add, fileName=/Users/johnson/svn-csdl/StackyHack/src/edu/hawaii/stack/ClearStack.java, uncovered=1, granularity=statement, tool=Clover, covered=1, runTime=1168192491004] Sending to sensorshell: Coverage [add, fileName=/Users/johnson/svn-csdl/StackyHack/src/edu/hawaii/stack/EmptyStackException.java, uncovered=0, granularity=statement, tool=Clover, covered=1, runTime=1168192491004] Sending to sensorshell: Coverage [add, fileName=/Users/johnson/svn-csdl/StackyHack/src/edu/hawaii/stack/TestStack.java, uncovered=1, granularity=statement, tool=Clover, covered=13, runTime=1168192491004] Sending to sensorshell: Coverage [add, fileName=/Users/johnson/svn-csdl/StackyHack/src/edu/hawaii/stack/TestClearStack.java, uncovered=0, granularity=statement, tool=Clover, covered=11, runTime=1168192491004] Sending to sensorshell: Coverage [add, fileName=/Users/johnson/svn-csdl/StackyHack/src/edu/hawaii/stack/Stack.java, uncovered=3, granularity=statement, tool=Clover, covered=16, runTime=1168192491004]
The first step in troubleshooting your sensor installation is to verify that your Hackystat host and key settings are valid and that you can contact the Hackystat server, as described in Section 2.4, “HackyInstaller GUI: Setting and verifying the Hackystat host and user key”
If you find that you need to modify the XSL stylesheet in some manner, you may find it useful to read the Developer Guide section called Section 17.3, “Designing a sensor using the XmlData sensor”, or the XmlData sensor documentation at Section 26.34, “XmlData”.
The XmlData sensor writes out a file called XmlData.0.log to the .hackystat/logs directory that can be useful in debugging your installation.
If none of the above troubleshooting activities solves your problem, then you should send an email to your Hackystat Administrator to request help. Please include in your email the following information:
The output from 'java -version'.
The output from 'java -jar sensorshell.jar -verify'.
The contents of your sensor.properties file.
The contents of the XmlData.0.log file.
A description of the problem you are having.
To disable XmlData sensor data collection temporarily from Ant or the command-line, invoke HackyInstaller, bring up the XmlData-Ant or XmlData-Cli configuration window, and uncheck the "Enable XmlData sensor" property, and apply the setting. To permanently uninstall the XmlData sensor, press the "Uninstall" button.