Crimson and Clover
As part of work to do provide coverage reports for the TCK of JCache we had to add a coverage tool. As we are open source I spent some time playing with coverage tools.
We build with Maven 3. For reasons do with usage of the TCK, we have four standalone modules: jsr107soec, jsr107tck, RI and Demo. Within the jsr107tck and RI there is a parent pom and children with back references to their parents. To easily run the four top level modules we have an aggregate module which is not declared as a parent in the poms of the four top level modules. It looks like this.
<project xmlns_xsi="http://www.w3.org/2001/XMLSchema-instance" xsi_schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>javax.cache</groupId> <artifactId>jsr107-parent</artifactId> <version>0.12-SNAPSHOT</version> <packaging>pom</packaging> <build> <plugins> <plugin> <groupId>com.atlassian.maven.plugins</groupId> <artifactId>maven-clover2-plugin</artifactId> <version>3.2.0</version> <configuration> <cloverDatabase>${java.io.tmpdir}/clover/clover.db</cloverDatabase> <singleCloverDatabase>true</singleCloverDatabase> <generatePdf>false</generatePdf> <generateXml>false</generateXml> <generateHtml>true</generateHtml> </configuration> </plugin> </plugins> </build> <modules> <module>jsr107spec</module> <module>RI</module> <module>jsr107tck</module> <module>demo</module> </modules> </project>
An unusual aspect of this arrangements is that all tests for the RI are contained in the jsr107tck module. The RI itself has no tests.
My approach was to spend a few hours with first the open source coverage tools, Emma and Cobertura, and then to move on to Clover which I have used before, if needed.
Emma’s Maven plugin is old and needs a work around for Java 7. But got it basically working but could not get it to deal with our complicated structure.
Then I tried Cobertura. Version 2.6 of the Maven module was released just in August. It worked fine with Java 7. But once again I found it difficult to make progress with our complicated structure. I was thinking the best approach would be to give all modules the same coverage database location. In Cobertura you do this with a system property. e.g. -Dnet.sourceforge.cobertura.datafile=/path/cobertura.ser
. I didn’t get this working.
I then tried Clover, and got up and running. I specified the same clover.db location for all modules. I needed to add this to the aggregate pom, and each top level pom. For those top level modules with children, defining it in the parent was sufficient. I added the following to each of those poms.
Then to run a build with clover instrumentation:
`mvn clean com.atlassian.maven.plugins:maven-clover2-plugin:setup install`
And to run the clover report:
`mvn com.atlassian.maven.plugins:maven-clover2-plugin:clover`
Note the wordy module definitions. You can use the short name of clover2 if you add the following to your settings.xml:
<pluginGroups> <pluginGroup>com.atlassian.maven.plugins</pluginGroup> </pluginGroups>
The first example then becomes:
`mvn clean clover2:setup install`
It would be great if they could change the User Guide to point out this step as it mars what is otherwise a very smooth experience.