Perhaps you want to display your coverage reports generated by emma within your cruisecontrol installation.
There are at least three different ways to get this done. I used cruisecontrol-bin-2.8.1 and the way described here.
1. By using the artifactspublisher you can just store your html emma reports within your artifacts and display them inside of cruise control by using an iframe. More information about this way can be found here: http://markmail.org/message/oew5ope3jcdds5az
2. Using the method i describe within this post. It is similar to the way junit reports are included by using xsl.
3. Using EmmaArtifactWidget that ships with cc. I tried to find more information about this widget and how to use it but found none. Usage of widgets is badly documented within cc.
At first we have to add emma code coverage tasks to the default project called ‘connectfour’.
<project name="connectfour" default="all">
<target name="all" depends="clean, compile, sleep, test,emma.report, jar"/>
<target name="clean">
<delete dir="target" quiet="true" />
</target>
<property name="emma.dir" location="bin/emma" />
<property name="emma.thresholds" value="class:100,method:100,block:100,line:100" />
<path id="emma.lib">
<pathelement location="lib/emma.jar" />
<pathelement location="lib/emma_ant.jar" />
</path>
<taskdef resource="emma_ant.properties" classpathref="emma.lib" />
<target name="compile">
<mkdir dir="target/classes"/>
<javac srcdir="src" destdir="target/classes" debug="true" />
</target>
<target name="sleep">
<echo message="Sleeping for a while so you can see the build in the new dashboard" />
<sleep seconds="0" />
</target>
<target name="emma.instrument">
<emma enabled="true">
<instr instrpath="target/classes" destdir="target/classes" metadatafile="target/test-results/metadata.emma" merge="true" mode="overwrite" />
</emma>
</target>
<target name="emma.report">
<emma enabled="true">
<report sourcepath="src" sort="+name" metrics="method:83,block:83,line:74,class:88">
<fileset dir="target/test-results/">
<include name="*.emma" />
<include name="*.ec" />
</fileset>
<xml outfile="target/test-results/coverage.xml" depth="method" />
<html outfile="target/test-results/index.html" depth="method" columns="name,class,method,block,line" />
</report>
</emma>
</target>
<target name="test" depends="compile,emma.instrument">
<mkdir dir="target/test-classes"/>
<javac srcdir="test" destdir="target/test-classes">
<classpath>
<pathelement location="target/classes"/>
<pathelement location="lib/junit.jar"/>
</classpath>
</javac>
<mkdir dir="target/test-results"/>
<junit haltonfailure="no" fork="yes" printsummary="on">
<classpath >
<pathelement location="target/classes"/>
<pathelement location="lib/junit.jar"/>
<path refid="emma.lib" />
<pathelement location="target/test-classes"/>
</classpath>
<jvmarg value="-Demma.coverage.out.file=target/test-results/coverage.emma" />
<jvmarg value="-Demma.coverage.out.merge=true" />
<formatter type="brief" usefile="false"/>
<formatter type="xml" />
<batchtest todir="target/test-results" >
<fileset dir="target/test-classes" includes="**/*Test.class"/>
</batchtest>
</junit>
</target>
<target name="jar" depends="compile">
<jar jarfile="target/connectfour.jar" basedir="target/classes"/>
</target>
</project>
You will have to change the CruiseControl project configuration. The schedule section should look like this:
<schedule interval="300">
<ant anthome="apache-ant-1.7.0" buildfile="build.xml" antWorkingDir="projects/${project.name}" />
</schedule>
My full config.xml:
<cruisecontrol>
<project name="connectfour"> <listeners> <currentbuildstatuslistener file="logs/${project.name}/status.txt"/> </listeners> <bootstrappers> <antbootstrapper anthome="apache-ant-1.7.0" buildfile="projects/${project.name}/build.xml" target="clean" /> </bootstrappers> <modificationset quietperiod="30"> <!— touch any file in connectfour project to trigger a build —> <filesystem folder="projects/${project.name}"/> </modificationset> <schedule interval="300"> <ant anthome="apache-ant-1.7.0" buildfile="build.xml" antWorkingDir="projects/${project.name}" /> </schedule> <log> <merge dir="projects/${project.name}/target/test-results"/> </log> <publishers> <onsuccess> <artifactspublisher dest="artifacts/${project.name}" file="projects/${project.name}/target/${project.name}.jar"/> </onsuccess> </publishers> </project></cruisecontrol>
Add the following section below for example your testresults tab in cruisecontrol-bin-2.8.1/webapps/cruisecontrol/main.jsp
<cruisecontrol:tab name="emmaResults" label="Emma Results" >
<%@ include file="emmadetails.jsp" %>
</cruisecontrol:tab>
Add a new file called emmadetails.jsp in cruisecontrol-bin-2.8.1/webapps/cruisecontrol/
<%@ taglib uri="/WEB-INF/cruisecontrol-jsp11.tld" prefix="cruisecontrol"%><cruisecontrol:xsl xslFile="/xsl/emma.xsl"/>
Add a new xsl file that will parse your CruiseControl xml build log called emma.xsl in cruisecontrol-bin-2.8.1/webapps/cruisecontrol/xsl/ :
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:output method="html"/><xsl:template match="/" mode="emma">
<xsl:if test="count(/cruisecontrol/report/data/all/package) > 0">
<table align="center" cellpadding="2" cellspacing="0" border="0" width="98%">
<tbody>
<tr>
<th class="checkstyle-sectionheader" colspan="5" align="left">Emma Results</th>
</tr>
<tr>
<td class="checkstyle-sectionheader">Package</td>
<td class="checkstyle-sectionheader">Class Coverage</td>
<td class="checkstyle-sectionheader">Method Coverage</td>
<td class="checkstyle-sectionheader">Block Coverage</td>
<td class="checkstyle-sectionheader">Line Coverage</td>
</tr>
<xsl:for-each select="/cruisecontrol/report/data/all/package">
<xsl:sort select="name"/> <tr> <xsl:if test="position() mod 2 = 1"> <xsl:attribute name="class">checkstyle-oddrow</xsl:attribute> </xsl:if> <td><xsl:value-of select="name"/></td>
<xsl:for-each select="coverage">
<td>
<xsl:value-of select="@value"/>
</td>
</xsl:for-each>
</tr>
</xsl:for-each>
</tbody>
</table>
</xsl:if>
</xsl:template><xsl:template match="/">
<xsl:apply-templates select="." mode="emma"/>
</xsl:template>
</xsl:stylesheet>