Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

[ANSWER]Build.xml Example With Code Coverage

Following you will find a build.xml file that does everything needed to "integrate" well with Jazz. If I have missed anything let me know. Also, if you have questions I will try to help out the best I can.

This is in response to the code coverage topic I posted a few days back, I hope this helps some people that my be a little lost/stuck.


<?xml version="1.0" encoding="UTF-8"?>
<project basedir="." default="all">
<!--
The build file must be invoked by the jazz build engine.

Prerequisites:

1. Create a new Ant build definition in Jazz. Set the build file field on the Ant page
to this build file.

2. You must download the eclipse JDT standalone compiler (ecj.jar) to use this build file.
Find it in the eclipse.org platform downloads. Look for "JDT Core Batch Compiler"

3. You must update the antArgs property in the build definition properties,
to point to your location of ecj.jar. For example, assuming you saved ecj.jar to
C:\, you would set the antArgs to: -lib C:\ecj.jar -lib C:\jazz\buildsystem\buildtoolkit

4. You must update the junit.jar property in this build file to point at a junit.jar.
To get junit.jar, you can use the one from an eclipse installation (eclipse\plugins\junit...)
or download it from junit.org.

5. You must update the toolkit.dir property in this build file to point to the build toolkit directory.


6. Please Set the following properties in your build definition
build.user - Your repository user to connect as
build.password - Your repository users password
file.destination.jar - Your generated jar file name
test.class.name - Your test suite main class (Assumes one test suite class for all tests)

7. Expected Directory Structure
<base>
>src
>test
>src
>lib
>build-lib

-->
<!-- Activiy ID used to identify in the build status -->
<property name="activity.compile" value="compile" />
<property name="activity.jar" value="jar" />
<property name="activity.test" value="test" />
<property name="activity.instrument" value="instrument" />
<property name="activity.coverage" value="coverage" />
<property name="activity.coverage.report" value="report" />
<property name="activity.coverage.publish" value="publish" />

<!-- Location of important libs, may need to be customized -->
<property name="junit.jar" value="${basedir}/build-lib/junit-4.4.jar" />
<property name="toolkit.dir" value="${basedir}/../../../../buildtoolkit" />
<property name="file.compile.log" value="${basedir}/compile.xml" />

<!-- Coverage settings -->
<property name="coverage.dir" value="${basedir}/coverage" />
<property name="file.coverage.analysis" value="${coverage.dir}/coverage.analysis" />
<property name="file.coverage.summary" value="${coverage.dir}/coverage.summary" />
<property name="file.coverage.meta" value="${coverage.dir}/coverage.em" />
<property name="file.coverage.trace" value="${coverage.dir}/coverage.ec" />
<property name="file.coverage.report.zip" value="${coverage.dir}/coverage.zip" />
<property name="file.coverage.analysis.zip" value="${coverage.dir}/coverage-analysis.zip" />

<property name="coverage.instrumented.dir" value="${coverage.dir}/instrumented" />
<property name="coverage.report.dir" value="${coverage.dir}/report" />
<property name="coverage.report.index" value="${coverage.report.dir}/index.html" />

<!-- Build settings -->
<property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter" />
<property name="build.src.dir" value="${basedir}/src" />
<property name="build.test.src.dir" value="${basedir}/test/src" />
<property name="build.destination.dir" value="${basedir}/bin" />
<property name="build.test.destination.dir" value="${basedir}/test/bin" />

<target name="all" depends="build" />

<target name="build" depends="init, compile, instrument, jar, test, reports.create, reports.publish">
<echo message="Build ${buildDefinitionId} completed." />
</target>

<!-- Setup destination directories -->
<target name="init">
<delete dir="${build.destination.dir}" />
<mkdir dir="${build.destination.dir}" />
<delete dir="${build.test.destination.dir}" />
<mkdir dir="${build.test.destination.dir}" />
<delete dir="${coverage.report.dir}" />
<mkdir dir="${coverage.report.dir}" />
</target>

