It's all about the answers!

Ask a question

Ant task for publishing code coverage results?


Torben Knerr (41112) | asked Sep 27 '07, 9:55 a.m.
Is there a possibility to include the code coverage results into our continous builds, similar to the results report shown in https://jazz.net/wiki/bin/view/Main/GettingStartedWithCoverage#Getting_Coverage_Reports_from_Ja ?

I was expecting something like a coveragePublisher ant task, similar to the junitLogPublisher or buildResultPublisher tasks defined in the example build.xml file. Does such a task exist in 0.6.0M2a?

Thanks in advance and best regards,
Torben

5 answers



permanent link
Tobias Widmer (3211) | answered Sep 27 '07, 12:14 p.m.
torben.knerr schrieb:
Is there a possibility to include the code coverage results into our
continous builds, similar to the results report shown in
https://jazz.net/wiki/bin/view/Main/GettingStartedWithCoverage#Getting_Coverage_Reports_from_Ja
?

I was expecting something like a coveragePublisher ant task, similar
to the junitLogPublisher or buildResultPublisher tasks defined in the
example build.xml file. Does such a task exist in 0.6.0M2a?

Thanks in advance and best regards,
Torben


Hi Torben

You can use a plain filePublisher ant task. After you've created the
coverage report during the build (usually a file with .analysis
extension), just zip it using the zip ant task and use a filePubisher to
publish the zipped coverage report into the repository.

HTH,

Tobias

permanent link
Torben Knerr (41112) | answered Sep 27 '07, 5:25 p.m.
Hi Tobias,

thanks for the quick reply.

I have tried the filePublisher task, but it requires the contributionTypeId to be set:

build.xml:221: Missing required attribute "contributionTypeId".


With the right contributionTypeId set, will it produce the same, nice looking output shown on this picture, or will it be a plain download link pointing to a zip file?

Also, I am not sure where the .analysis file comes from... I am currently using the emmajava task, which outputs an xml file:


<taskdef name="emmajava" classname="com.vladium.emma.emmajavaTask"/>

<emmajava
enabled="true"
classname="com.zuehlke.camp07.eaa.jazz.hello.HelloTest"
classpathref="run.cp"
sourcepath="${buildWorkingDir}/HelloGuys/src"
libclasspathref="buildtoolkit.path" >
<xml outfile="${buildWorkingDir}/coverage.xml" />
</emmajava>


Maybe I am doing something wrong?

Best regards,
Torben

permanent link
Stefan Hufnagl (29411920) | answered Oct 01 '07, 10:39 a.m.
Hi,

also I'm interested in codecoverage.

Questions:
* Is there a codecoverage example available?
* Snippets from a build.xml would be great...

Thanks

Stefan

permanent link
Tobias Widmer (3211) | answered Oct 02 '07, 11:11 a.m.
torben.knerr schrieb:
Hi Tobias,

thanks for the quick reply.

I have tried the filePublisher task, but it requires the
contributionTypeId to be set:

build.xml:221: Missing required attribute
"contributionTypeId".

With the right contributionTypeId set, will it produce the same, nice
looking output shown on
this
picture, or will it be a plain download link pointing to a zip
file?

Also, I am not sure where the .analysis file comes from... I am
currently using the emmajava task, which outputs an xml file:


taskdef name="emmajava"
classname="com.vladium.emma.emmajavaTask"/

emmajava
enabled="true"
classname="com.zuehlke.camp07.eaa.jazz.hello.HelloTest"
classpathref="run.cp"
sourcepath="${buildWorkingDir}/HelloGuys/src"
libclasspathref="buildtoolkit.path"
<xml outfile="${buildWorkingDir}/coverage.xml" /
/emmajava


Maybe I am doing something wrong?

Best regards,
Torben


Yes, if you use the contribution id "com.ibm.team.build.coverage", build
results will have an additional coverage tab.

We don't use the Emma tasks directly, but instead have adapted tasks
which accept additional arguments.

For M4, we are planning to create an ANT example on how to set up coverage.

These are the relevant snippets from our build.xml file:


