This section introduces EMMA ANT tasks. It starts with an example
of how to run an application from ANT so that coverage instrumentation is
performed on-the-fly, as the classes are loaded by the JVM, and then repeats
the same process by breaking it into distinct
instrumentation/execution/reporting steps. The ANT logic sequence will be
equivalent to what was described previously, in Section 2, “Getting Started (command line)”. Additionally, the ANT build.xml
files
created below will have logic for enabling and disabling coverage through
ANT command line.
The source code located in examples/src
directory of EMMA distribution is used for all examples in this tutorial.
EMMA distribution also includes two sample ANT buildfiles,
build-onthefly.xml
and
build-offline.xml
, that correspond to the two
approaches to collecting coverage. Although it would have been possible to
keep everything in a single file, using distinct files allows for more
clarity.
EMMA ANT tasks can be deployed in any of the many ways available
for custom ANT taskdefs. This tutorial assumes that you have an EMMA
distribution directory that contains both emma.jar
and
emma_ant.jar
. The latter archive is what contains EMMA
taskdefs, however, both archives need to be visible to ANT. The easiest way
to accomplish this is with the following definitions in your
build.xml
:
<!-- directory that contains emma.jar and emma_ant.jar: --> <property name="emma.dir" value="${basedir}/../lib" /> <path id="emma.lib" > <pathelement location="${emma.dir}/emma.jar" /> <pathelement location="${emma.dir}/emma_ant.jar" /> </path> <taskdef resource="emma_ant.properties" classpathref="emma.lib" />