<target name="compile">
<startBuildActivity activityId="${activity.compile}" label="compiling..." buildResultUUID="${buildResultUUID}" repositoryAddress="${repositoryAddress}" userId="${build.user}" password="${build.password}" />
<!-- Compile main source code -->
<javac srcdir="${build.src.dir}" destdir="${build.destination.dir}" source="1.5" target="1.5" debug="on" nowarn="on" failonerror="false">
<classpath>
<pathelement path="${junit.jar}" />
</classpath>
<compilerarg line="-1.5 -log ${file.compile.log}" />
</javac>
<!-- Compile test classes -->
<javac srcdir="${build.test.src.dir}" destdir="${build.test.destination.dir}" source="1.5" target="1.5" debug="on" nowarn="on" failonerror="false">
<classpath>
<pathelement path="${junit.jar}" />
<pathelement path="${build.destination.dir}" />
</classpath>
</javac>
<!-- Publish the compile log to the jazz server -->
<jdtCompileLogPublisher buildResultUUID="${buildResultUUID}" repositoryAddress="${repositoryAddress}" userId="${build.user}" password="${build.password}" filePath="${file.compile.log}" />
<completeBuildActivity activityId="${activity.compile}" buildResultUUID="${buildResultUUID}" repositoryAddress="${repositoryAddress}" userId="${build.user}" password="${build.password}" />
</target>

<target name="instrument">
<startBuildActivity activityId="${activity.instrument}" label="instrumenting..." buildResultUUID="${buildResultUUID}" repositoryAddress="${repositoryAddress}" userId="${build.user}" password="${build.password}" />
<path id="toolkit.lib">
<fileset dir="${toolkit.dir}" />
</path>
<!-- Run coverage on the compiled code -->
<coverage>
<instr mode="overwrite" merge="yes" metadatafile="${file.coverage.meta}" verbosity="verbose">
<filter excludes="java.*, javax.*" />
<instrpath>
<dirset dir="${build.destination.dir}" includes="**/*" />
</instrpath>
</instr>
</coverage>
<completeBuildActivity activityId="${activity.instrument}" buildResultUUID="${buildResultUUID}" repositoryAddress="${repositoryAddress}" userId="${build.user}" password="${build.password}" />
</target>

<target name="jar">
<startBuildActivity activityId="${activity.jar}" label="creating jar..." buildResultUUID="${buildResultUUID}" repositoryAddress="${repositoryAddress}" userId="${build.user}" password="${build.password}" />
<jar basedir="${build.destination.dir}" destfile="${basedir}/${file.destination.jar}" />
<!-- Publish jar and make available for download -->
<artifactFilePublisher buildResultUUID="${buildResultUUID}" repositoryAddress="${repositoryAddress}" userId="${build.user}" password="${build.password}" verbose="true" filePath="${basedir}/${file.destination.jar}" label="Produced JAR" />
<completeBuildActivity activityId="${activity.jar}" buildResultUUID="${buildResultUUID}" repositoryAddress="${repositoryAddress}" userId="${build.user}" password="${build.password}" />
</target>

<target name="test">
<startBuildActivity activityId="${activity.test}" label="testing..." buildResultUUID="${buildResultUUID}" repositoryAddress="${repositoryAddress}" userId="${build.user}" password="${build.password}" />
<!-- Run junit with code coverage hooks, forked="yes" is required -->
<junit fork="yes" showoutput="yes">
<!-- You man need to tweak for the location of your emma.jar file -->
<jvmarg line="-Xbootclasspath/a:${toolkit.dir}/emma.jar -Drt.control=true -Drt.control.host=localhost -Drt.control.port=4765 -Demma.coverage.out.file=${file.coverage.trace}" />
<formatter type="xml" />
<!-- Expected a single class TestSuite -->
<test name="${test.class.name}" outfile="TestResults" />
<classpath>
<pathelement path="${basedir}/${file.destination.jar}" />
<pathelement path="${build.test.destination.dir}" />
<pathelement path="${junit.jar}" />
</classpath>
</junit>
<!-- Publis the JUnit results to jazz for view and for download -->
<logPublisher filePath="TestResults.xml" buildResultUUID="${buildResultUUID}" repositoryAddress="${repositoryAddress}" userId="${build.user}" password="${build.password}" label="JUnit log" />
<junitLogPublisher filePath="TestResults.xml" buildResultUUID="${buildResultUUID}" repositoryAddress="${repositoryAddress}" userId="${build.user}" password="${build.password}" />
<completeBuildActivity activityId="${activity.test}" buildResultUUID="${buildResultUUID}" repositoryAddress="${repositoryAddress}" userId="${build.user}" password="${build.password}" />
</target>