<!--code coverage properties and tasks-->
<tempfile property="analysisFile" destdir="${working.dir}"
suffix="_${buildDefinitionId}.analysis"/>
<tempfile property="summaryFile" destdir="${working.dir}"
suffix="_${buildDefinitionId}.summary"/>

<property name="zippedReportDownload"
value="Coverage-${buildDefinitionId}.zip" />
<property name="zippedReportFile"
value="${working.dir}/${zippedReportDownload}"/>
<property name="zippedAnalysisFile"
value="${working.dir}/Analysis-${buildDefinitionId}.zip"/>
<property name="reportDir" value="${working.dir}/report"/>
<property name="reportIndex" value="${reportDir}/index.html"/>
<property name="instrumented" value="${working.dir}/instrumented"/>

<tempfile property="metaFile" destdir="${working.dir}"
suffix="_${buildDefinitionId}.em"/>
<tempfile property="traceFile" destdir="${working.dir}"
suffix="_${buildDefinitionId}.ec"/>

<property name="outVMArgument"
value="-Demma.coverage.out.file=${traceFile}" />
<property name="exclusion.filter"
value=
"org.apache*,
org.eclipse*,
org.jdom*,
org.mortbay*,
org.osgi*,
org.xmlsoap*,
org.junit*,
junit*,
com.ibm.db2*,
db2*,
COM.ibm.db2*,
com.ibm.etools.*,
com.ibm.ejs.*,
com.sun*,
com.ibm.icu*,
com.ibm.ObjectQuery.*,
*test*,
*borland*,
*objectspace*,
*jcraft*,
com.ibm.team.repository.service.internal.query*,
com.ibm.swt.xulrunner*,
com.ibm.websphere*,
default package,
java*,
javax*,
mx4j*,
sqlj*,
JDOM*" />

<!-- This may change if we move to a newer build -->
<property name="bootVMArgument"
value="-Xbootclasspath/a:${emma-libs}/emma.jar"/>

<!-- This may change if we move to a newer build -->
<path id="emma.lib" >
<pathelement location="${emma-libs}/emma.jar" />
<pathelement location="${emma-libs}/emma_ant.jar" />
</path>

<taskdef name="report"
classname="com.vladium.emma.report.reportTask"
classpathref="emma.lib" />

<taskdef name="instr"
classname="com.vladium.emma.instr.instrTask" classpathref="emma.lib" />


<target name="invokeInstrumentation" if="shouldRunCoverage">
<buildResultPublisher buildResultUUID="${buildResultUUID}"
repositoryAddress="${repositoryAddress}"
userId="${userId}"
password="${password}"
currentActivityLabel="preparing tests..." />
<timestamp message="started code instrumentation" />
<path id="analysis.lib" >
<path refid="emma.lib" />
<pathelement
location="/releng/jazz/buildsystem/coverage/com.ibm.team.coverage.common.jar"
/>
<fileset dir="${working.dir}/eclipse/plugins"
includes="org.eclipse.core.*.jar, org.apache.*.jar "/>
</path>
<taskdef name="coverage"
classname="com.ibm.team.coverage.common.coverageTask"
classpathref="analysis.lib" />
<condition property="coverage.exclude" value="java.*, javax.*">
<not>
<isset property="coverage.exclude" />
</not>
</condition>
<condition property="coverage.include" value="">
<not>
<isset property="coverage.include" />
</not>
</condition>
<coverage>
<instr mode="overwrite" merge="yes" metadatafile="${metaFile}">
<filter excludes="${exclusion.filter}" />
<filter excludes="${coverage.exclude}" />
<filter includes="${coverage.include}" />
<instrpath>
<fileset dir="${working.dir}"
includes="eclipse.test/**/*.jar,eclipse.plainjava.test/**/*.jar"
excludes="**/com.ibm.team.build.cruisecontrol.controller.tests**/**,**/org.eclipse*/**,**/org.apache*/**"/>
</instrpath>
</instr>
</coverage>
<timestamp message="finished code instrumentation" />
</target>


