1
<?xml version="1.0" encoding="UTF-8"?>
3
<project name="cobertura.examples.basic" default="coverage" basedir=".">
6
Cobertura - http://cobertura.sourceforge.net/
7
Copyright (C) 2003 jcoverage ltd.
8
Copyright (C) 2006 Mark Doliner <thekingant@users.sourceforge.net>
9
Cobertura is licensed under the GNU General Public License
10
Cobertura comes with ABSOLUTELY NO WARRANTY
13
<property file="build.properties" />
15
<path id="cobertura.classpath">
16
<fileset dir="${cobertura.dir}">
17
<include name="cobertura.jar" />
18
<include name="lib/**/*.jar" />
22
<taskdef classpathref="cobertura.classpath" resource="tasks.properties"/>
24
<path id="groovy.classpath">
25
<fileset dir="${groovy.dir}">
26
<include name="*.jar" />
29
<taskdef name="groovyc" classname="org.codehaus.groovy.ant.Groovyc" classpathref="groovy.classpath" />
32
<mkdir dir="${classes.dir}" />
33
<mkdir dir="${instrumented.dir}" />
34
<mkdir dir="${reports.xml.dir}" />
35
<mkdir dir="${reports.html.dir}" />
36
<mkdir dir="${coverage.xml.dir}" />
37
<mkdir dir="${coverage.html.dir}" />
40
<target name="compile" depends="init">
41
<groovyc srcdir="${src.dir}" destdir="${classes.dir}">
42
<classpath refid="cobertura.classpath" />
46
<target name="instrument" depends="init,compile">
48
Remove the coverage data file and any old instrumentation.
50
<delete file="cobertura.ser"/>
51
<delete dir="${instrumented.dir}" />
54
Instrument the application classes, writing the
55
instrumented classes into ${build.instrumented.dir}.
57
<cobertura-instrument todir="${instrumented.dir}">
59
The following line causes instrument to ignore any
60
source line containing a reference to log4j, for the
61
purposes of coverage reporting.
63
<ignore regex="org.apache.log4j.*" />
65
<fileset dir="${classes.dir}">
67
Instrument all the application classes, but
68
don't instrument the test classes.
70
<include name="**/*.class" />
71
<exclude name="**/*Test.class" />
73
</cobertura-instrument>
76
<target name="test" depends="init,compile">
77
<junit fork="yes" dir="${basedir}" failureProperty="test.failed">
79
Note the classpath order: instrumented classes are before the
80
original (uninstrumented) classes. This is important.
82
<classpath location="${instrumented.dir}" />
83
<classpath location="${classes.dir}" />
86
The instrumented classes reference classes used by the
87
Cobertura runtime, so Cobertura and its dependencies
88
must be on your classpath.
90
<classpath refid="cobertura.classpath" />
92
<classpath refid="groovy.classpath" />
94
<formatter type="xml" />
95
<test name="com.example.simple.SimpleTest" todir="${reports.xml.dir}" />
98
<junitreport todir="${reports.xml.dir}">
99
<fileset dir="${reports.xml.dir}">
100
<include name="TEST-*.xml" />
102
<report format="frames" todir="${reports.html.dir}" />
106
<target name="coverage-check">
107
<cobertura-check branchrate="34" totallinerate="100" />
110
<target name="coverage-report">
112
Generate an XML file containing the coverage data using
113
the "srcdir" attribute.
115
<cobertura-report srcdir="${src.dir}" destdir="${coverage.xml.dir}" format="xml" />
118
<target name="alternate-coverage-report">
120
Generate a series of HTML files containing the coverage
121
data in a user-readable form using nested source filesets.
123
<cobertura-report destdir="${coverage.html.dir}">
124
<fileset dir="${src.dir}">
125
<include name="**/*.groovy"/>
130
<target name="clean" description="Remove all files created by the build/test process.">
131
<delete dir="${classes.dir}" />
132
<delete dir="${instrumented.dir}" />
133
<delete dir="${reports.dir}" />
134
<delete file="cobertura.log" />
135
<delete file="cobertura.ser" />
138
<target name="coverage" depends="compile,instrument,test,coverage-report,alternate-coverage-report" description="Compile, instrument ourself, run the tests and generate JUnit and coverage reports."/>