<!-- Generate Coverage Reports -->
<target name="reports.create">
<startBuildActivity activityId="${activity.coverage.report}" label="creating coverage report..." buildResultUUID="${buildResultUUID}" repositoryAddress="${repositoryAddress}" userId="${build.user}" password="${build.password}" />
<dirset id="project.dirs" dir="${basedir}" includes="*" />
<!-- Run coverage task on files generated from implimentation and junit execution -->
<coverage>
<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="${build.src.dir}" verbosity="verbose">
<infileset dir="${coverage.dir}" includes="*.em, *.ec" />
<html outfile="${coverage.report.index}" />
</report>
<analysis projectsref="project.dirs" flags="0" sourcepath="${build.src.dir}" outfile="${file.coverage.analysis}" summaryFile="${file.coverage.summary}" verbosity="verbose">
<infileset dir="${coverage.dir}" includes="*.em, *.ec" />
</analysis>
</coverage>
<!-- Create zip files to be uploaded -->
<zip destfile="${file.coverage.report.zip}" basedir="${coverage.report.dir}" />
<zip destfile="${file.coverage.analysis.zip}">
<fileset file="${file.coverage.analysis}" />
</zip>
<completeBuildActivity activityId="${activity.coverage.report}" buildResultUUID="${buildResultUUID}" repositoryAddress="${repositoryAddress}" userId="${build.user}" password="${build.password}" />
</target>

<!-- Publish Coverage Reports to Jazz Server -->
<target name="reports.publish">
<startBuildActivity activityId="${activity.coverage.publish}" label="publishing coverage report..." buildResultUUID="${buildResultUUID}" repositoryAddress="${repositoryAddress}" userId="${build.user}" password="${build.password}" />
<artifactFilePublisher buildResultUUID="${buildResultUUID}" repositoryAddress="${repositoryAddress}" userId="${build.user}" password="${build.password}" verbose="true" filePath="${file.coverage.report.zip}" label="Coverage Report" />
<filePublisher buildResultUUID="${buildResultUUID}" repositoryAddress="${repositoryAddress}" userId="${build.user}" password="${build.password}" contributionTypeId="com.ibm.team.build.coverage" verbose="true" filePath="${file.coverage.analysis.zip}" label="Coverage Report" failOnError="false" />
<filePublisher buildResultUUID="${buildResultUUID}" repositoryAddress="${repositoryAddress}" userId="${build.user}" password="${build.password}" contributionTypeId="com.ibm.team.build.summary" verbose="true" filePath="${file.coverage.summary}" label="Coverage Summary" failOnError="false" />
<completeBuildActivity activityId="${activity.coverage.publish}" buildResultUUID="${buildResultUUID}" repositoryAddress="${repositoryAddress}" userId="${build.user}" password="${build.password}" />
</target>

<taskdef name="artifactFilePublisher" classname="com.ibm.team.build.ant.task.ArtifactFilePublisherTask" />
<taskdef name="artifactLinkPublisher" classname="com.ibm.team.build.ant.task.ArtifactLinkPublisherTask" />
<taskdef name="buildResultPublisher" classname="com.ibm.team.build.ant.task.BuildResultPublisherTask" />
<taskdef name="filePublisher" classname="com.ibm.team.build.ant.task.FilePublisherTask" />
<taskdef name="jdtCompileLogPublisher" classname="com.ibm.team.build.ant.task.JdtCompileLogPublisherTask" />
<taskdef name="junitLogPublisher" classname="com.ibm.team.build.ant.task.JUnitLogPublisherTask" />
<taskdef name="linkPublisher" classname="com.ibm.team.build.ant.task.LinkPublisherTask" />
<taskdef name="logPublisher" classname="com.ibm.team.build.ant.task.LogPublisherTask" />
<taskdef name="startBuildActivity" classname="com.ibm.team.build.ant.task.StartBuildActivityTask" />
<taskdef name="completeBuildActivity" classname="com.ibm.team.build.ant.task.CompleteBuildActivityTask" />
<taskdef name="report" classname="com.vladium.emma.report.reportTask" />
<taskdef name="coverage" classname="com.ibm.team.coverage.common.coverageTask" />
<taskdef name="analysis" classname="com.ibm.team.coverage.common.analysisTask" />
<taskdef name="coverage" classname="com.ibm.team.coverage.common.coverageTask" />
<taskdef name="instr" classname="com.vladium.emma.instr.instrTask" />
</project>