<target name="invokeCoverageReports" if="generateCoverageReport">
<mkdir dir="${reportDir}" />
<buildResultPublisher buildResultUUID="${buildResultUUID}"
repositoryAddress="${repositoryAddress}"
userId="${userId}"
password="${password}"
currentActivityLabel="creating coverage
report..." />
<timestamp message="started coverage report generation" />
<taskdef name="coverage"
classname="com.ibm.team.coverage.common.coverageTask"
classpathref="analysis.lib" />
<taskdef name="analysis"
classname="com.ibm.team.coverage.common.analysisTask"
classpathref="analysis.lib" />
<dirset id="project.dirs" dir="${working.dir}/plugins" includes="*"
excludes="org.eclipse.*, org.apache.*, org.mortbay.*,
org.jivesoftware.*, org.jdom, org.dojotoolkit, org.mozilla.rhino,
org.w3c.sac, website_content, config, anttasks, bootstrap, buildfiles,
com.sun.rome, java.*, javax.*, .jazz*" />
<coverage>
<!--${working.dir}/coverage-src created in postBuild target in PDE
Build customTargets.xml-->
<report units="instr" depth="method" columns="name, class, method,
block, line" sort="+name,+class,+method,+block"
metrics="method:70,block:80,line:80,class:100"
sourcepath="${working.dir}/coverage-src">
<infileset dir="${working.dir}" includes="*.em, *.ec"/>
<html outfile="${reportIndex}"/>
</report>
<analysis flags="0" projectsref="project.dirs"
sourcepath="${working.dir}/coverage-src" outfile="${analysisFile}"
summaryFile="${summaryFile}"
componentMap="${working.dir}/config/componentMap.xml">
<infileset dir="${working.dir}" includes="*.em, *.ec"/>
</analysis>
</coverage>
<zip destfile="${zippedReportFile}" basedir="${reportDir}" />
<zip destfile="${zippedAnalysisFile}">
<fileset file="${analysisFile}" />
</zip>
<timestamp message="finished coverage report generation" />
<antcall target="publishReports" />
</target>


<target name="publishReports">
<property name="publishDestination"
value="${artifactPublishRoot}/${buildDefinitionId}/${buildId}" />
<mkdir dir="${publishDestination}" />
<echo message="Copying ${zippedReportFile} to ${publishDestination}" />
<copy todir="${publishDestination}"
file="${zippedReportFile}"
verbose="true"
overwrite="true"
failonerror="false" />
<artifactLinkPublisher buildResultUUID="${buildResultUUID}"
repositoryAddress="${repositoryAddress}"
userId="${userId}"
password="${password}"
verbose="true"
label="Coverage Report for ${buildId}"

url="http://${buildServer}:8080/builds/${buildDefinitionId}/${buildId}/${zippedReportDownload}"

failOnError="false"/>
<filePublisher buildResultUUID="${buildResultUUID}"
repositoryAddress="${repositoryAddress}"
userId="${userId}"
password="${password}"
contributionTypeId="com.ibm.team.build.coverage"
verbose="true"
filePath="${zippedAnalysisFile}"
label="Coverage Report"
failOnError="false" />
<filePublisher buildResultUUID="${buildResultUUID}"
repositoryAddress="${repositoryAddress}"
userId="${userId}"
password="${password}"
contributionTypeId="com.ibm.team.build.summary"
verbose="true"
filePath="${summaryFile}"
label="Coverage Summary"
failOnError="false" />
</target>

permanent link
Tobias Widmer (3211) | answered Oct 02 '07, 11:13 a.m.
Tobias Widmer schrieb:

The "analysis.lib" library is part of the com.ibm.team.coverage.common
plugin and needs to be on the classpath of the build engine.

Tobias

torben.knerr schrieb:
Hi Tobias,

thanks for the quick reply.
I have tried the filePublisher task, but it requires the
contributionTypeId to be set:

build.xml:221: Missing required attribute
"contributionTypeId".

With the right contributionTypeId set, will it produce the same, nice
looking output shown on
this
picture, or will it be a plain download link pointing to a zip
file?
Also, I am not sure where the .analysis file comes from... I am
currently using the emmajava task, which outputs an xml file:


taskdef name="emmajava"
classname="com.vladium.emma.emmajavaTask"/

emmajava
enabled="true"
classname="com.zuehlke.camp07.eaa.jazz.hello.HelloTest"
classpathref="run.cp"
sourcepath="${buildWorkingDir}/HelloGuys/src"
libclasspathref="buildtoolkit.path"
xml outfile="${buildWorkingDir}/coverage.xml" /
/emmajava


Maybe I am doing something wrong?

Best regards,
Torben


Yes, if you use the contribution id "com.ibm.team.build.coverage", build
results will have an additional coverage tab.

We don't use the Emma tasks directly, but instead have adapted tasks
which accept additional arguments.

For M4, we are planning to create an ANT example on how to set up coverage.

These are the relevant snippets from our build.xml file:


!--code coverage properties and tasks--
tempfile property="analysisFile" destdir="${working.dir}"
suffix="_${buildDefinitionId}.analysis"/
tempfile property="summaryFile" destdir="${working.dir}"
suffix="_${buildDefinitionId}.summary"/

property name="zippedReportDownload"
value="Coverage-${buildDefinitionId}.zip" /
property name="zippedReportFile"
value="${working.dir}/${zippedReportDownload}"/
property name="zippedAnalysisFile"
value="${working.dir}/Analysis-${buildDefinitionId}.zip"/
property name="reportDir" value="${working.dir}/report"/
property name="reportIndex" value="${reportDir}/index.html"/
property name="instrumented" value="${working.dir}/instrumented"/

tempfile property="metaFile" destdir="${working.dir}"
suffix="_${buildDefinitionId}.em"/
tempfile property="traceFile" destdir="${working.dir}"
suffix="_${buildDefinitionId}.ec"/

property name="outVMArgument"
value="-Demma.coverage.out.file=${traceFile}" /
property name="exclusion.filter"
value=
"org.apache*,
org.eclipse*,
org.jdom*,
org.mortbay*,
org.osgi*,
org.xmlsoap*,
org.junit*,
junit*,
com.ibm.db2*,
db2*,
COM.ibm.db2*,
com.ibm.etools.*,
com.ibm.ejs.*,
com.sun*,
com.ibm.icu*,
com.ibm.ObjectQuery.*,
*test*,
*borland*,
*objectspace*,
*jcraft*,
com.ibm.team.repository.service.internal.query*,
com.ibm.swt.xulrunner*,
com.ibm.websphere*,
default package,
java*,
javax*,
mx4j*,
sqlj*,
JDOM*" /

!-- This may change if we move to a newer build --
property name="bootVMArgument"
value="-Xbootclasspath/a:${emma-libs}/emma.jar"/

!-- This may change if we move to a newer build --
path id="emma.lib"
pathelement location="${emma-libs}/emma.jar" /
pathelement location="${emma-libs}/emma_ant.jar" /
/path

taskdef name="report"
classname="com.vladium.emma.report.reportTask"
classpathref="emma.lib" /

taskdef name="instr"
classname="com.vladium.emma.instr.instrTask"
classpathref="emma.lib" /


target name="invokeInstrumentation" if="shouldRunCoverage"
buildResultPublisher buildResultUUID="${buildResultUUID}"
repositoryAddress="${repositoryAddress}"
userId="${userId}"
password="${password}"
currentActivityLabel="preparing
tests..." /
timestamp message="started code instrumentation" /
path id="analysis.lib"
path refid="emma.lib" /
pathelement
location="/releng/jazz/buildsystem/coverage/com.ibm.team.coverage.common.jar"
/
fileset dir="${working.dir}/eclipse/plugins"
includes="org.eclipse.core.*.jar, org.apache.*.jar "/
/path
taskdef name="coverage"
classname="com.ibm.team.coverage.common.coverageTask"
classpathref="analysis.lib" /
condition property="coverage.exclude" value="java.*, javax.*"
not
isset property="coverage.exclude" /
/not
/condition
condition property="coverage.include" value=""
not
isset property="coverage.include" /
/not
/condition
coverage
instr mode="overwrite" merge="yes" metadatafile="${metaFile}"
filter excludes="${exclusion.filter}" /
filter excludes="${coverage.exclude}" /
filter includes="${coverage.include}" /
instrpath
fileset dir="${working.dir}"
includes="eclipse.test/**/*.jar,eclipse.plainjava.test/**/*.jar"
excludes="**/com.ibm.team.build.cruisecontrol.controller.tests**/**,**/org.eclipse*/**,**/org.apache*/**"/