0 votes



7 answers

Permanent link
Hi,

Would you be willing to share the improved version of the Coverage Example build script with the Coverage incubator component? I see that the build script takes considerably less effort to be adapted to a specific environment and also contains improved build activity monitoring.

If you file an enhancement request against the Code Coverage component with the source of your improved script, we could further talk whether we could integrate your build script into RTC 1.0

Thanks for your effort,

Tobias
Jazz Collaboration, Coverage, Agile Planning team

0 votes


Permanent link
Added as work item 42631

0 votes


Permanent link
Hi Guys,

I am bit new to JAZZ and hence to the build script too. I have taken the complete script and saved in my work space. I have changed the buildToolkit variable to point my installed buildtoolkit location.

Even after doing this, I am getting error in build file. It says "taskdef com.ibm.team.build.ant.task.ArtifactFilePublisherTask cannot be found"

I read about this on forum and tried following solutions.
1) I defined <classpath> within taskdef to point to my installed location of buildtoolkit.

<taskdef name="artifactFilePublisher" classname="com.ibm.team.build.ant.task.ArtifactFilePublisherTask" >
<classpath>
<fileset dir="my-location\buildtoolkit" includes="*.jar"/>
</classpath>
</taskdef>

2) One of the forum mentioned that, instead of all defining these task in build.xml, I should include BuildToolkitTaskDefs.xml, it will serve the purpose. But I couldn't locate BuildToolkitTaskDefs.xml in buildtoolkit project. I hope I have correct verison of code coverage tool which is downloaded from Download link "JazzCodeCoverage-0.6M5.zip"

The observation is, I couldn't find any Jar in this zip which can possibly have any of the task definition classes like "com.ibm.team.build.ant.task.ArtifactFilePublisherTask"

If I am missing on any steps, please help me out for this.

-- Viren
Thanks

0 votes


Permanent link
The com.ibm.team.build.ant.task.ArtifactFilePublisherTask is in the com.ibm.team.build.toolkit_0.5.0.IXXXXXXX-XXXX.jar. (The Xs would be replaced with the version information of the jar).

This jar should be in the jazz\buildsystem\buildtoolkit directory.

The BuildToolkitTaskDefs.xml file should be in the same directory.

If the jar and xml file are not in the buildtoolkit directory, did you install using install manager or the .zip file?

Martha
Jazz Team Build Component

0 votes


Permanent link
Just to be extra clear, the BuildToolkitTaskDefs.xml and the
ArtifactFilePublisherTask are not part of the "JazzCodeCoverage-0.6M5.zip".

They are part of the jazz client install at /jazz/buildsystem/buildtoolkit.

The "JazzCodeCoverage-0.6M5.zip" is meant to be installed on top of the
client install (at least the buildsystem tree portion).

---
Ryan Manwiller
Jazz Team Build

0 votes


Permanent link
Thank you very much for your quick response. This resolved my issue. I was not aware of the fact that the buildtoolkit is also a part of the jazz client.

One quick question: When unzipping the "JazzCodeCoverage-0.6M5.zip", it also creates buildtoolkit directory. Is it advisable (or necessary) to merge both the directory? (Or unzip in the same directory?)

As of now, I have both the buildtoolkit at different locations.

Thank you once again for the help.

-- Viren

0 votes


Permanent link
The zips are designed to be unzipped on top of each other. They should merge
cleanly.


"gohilv" <virendrasinhgohil@hsbc.co-dot-in.no-spam.invalid> wrote in message
news:fqr5bh$f1f$1@localhost.localdomain...
Thank you very much for your quick response. This resolved my issue. I
was not aware of the fact that the buildtoolkit is also a part of the
jazz client.

One quick question: When unzipping the
"JazzCodeCoverage-0.6M5.zip", it also creates buildtoolkit
directory. Is it advisable (or necessary) to merge both the
directory? (Or unzip in the same directory?)

As of now, I have both the buildtoolkit at different locations.

Thank you once again for the help.

-- Viren

0 votes

Your answer

Register or log in 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details

Question asked: Jan 22 '08, 3:03 p.m.

Question was seen: 14,400 times

Last updated: Jan 22 '08, 3:03 p.m.

Confirmation Cancel Confirm