/instrpath
/instr
/coverage
timestamp message="finished code instrumentation" /
/target


target name="invokeCoverageReports" if="generateCoverageReport"
mkdir dir="${reportDir}" /
buildResultPublisher buildResultUUID="${buildResultUUID}"
repositoryAddress="${repositoryAddress}"
userId="${userId}"
password="${password}"
currentActivityLabel="creating
coverage report..." /
timestamp message="started coverage report generation" /
taskdef name="coverage"
classname="com.ibm.team.coverage.common.coverageTask"
classpathref="analysis.lib" /
taskdef name="analysis"
classname="com.ibm.team.coverage.common.analysisTask"
classpathref="analysis.lib" /
dirset id="project.dirs" dir="${working.dir}/plugins"
includes="*" excludes="org.eclipse.*, org.apache.*, org.mortbay.*,
org.jivesoftware.*, org.jdom, org.dojotoolkit, org.mozilla.rhino,
org.w3c.sac, website_content, config, anttasks, bootstrap, buildfiles,
com.sun.rome, java.*, javax.*, .jazz*" /
coverage
!--${working.dir}/coverage-src created in postBuild target
in PDE Build customTargets.xml--
report units="instr" depth="method" columns="name, class,
method, block, line" sort="+name,+class,+method,+block"
metrics="method:70,block:80,line:80,class:100"
sourcepath="${working.dir}/coverage-src"
infileset dir="${working.dir}" includes="*.em, *.ec"/
html outfile="${reportIndex}"/
/report
analysis flags="0" projectsref="project.dirs"
sourcepath="${working.dir}/coverage-src" outfile="${analysisFile}"
summaryFile="${summaryFile}"
componentMap="${working.dir}/config/componentMap.xml"
infileset dir="${working.dir}" includes="*.em, *.ec"/
/analysis
/coverage
zip destfile="${zippedReportFile}" basedir="${reportDir}" /
zip destfile="${zippedAnalysisFile}"
fileset file="${analysisFile}" /
/zip
timestamp message="finished coverage report generation" /
antcall target="publishReports" /
/target


target name="publishReports"
property name="publishDestination"
value="${artifactPublishRoot}/${buildDefinitionId}/${buildId}" /
mkdir dir="${publishDestination}" /
echo message="Copying ${zippedReportFile} to
${publishDestination}" /
copy todir="${publishDestination}"
file="${zippedReportFile}"
verbose="true"
overwrite="true"
failonerror="false" /
artifactLinkPublisher buildResultUUID="${buildResultUUID}"
repositoryAddress="${repositoryAddress}"
userId="${userId}"
password="${password}"
verbose="true"
label="Coverage Report for ${buildId}"

url="http://${buildServer}:8080/builds/${buildDefinitionId}/${buildId}/${zippedReportDownload}"

failOnError="false"/
filePublisher buildResultUUID="${buildResultUUID}"
repositoryAddress="${repositoryAddress}"
userId="${userId}"
password="${password}"
contributionTypeId="com.ibm.team.build.coverage"
verbose="true"
filePath="${zippedAnalysisFile}"
label="Coverage Report"
failOnError="false" /
filePublisher buildResultUUID="${buildResultUUID}"
repositoryAddress="${repositoryAddress}"
userId="${userId}"
password="${password}"
contributionTypeId="com.ibm.team.build.summary"
verbose="true"
filePath="${summaryFile}"
label="Coverage Summary"
failOnError="false" /
/target

Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.