Marc R. Hoffmann | f7d1752 | 2009-08-07 11:21:23 +0000 | [diff] [blame] | 1 | <?xml version="1.0" encoding="ISO-8859-1" ?>
|
| 2 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
| 3 | <html xmlns="http://www.w3.org/1999/xhtml" lang="en">
|
| 4 | <head>
|
| 5 | <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
|
| 6 | <link rel="stylesheet" href=".resources/doc.css" charset="ISO-8859-1" type="text/css" />
|
Marc R. Hoffmann | a760f32 | 2010-03-10 22:23:52 +0000 | [diff] [blame] | 7 | <link rel="stylesheet" href="../coverage/.resources/prettify.css" charset="ISO-8859-1" type="text/css" />
|
Marc R. Hoffmann | d7d2f75 | 2010-05-06 21:12:31 +0000 | [diff] [blame] | 8 | <link rel="shortcut icon" href=".resources/report.gif" type="image/gif" />
|
Marc R. Hoffmann | a760f32 | 2010-03-10 22:23:52 +0000 | [diff] [blame] | 9 | <script type="text/javascript" src="../coverage/.resources/prettify.js"></script>
|
Marc R. Hoffmann | f7d1752 | 2009-08-07 11:21:23 +0000 | [diff] [blame] | 10 | <title>JaCoCo - Ant Tasks</title>
|
| 11 | </head>
|
Marc R. Hoffmann | a760f32 | 2010-03-10 22:23:52 +0000 | [diff] [blame] | 12 | <body onload="prettyPrint()">
|
Marc R. Hoffmann | f7d1752 | 2009-08-07 11:21:23 +0000 | [diff] [blame] | 13 |
|
| 14 | <div class="breadcrumb">
|
Marc R. Hoffmann | d7d2f75 | 2010-05-06 21:12:31 +0000 | [diff] [blame] | 15 | <a href="../index.html" class="el_report">JaCoCo</a> >
|
Marc R. Hoffmann | f7d1752 | 2009-08-07 11:21:23 +0000 | [diff] [blame] | 16 | <a href="index.html" class="el_group">Documentation</a> >
|
| 17 | <span class="el_source">Ant Tasks</span>
|
| 18 | </div>
|
Marc R. Hoffmann | 17be269 | 2010-02-02 05:44:47 +0000 | [diff] [blame] | 19 | <div id="content">
|
Marc R. Hoffmann | f7d1752 | 2009-08-07 11:21:23 +0000 | [diff] [blame] | 20 |
|
| 21 | <h1>Ant Tasks</h1>
|
| 22 |
|
| 23 | <p>
|
| 24 | JaCoCo comes with Ant tasks to launch Java programs with execution recording
|
Marc R. Hoffmann | 6fd10ff | 2010-06-02 21:42:25 +0000 | [diff] [blame] | 25 | and for creating coverage reports from the recorded data. Execution data can
|
| 26 | be collected and managed with the tasks
|
| 27 | <a href="#coverage"><code>coverage</code></a>,
|
| 28 | <a href="#agent"><code>agent</code></a>,
|
| 29 | <a href="#dump"><code>dump</code></a> and
|
| 30 | <a href="#merge"><code>merge</code></a>. Reports in different formats are
|
| 31 | creates with the <a href="#report"><code>report</code></a> task.
|
| 32 | </p>
|
| 33 |
|
Marc R. Hoffmann | c5d6e80 | 2010-07-02 19:34:16 +0000 | [diff] [blame] | 34 | <p class="hint">
|
| 35 | If you want to have line number information included in the coverage reports
|
| 36 | or you want source code highlighting the class files of the test target must
|
| 37 | be compiled with debug information.
|
| 38 | </p>
|
| 39 |
|
Marc R. Hoffmann | 6fd10ff | 2010-06-02 21:42:25 +0000 | [diff] [blame] | 40 | <h2>Example</h2>
|
| 41 |
|
| 42 | <p>
|
| 43 | The JaCoCo distribution contains a simple example how code coverage can be
|
| 44 | added to a Ant based build. The
|
| 45 | <a href="examples/ant/build.xml">build script</a> compiles Java sources, runs
|
| 46 | the test program and creates a coverage report. The complete example is
|
| 47 | located in the <code>./doc/examples/ant</code> folder of the distribution.
|
| 48 | </p>
|
| 49 |
|
| 50 |
|
| 51 | <h2>Prerequisites</h2>
|
| 52 |
|
| 53 | <p>
|
| 54 | The JaCoCo Ant tasks require
|
Marc R. Hoffmann | b8a7746 | 2009-08-21 14:53:50 +0000 | [diff] [blame] | 55 | </p>
|
| 56 |
|
| 57 | <ul>
|
| 58 | <li>Ant 1.7.0 or higher and</li>
|
| 59 | <li>Java 1.5 or higher (for both, the Ant runner and the test executor).</li>
|
| 60 | </ul>
|
| 61 |
|
| 62 |
|
Marc R. Hoffmann | 57f9ab4 | 2009-08-24 10:52:42 +0000 | [diff] [blame] | 63 | <p>All tasks are defined in <code>jacocoant.jar</code> (which is part of the
|
| 64 | distribution) and can be included in your Ant scripts with the usual
|
| 65 | <code>taskdef</code> declaration:
|
Marc R. Hoffmann | f7d1752 | 2009-08-07 11:21:23 +0000 | [diff] [blame] | 66 | </p>
|
| 67 |
|
Marc R. Hoffmann | 0fd9c83 | 2011-03-16 20:42:40 +0000 | [diff] [blame] | 68 | <pre class="source lang-xml linenums">
|
| 69 | <project name="Example" xmlns:jacoco="antlib:org.jacoco.ant">
|
| 70 |
|
| 71 | <taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml">
|
| 72 | <classpath path="<i>path_to_jacoco</i>/lib/jacocoant.jar"/>
|
| 73 | </taskdef>
|
| 74 |
|
| 75 | ...
|
| 76 |
|
| 77 | </project>
|
Marc R. Hoffmann | f7d1752 | 2009-08-07 11:21:23 +0000 | [diff] [blame] | 78 | </pre>
|
| 79 |
|
| 80 | <p>
|
Marc R. Hoffmann | db3e7d0 | 2009-08-12 10:57:39 +0000 | [diff] [blame] | 81 | Alternatively you might also place the <code>jacocoant.jar</code> in your
|
| 82 | Ant <code><i>ANT_HOME</i>/lib</code> folder. If you use the name space URI
|
| 83 | <code>antlib:org.jacoco.ant</code> for JaCoCo tasks Ant will find them
|
Marc R. Hoffmann | 5039bac | 2011-11-10 21:45:54 +0000 | [diff] [blame] | 84 | automatically without the <code>taskdef</code> declaration above.
|
| 85 | </p>
|
| 86 |
|
| 87 | <p class="hint">
|
| 88 | Declaring a XML namespace for JaCoCo tasks is optional but always recommended
|
| 89 | if you mix tasks from different libraries. All subsequent examples use the
|
| 90 | <code>jacoco</code> prefix declared above. If you don't declare a separate
|
| 91 | namespace the <code>jacoco</code> prefix must be removed from the following
|
| 92 | examples.
|
Marc R. Hoffmann | f7d1752 | 2009-08-07 11:21:23 +0000 | [diff] [blame] | 93 | </p>
|
| 94 |
|
Brock Janiczak | d267c57 | 2010-01-28 09:53:54 +0000 | [diff] [blame] | 95 | <h2><a name="coverage">Task <code>coverage</code></a></h2>
|
Marc R. Hoffmann | f7d1752 | 2009-08-07 11:21:23 +0000 | [diff] [blame] | 96 |
|
| 97 | <p>
|
Evgeny Mandrikov | 71b5f6e | 2011-02-19 22:55:47 +0000 | [diff] [blame] | 98 | The standard Ant tasks to launch Java programs are <code>java</code>, <code>junit</code> and
|
| 99 | <code>testng</code>. To add code coverage recording to these tasks they can
|
Marc R. Hoffmann | f7d1752 | 2009-08-07 11:21:23 +0000 | [diff] [blame] | 100 | simply be wrapped with the <code>coverage</code> task as shown in the
|
| 101 | following examples:
|
| 102 | </p>
|
| 103 |
|
Marc R. Hoffmann | 0fd9c83 | 2011-03-16 20:42:40 +0000 | [diff] [blame] | 104 | <pre class="source lang-xml linenums">
|
| 105 | <jacoco:coverage>
|
| 106 | <java classname="org.jacoco.examples.HelloJaCoCo" fork="true">
|
| 107 | <classpath>
|
| 108 | <pathelement location="./bin"/>
|
| 109 | </classpath>
|
| 110 | </java>
|
| 111 | </jacoco:coverage>
|
| 112 |
|
| 113 |
|
| 114 | <jacoco:coverage>
|
| 115 | <junit fork="true" forkmode="once">
|
| 116 | <test name="org.jacoco.examples.HelloJaCoCoTest"/>
|
| 117 | <classpath>
|
| 118 | <pathelement location="./bin"/>
|
| 119 | </classpath>
|
| 120 | </junit>
|
| 121 | </jacoco:coverage>
|
Marc R. Hoffmann | f7d1752 | 2009-08-07 11:21:23 +0000 | [diff] [blame] | 122 | </pre>
|
| 123 |
|
| 124 | <p>
|
Radek Liba | ad5fbc9 | 2009-10-26 13:26:53 +0000 | [diff] [blame] | 125 | Resulting coverage information is collected during execution and written
|
| 126 | to a file when the process terminates. Note the <code>fork</code> attribute
|
| 127 | above in the wrapped <code>java</code> task.
|
Marc R. Hoffmann | f7d1752 | 2009-08-07 11:21:23 +0000 | [diff] [blame] | 128 | </p>
|
| 129 |
|
| 130 | <p class="hint">
|
| 131 | The nested task always has to declare <code>fork="true"</code>, otherwise the
|
| 132 | <code>coverage</code> task can't record coverage information and will fail.
|
| 133 | In addition the <code>junit</code> task should declare
|
| 134 | <code>forkmode="once"</code> to avoid starting a new JVM for every single test
|
| 135 | case and decreasing execution performance dramatically (unless this is
|
| 136 | required by the nature of the test cases).
|
| 137 | </p>
|
| 138 |
|
| 139 | <p>
|
| 140 | The coverage task must wrap exactly one task. While it typically works without
|
| 141 | any configuration, the behavior can be adjusted with some optional attributes:
|
| 142 | </p>
|
| 143 |
|
| 144 | <table class="coverage">
|
| 145 | <thead>
|
| 146 | <tr>
|
| 147 | <td>Attribute</td>
|
| 148 | <td>Description</td>
|
| 149 | <td>Default</td>
|
| 150 | </tr>
|
| 151 | </thead>
|
| 152 | <tbody>
|
| 153 | <tr>
|
Brock Janiczak | d267c57 | 2010-01-28 09:53:54 +0000 | [diff] [blame] | 154 | <td><code>enabled</code></td>
|
| 155 | <td>If set to <code>true</code> coverage data will be collected for the contained task.</td>
|
| 156 | <td><code>true</code></td>
|
| 157 | </tr>
|
Marc R. Hoffmann | e3ef2f3 | 2010-01-28 18:17:46 +0000 | [diff] [blame] | 158 | <tr>
|
Brock Janiczak | 003d47c | 2010-01-15 00:45:17 +0000 | [diff] [blame] | 159 | <td><code>destfile</code></td>
|
Marc R. Hoffmann | f7d1752 | 2009-08-07 11:21:23 +0000 | [diff] [blame] | 160 | <td>Path to the output file for execution data.</td>
|
| 161 | <td><code>jacoco.exec</code></td>
|
| 162 | </tr>
|
| 163 | <tr>
|
Brock Janiczak | 003d47c | 2010-01-15 00:45:17 +0000 | [diff] [blame] | 164 | <td><code>append</code></td>
|
Marc R. Hoffmann | f7d1752 | 2009-08-07 11:21:23 +0000 | [diff] [blame] | 165 | <td>If set to <code>true</code> and the execution data file already
|
Brock Janiczak | 003d47c | 2010-01-15 00:45:17 +0000 | [diff] [blame] | 166 | exists, coverage data is appended to the existing file. If set to
|
Marc R. Hoffmann | f7d1752 | 2009-08-07 11:21:23 +0000 | [diff] [blame] | 167 | <code>false</code>, an existing execution data file will be replaced.
|
| 168 | </td>
|
| 169 | <td><code>true</code></td>
|
| 170 | </tr>
|
| 171 | <tr>
|
Marc R. Hoffmann | cf5345f | 2009-09-10 15:01:24 +0000 | [diff] [blame] | 172 | <td><code>includes</code></td>
|
Radek Liba | ad5fbc9 | 2009-10-26 13:26:53 +0000 | [diff] [blame] | 173 | <td>A list of class names that should be included in execution analysis.
|
Evgeny Mandrikov | bab5da4 | 2011-02-20 21:43:33 +0000 | [diff] [blame] | 174 | The list entries are separated by a colon (<code>:</code>) and
|
Marc R. Hoffmann | cf5345f | 2009-09-10 15:01:24 +0000 | [diff] [blame] | 175 | may use wildcard characters (<code>*</code> and <code>?</code>).
|
| 176 | Except for performance optimization or technical corner cases this
|
| 177 | option is normally not required.
|
| 178 | </td>
|
| 179 | <td><code>*</code> (all classes)</td>
|
| 180 | </tr>
|
| 181 | <tr>
|
| 182 | <td><code>excludes</code></td>
|
| 183 | <td>A list of class names that should be excluded from execution analysis.
|
Evgeny Mandrikov | bab5da4 | 2011-02-20 21:43:33 +0000 | [diff] [blame] | 184 | The list entries are separated by a colon (<code>:</code>) and
|
Marc R. Hoffmann | cf5345f | 2009-09-10 15:01:24 +0000 | [diff] [blame] | 185 | may use wildcard characters (<code>*</code> and <code>?</code>).
|
| 186 | Except for performance optimization or technical corner cases this
|
| 187 | option is normally not required.
|
| 188 | </td>
|
| 189 | <td><i>empty</i> (no excluded classes)</td>
|
| 190 | </tr>
|
| 191 | <tr>
|
Marc R. Hoffmann | f7d1752 | 2009-08-07 11:21:23 +0000 | [diff] [blame] | 192 | <td><code>exclclassloader</code></td>
|
Marc R. Hoffmann | 2a6b5bf | 2009-08-11 12:54:36 +0000 | [diff] [blame] | 193 | <td>A list of class loader names, that should be excluded from execution
|
Evgeny Mandrikov | bab5da4 | 2011-02-20 21:43:33 +0000 | [diff] [blame] | 194 | analysis. The list entries are separated by a colon
|
| 195 | (<code>:</code>) and may use wildcard characters (<code>*</code> and
|
Marc R. Hoffmann | 2a6b5bf | 2009-08-11 12:54:36 +0000 | [diff] [blame] | 196 | <code>?</code>). This option might be required in case of special
|
Marc R. Hoffmann | 57f9ab4 | 2009-08-24 10:52:42 +0000 | [diff] [blame] | 197 | frameworks that conflict with JaCoCo code instrumentation, in
|
| 198 | particular class loaders that do not have access to the Java runtime
|
| 199 | classes.
|
Marc R. Hoffmann | f7d1752 | 2009-08-07 11:21:23 +0000 | [diff] [blame] | 200 | </td>
|
| 201 | <td><code>sun.reflect.DelegatingClassLoader</code></td>
|
| 202 | </tr>
|
Brock Janiczak | f2d6f88 | 2010-05-04 06:47:40 +0000 | [diff] [blame] | 203 | <tr>
|
Marc R. Hoffmann | adfa118 | 2010-05-05 12:59:42 +0000 | [diff] [blame] | 204 | <td><code>sessionid</code></td>
|
| 205 | <td>A session identifier that is written with the execution data. Without
|
| 206 | this parameter a random identifier is created by the agent.
|
| 207 | </td>
|
| 208 | <td><i>auto-generated</i></td>
|
| 209 | </tr>
|
| 210 | <tr>
|
Brock Janiczak | f2d6f88 | 2010-05-04 06:47:40 +0000 | [diff] [blame] | 211 | <td><code>dumponexit</code></td>
|
Marc R. Hoffmann | adfa118 | 2010-05-05 12:59:42 +0000 | [diff] [blame] | 212 | <td>If set to <code>true</code> coverage data will be written on VM
|
| 213 | shutdown.
|
| 214 | </td>
|
Brock Janiczak | f2d6f88 | 2010-05-04 06:47:40 +0000 | [diff] [blame] | 215 | <td><code>true</code></td>
|
| 216 | </tr>
|
Marc R. Hoffmann | 4c3512a | 2010-05-12 08:50:23 +0000 | [diff] [blame] | 217 | <tr>
|
| 218 | <td><code>output</code></td>
|
| 219 | <td>Output method to use for writing coverage data. Valid options are:
|
| 220 | <ul>
|
| 221 | <li><code>file</code>: At VM termination execution data is written to
|
Evgeny Mandrikov | 0d5cda1 | 2011-06-24 20:33:43 +0000 | [diff] [blame] | 222 | the file specified in the <code>destfile</code> attribute.</li>
|
Marc R. Hoffmann | 4c3512a | 2010-05-12 08:50:23 +0000 | [diff] [blame] | 223 | <li><code>tcpserver</code>: The agent listens for incoming connections
|
| 224 | on the TCP port specified by the <code>address</code> and
|
| 225 | <code>port</code> attribute. Execution data is written to this
|
| 226 | TCP connection.</li>
|
| 227 | <li><code>tcpclient</code>: At startup the agent connects to the TCP
|
| 228 | port specified by the <code>address</code> and <code>port</code>
|
| 229 | attribute. Execution data is written to this TCP connection.</li>
|
Marc R. Hoffmann | c065868 | 2011-06-20 06:01:37 +0000 | [diff] [blame] | 230 | <li><code>mbean</code>: The agent registers an JMX MBean under the
|
| 231 | name <code>org.jacoco:type=Runtime</code>.</li>
|
Marc R. Hoffmann | 4c3512a | 2010-05-12 08:50:23 +0000 | [diff] [blame] | 232 | </ul>
|
| 233 | </td>
|
| 234 | <td><code>file</code></td>
|
| 235 | </tr>
|
| 236 | <tr>
|
| 237 | <td><code>address</code></td>
|
| 238 | <td>IP address or hostname to bind to when the output method is
|
| 239 | <code>tcpserver</code> or connect to when the output method is
|
Marc R. Hoffmann | 1cf157a | 2010-06-04 05:54:48 +0000 | [diff] [blame] | 240 | <code>tcpclient</code>. In <code>tcpserver</code> mode the value
|
| 241 | "<code>*</code>" causes the agent to accept connections on any local
|
| 242 | address.
|
Marc R. Hoffmann | 4c3512a | 2010-05-12 08:50:23 +0000 | [diff] [blame] | 243 | </td>
|
Marc R. Hoffmann | 1cf157a | 2010-06-04 05:54:48 +0000 | [diff] [blame] | 244 | <td><i>loopback interface</i></td>
|
Marc R. Hoffmann | 4c3512a | 2010-05-12 08:50:23 +0000 | [diff] [blame] | 245 | </tr>
|
| 246 | <tr>
|
| 247 | <td><code>port</code></td>
|
| 248 | <td>Port to bind to when the output method is <code>tcpserver</code> or
|
| 249 | connect to when the output method is <code>tcpclient</code>. In
|
| 250 | <code>tcpserver</code> mode the port must be available, which means
|
| 251 | that if multiple JaCoCo agents should run on the same machine,
|
| 252 | different ports have to be specified.
|
| 253 | </td>
|
| 254 | <td><code>6300</code></td>
|
| 255 | </tr>
|
Marc R. Hoffmann | f7d1752 | 2009-08-07 11:21:23 +0000 | [diff] [blame] | 256 | </tbody>
|
| 257 | </table>
|
| 258 |
|
| 259 |
|
Brock Janiczak | d267c57 | 2010-01-28 09:53:54 +0000 | [diff] [blame] | 260 | <h2><a name="agent">Task <code>agent</code></a></h2>
|
Marc R. Hoffmann | f7d1752 | 2009-08-07 11:21:23 +0000 | [diff] [blame] | 261 |
|
Marc R. Hoffmann | d519add | 2009-08-11 11:09:29 +0000 | [diff] [blame] | 262 | <p>
|
| 263 | If the <code>coverage</code> task is not suitable for your launch target, you
|
Marc R. Hoffmann | 6fd10ff | 2010-06-02 21:42:25 +0000 | [diff] [blame] | 264 | might alternatively use the <code>agent</code> task to create the
|
| 265 | <a href="agent.html">Java agent</a> parameter. The following example defines a
|
| 266 | Ant property with the name <code>agentvmparam</code> that can be directly used
|
| 267 | as a Java VM parameter:
|
Marc R. Hoffmann | d519add | 2009-08-11 11:09:29 +0000 | [diff] [blame] | 268 | </p>
|
| 269 |
|
Marc R. Hoffmann | 0fd9c83 | 2011-03-16 20:42:40 +0000 | [diff] [blame] | 270 | <pre class="source lang-xml linenums">
|
| 271 | <jacoco:agent property="agentvmparam"/>
|
Marc R. Hoffmann | d519add | 2009-08-11 11:09:29 +0000 | [diff] [blame] | 272 | </pre>
|
| 273 |
|
| 274 | <p>
|
| 275 | This task has the same attributes as the <code>coverage</code> task plus an
|
| 276 | additional property to specify the target property name:
|
| 277 | </p>
|
| 278 |
|
| 279 | <table class="coverage">
|
| 280 | <thead>
|
| 281 | <tr>
|
| 282 | <td>Attribute</td>
|
| 283 | <td>Description</td>
|
| 284 | <td>Default</td>
|
| 285 | </tr>
|
| 286 | </thead>
|
| 287 | <tbody>
|
| 288 | <tr>
|
Brock Janiczak | d267c57 | 2010-01-28 09:53:54 +0000 | [diff] [blame] | 289 | <td><code>enabled</code></td>
|
| 290 | <td>When this variable is set to <code>false</code> the value of <code>property</code> will be set to an empty string, effectively
|
Marc R. Hoffmann | e3ef2f3 | 2010-01-28 18:17:46 +0000 | [diff] [blame] | 291 | disabling coverage instrumentation for any tasks that used the value.</td>
|
Brock Janiczak | d267c57 | 2010-01-28 09:53:54 +0000 | [diff] [blame] | 292 | <td><code>true</code></td>
|
| 293 | </tr>
|
| 294 | <tr>
|
Marc R. Hoffmann | d519add | 2009-08-11 11:09:29 +0000 | [diff] [blame] | 295 | <td><code>property</code></td>
|
| 296 | <td>Name of the Ant property to set.</td>
|
| 297 | <td><i>none (required)</i></td>
|
| 298 | </tr>
|
Marc R. Hoffmann | 2bb6fca | 2009-08-13 14:04:21 +0000 | [diff] [blame] | 299 | <tr>
|
| 300 | <td colspan="3"><i>All attributes of the <code>coverage</code> task.</i></td>
|
| 301 | </tr>
|
Marc R. Hoffmann | d519add | 2009-08-11 11:09:29 +0000 | [diff] [blame] | 302 | </tbody>
|
| 303 | </table>
|
| 304 |
|
Brock Janiczak | 74c1659 | 2010-01-29 21:34:14 +0000 | [diff] [blame] | 305 |
|
Marc R. Hoffmann | 7c77516 | 2010-05-27 16:43:34 +0000 | [diff] [blame] | 306 | <h2><a name="dump">Task <code>dump</code></a></h2>
|
| 307 |
|
| 308 | <p>
|
| 309 | This task allows to remotely collect execution data from another JVM without
|
| 310 | stopping it. For example:
|
| 311 | </p>
|
| 312 |
|
Marc R. Hoffmann | 0fd9c83 | 2011-03-16 20:42:40 +0000 | [diff] [blame] | 313 | <pre class="source lang-xml linenums">
|
| 314 | <jacoco:dump address="server.example.com" reset="true" destfile="remote.exec"/>
|
Marc R. Hoffmann | 7c77516 | 2010-05-27 16:43:34 +0000 | [diff] [blame] | 315 | </pre>
|
| 316 |
|
| 317 | <p>
|
| 318 | Remote dumps are usefull for long running Java processes like application
|
| 319 | servers.
|
| 320 | </p>
|
| 321 |
|
| 322 | <p class="hint">
|
Marc R. Hoffmann | 6fd10ff | 2010-06-02 21:42:25 +0000 | [diff] [blame] | 323 | The target JVM needs to have a <a href="agent.html">JaCoCo agent</a>
|
| 324 | configured with <code>output</code> mode <code>tcpserver</code>. See
|
Marc R. Hoffmann | 7c77516 | 2010-05-27 16:43:34 +0000 | [diff] [blame] | 325 | <a href="#coverage"><code>coverage</code></a> and
|
| 326 | <a href="#agent"><code>agent</code></a> tasks above.
|
| 327 | </p>
|
| 328 |
|
| 329 | <p>
|
| 330 | The <code>dump</code> task has the following attributes:
|
| 331 | </p>
|
| 332 |
|
| 333 | <table class="coverage">
|
| 334 | <thead>
|
| 335 | <tr>
|
| 336 | <td>Attribute</td>
|
| 337 | <td>Description</td>
|
| 338 | <td>Default</td>
|
| 339 | </tr>
|
| 340 | </thead>
|
| 341 | <tbody>
|
| 342 | <tr>
|
| 343 | <td><code>address</code></td>
|
| 344 | <td>Target IP address or DNS name.</td>
|
| 345 | <td><code>localhost</code></td>
|
| 346 | </tr>
|
| 347 | <tr>
|
| 348 | <td><code>port</code></td>
|
| 349 | <td>Target TCP port.</td>
|
| 350 | <td><code>6300</code></td>
|
| 351 | </tr>
|
| 352 | <tr>
|
| 353 | <td><code>dump</code></td>
|
| 354 | <td>Flag whether execution data should be dumped.</td>
|
| 355 | <td><code>true</code></td>
|
| 356 | </tr>
|
| 357 | <tr>
|
| 358 | <td><code>reset</code></td>
|
| 359 | <td>Flag whether execution data should be reset in the target agent after
|
| 360 | the dump.</td>
|
| 361 | <td><code>false</code></td>
|
| 362 | </tr>
|
| 363 | <tr>
|
| 364 | <td><code>destfile</code></td>
|
| 365 | <td>File location to write the collected execution data to.</td>
|
| 366 | <td><i>none (required if dump=true)</i></td>
|
| 367 | </tr>
|
| 368 | <tr>
|
| 369 | <td><code>append</code></td>
|
| 370 | <td>If set to <code>true</code> and the execution data file already
|
| 371 | exists, coverage data is appended to the existing file. If set to
|
| 372 | <code>false</code>, an existing execution data file will be replaced.
|
| 373 | </td>
|
| 374 | <td><code>true</code></td>
|
| 375 | </tr>
|
| 376 | </tbody>
|
| 377 | </table>
|
| 378 |
|
| 379 |
|
Brock Janiczak | 74c1659 | 2010-01-29 21:34:14 +0000 | [diff] [blame] | 380 | <h2><a name="merge">Task <code>merge</code></a></h2>
|
| 381 |
|
| 382 | <p>
|
| 383 | This task can be used to merge the execution data from multiple test runs
|
| 384 | into a single data store.
|
| 385 | </p>
|
| 386 |
|
Marc R. Hoffmann | 0fd9c83 | 2011-03-16 20:42:40 +0000 | [diff] [blame] | 387 | <pre class="source lang-xml linenums">
|
| 388 | <jacoco:merge destfile="merged.exec">
|
| 389 | <fileset dir="executionData" includes="*.exec"/>
|
| 390 | </jacoco:merge>
|
Brock Janiczak | 74c1659 | 2010-01-29 21:34:14 +0000 | [diff] [blame] | 391 | </pre>
|
| 392 |
|
| 393 | <p>
|
| 394 | The task definition can contain any number of resource collection types and
|
| 395 | has the following mandatory attribute:
|
| 396 | </p>
|
| 397 |
|
| 398 | <table class="coverage">
|
| 399 | <thead>
|
| 400 | <tr>
|
| 401 | <td>Attribute</td>
|
| 402 | <td>Description</td>
|
| 403 | <td>Default</td>
|
| 404 | </tr>
|
| 405 | </thead>
|
| 406 | <tbody>
|
| 407 | <tr>
|
| 408 | <td><code>destfile</code></td>
|
Marc R. Hoffmann | 7c77516 | 2010-05-27 16:43:34 +0000 | [diff] [blame] | 409 | <td>File location to write the merged execution data to.</td>
|
Brock Janiczak | 74c1659 | 2010-01-29 21:34:14 +0000 | [diff] [blame] | 410 | <td><i>none (required)</i></td>
|
| 411 | </tr>
|
| 412 | </tbody>
|
| 413 | </table>
|
| 414 |
|
| 415 |
|
Brock Janiczak | d267c57 | 2010-01-28 09:53:54 +0000 | [diff] [blame] | 416 | <h2><a name="report">Task <code>report</code></a></h2>
|
Marc R. Hoffmann | f7d1752 | 2009-08-07 11:21:23 +0000 | [diff] [blame] | 417 |
|
Marc R. Hoffmann | 2bb6fca | 2009-08-13 14:04:21 +0000 | [diff] [blame] | 418 | <p>
|
| 419 | Finally different reports can be created with the <code>report</code> task.
|
| 420 | A report task declaration consists of different sections, two specify the
|
| 421 | input data, additional ones specify the output formats:
|
| 422 | </p>
|
| 423 |
|
Marc R. Hoffmann | 0fd9c83 | 2011-03-16 20:42:40 +0000 | [diff] [blame] | 424 | <pre class="source lang-xml linenums">
|
| 425 | <jacoco:report>
|
| 426 |
|
| 427 | <executiondata>
|
| 428 | <file file="jacoco.exec"/>
|
| 429 | </executiondata>
|
| 430 |
|
| 431 | <structure name="Example Project">
|
| 432 | <classfiles>
|
| 433 | <fileset dir="classes"/>
|
| 434 | </classfiles>
|
| 435 | <sourcefiles encoding="UTF-8">
|
| 436 | <fileset dir="src"/>
|
| 437 | </sourcefiles>
|
| 438 | </structure>
|
| 439 |
|
| 440 | <html destdir="report"/>
|
| 441 |
|
| 442 | </jacoco:report>
|
Marc R. Hoffmann | 2bb6fca | 2009-08-13 14:04:21 +0000 | [diff] [blame] | 443 | </pre>
|
| 444 |
|
| 445 | <p>
|
| 446 | As you can see from the example above the <code>report</code> task is based
|
| 447 | on several nested elements:
|
| 448 | </p>
|
| 449 |
|
| 450 | <h3>Element <code>executiondata</code></h3>
|
| 451 |
|
| 452 | <p>
|
| 453 | Within this element Ant resources and resource collections can be specified,
|
| 454 | that represent JaCoCo execution data files. If more than one execution data
|
| 455 | file is specified, execution data is combined. A particular piece of code is
|
Radek Liba | ad5fbc9 | 2009-10-26 13:26:53 +0000 | [diff] [blame] | 456 | considered executed when it is marked as such in any of the input files.
|
Marc R. Hoffmann | 2bb6fca | 2009-08-13 14:04:21 +0000 | [diff] [blame] | 457 | </p>
|
| 458 |
|
| 459 | <h3>Element <code>structure</code></h3>
|
| 460 |
|
| 461 | <p>
|
Radek Liba | ad5fbc9 | 2009-10-26 13:26:53 +0000 | [diff] [blame] | 462 | This element defines the report structure. It might contain the following
|
Marc R. Hoffmann | 2bb6fca | 2009-08-13 14:04:21 +0000 | [diff] [blame] | 463 | nested elements:
|
| 464 | </p>
|
| 465 |
|
| 466 | <ul>
|
| 467 | <li><code>classfiles</code>: Container element for Ant resources and resource
|
Marc R. Hoffmann | ff7cd3a | 2010-04-06 08:54:29 +0000 | [diff] [blame] | 468 | collections that can specify Java class files, ZIP archive files (jar, war,
|
| 469 | ear etc.) or folders containing class files. Archives and folders are
|
| 470 | searched recursively for class files.</li>
|
Marc R. Hoffmann | 2bb6fca | 2009-08-13 14:04:21 +0000 | [diff] [blame] | 471 | <li><code>sourcefiles</code>: Optional container element for Ant resources and
|
Marc R. Hoffmann | 5625ff6 | 2011-03-27 12:53:52 +0000 | [diff] [blame] | 472 | resource collections that specify corresponding source files. If source
|
| 473 | files are specified, some report formats include highlighted source code.</li>
|
Marc R. Hoffmann | 2bb6fca | 2009-08-13 14:04:21 +0000 | [diff] [blame] | 474 | </ul>
|
| 475 |
|
| 476 | <p>
|
Marc R. Hoffmann | 5625ff6 | 2011-03-27 12:53:52 +0000 | [diff] [blame] | 477 | The <code>sourcefiles</code> element has these optional attributes:
|
| 478 | </p>
|
| 479 |
|
| 480 | <table class="coverage">
|
| 481 | <thead>
|
| 482 | <tr>
|
| 483 | <td>Attribute</td>
|
| 484 | <td>Description</td>
|
| 485 | <td>Default</td>
|
| 486 | </tr>
|
| 487 | </thead>
|
| 488 | <tbody>
|
| 489 | <tr>
|
| 490 | <td><code>encoding</code></td>
|
| 491 | <td>Character encoding of the source files.</td>
|
| 492 | <td>Platform default encoding</td>
|
| 493 | </tr>
|
| 494 | <tr>
|
| 495 | <td><code>tabwidth</code></td>
|
| 496 | <td>Number of whitespace characters that represent a tab character.</td>
|
| 497 | <td>4 characters</td>
|
| 498 | </tr>
|
| 499 | </tbody>
|
| 500 | </table>
|
| 501 |
|
| 502 | <p>
|
Marc R. Hoffmann | 1f01f86 | 2011-01-12 21:58:34 +0000 | [diff] [blame] | 503 | Note that the <code>classfiles</code> and <code>sourcefiles</code> elements
|
| 504 | accept any
|
| 505 | <a href="http://ant.apache.org/manual/Types/resources.html#collection">Ant
|
| 506 | resource collection</a>. Therefore also filtering the class file set is
|
| 507 | possible and allows to narrow the scope of the report, for example:
|
Marc R. Hoffmann | 2bb6fca | 2009-08-13 14:04:21 +0000 | [diff] [blame] | 508 | </p>
|
| 509 |
|
Marc R. Hoffmann | 0fd9c83 | 2011-03-16 20:42:40 +0000 | [diff] [blame] | 510 | <pre class="source lang-xml linenums">
|
| 511 | <classfiles>
|
| 512 | <fileset dir="classes">
|
| 513 | <include name="org/jacoco/examples/important/**/*.class"/>
|
| 514 | </fileset>
|
| 515 | </classfiles>
|
Marc R. Hoffmann | 1f01f86 | 2011-01-12 21:58:34 +0000 | [diff] [blame] | 516 | </pre>
|
| 517 |
|
Marc R. Hoffmann | 7232b74 | 2011-03-07 21:54:08 +0000 | [diff] [blame] | 518 | <p class="hint">
|
| 519 | <b>Performance Warning:</b> Although it is technically possible and sometimes
|
| 520 | convenient to use Ant's <code>zipfileset</code> to specify class or source
|
| 521 | files, this resource type has poor performance characteristics and comes with
|
| 522 | an huge memory overhead especially for large scale projects.
|
| 523 | </p>
|
| 524 |
|
Marc R. Hoffmann | 1f01f86 | 2011-01-12 21:58:34 +0000 | [diff] [blame] | 525 | <p>
|
| 526 | The structure can be refined with a hierarchy of <code>group</code> elements.
|
| 527 | This way the coverage report can reflect different modules of a software
|
| 528 | project. For each group element the corresponding class and source files can
|
| 529 | be specified separately. For example:
|
| 530 | </p>
|
| 531 |
|
Marc R. Hoffmann | 0fd9c83 | 2011-03-16 20:42:40 +0000 | [diff] [blame] | 532 | <pre class="source lang-xml linenums">
|
| 533 | <structure name="Example Project">
|
| 534 | <group name="Server">
|
| 535 | <classfiles>
|
| 536 | <fileset dir="${workspace.dir}/org.jacoco.example.server/classes"/>
|
| 537 | </classfiles>
|
| 538 | <sourcefiles>
|
| 539 | <fileset dir="${workspace.dir}/org.jacoco.example.server/src"/>
|
| 540 | </sourcefiles>
|
| 541 | </group>
|
| 542 | <group name="Client">
|
| 543 | <classfiles>
|
| 544 | <fileset dir="${workspace.dir}/org.jacoco.example.client/classes"/>
|
| 545 | </classfiles>
|
| 546 | <sourcefiles>
|
| 547 | <fileset dir="${workspace.dir}/org.jacoco.example.client/src"/>
|
| 548 | </sourcefiles>
|
| 549 | </group>
|
| 550 |
|
| 551 | ...
|
| 552 |
|
| 553 | </structure>
|
Marc R. Hoffmann | 2bb6fca | 2009-08-13 14:04:21 +0000 | [diff] [blame] | 554 | </pre>
|
| 555 |
|
Marc R. Hoffmann | 722cad8 | 2010-03-09 18:22:33 +0000 | [diff] [blame] | 556 | <p>
|
| 557 | Both <code>structure</code> and <code>group</code> elements have the following
|
| 558 | mandatory attribute:
|
| 559 | </p>
|
| 560 |
|
| 561 | <table class="coverage">
|
| 562 | <thead>
|
| 563 | <tr>
|
| 564 | <td>Attribute</td>
|
| 565 | <td>Description</td>
|
| 566 | <td>Default</td>
|
| 567 | </tr>
|
| 568 | </thead>
|
| 569 | <tbody>
|
| 570 | <tr>
|
| 571 | <td><code>name</code></td>
|
| 572 | <td>Name of the structure or group.</td>
|
| 573 | <td><i>none (required)</i></td>
|
| 574 | </tr>
|
| 575 | </tbody>
|
| 576 | </table>
|
| 577 |
|
Marc R. Hoffmann | 2bb6fca | 2009-08-13 14:04:21 +0000 | [diff] [blame] | 578 | <h3>Element <code>html</code></h3>
|
| 579 |
|
| 580 | <p>
|
Marc R. Hoffmann | 81f7920 | 2010-03-12 07:36:50 +0000 | [diff] [blame] | 581 | Create a multi-page report in HTML format. The report can either be written as
|
| 582 | multiple files into a directory or compressed into a single ZIP file.
|
Marc R. Hoffmann | 2bb6fca | 2009-08-13 14:04:21 +0000 | [diff] [blame] | 583 | </p>
|
| 584 |
|
| 585 | <table class="coverage">
|
| 586 | <thead>
|
| 587 | <tr>
|
| 588 | <td>Attribute</td>
|
| 589 | <td>Description</td>
|
| 590 | <td>Default</td>
|
| 591 | </tr>
|
| 592 | </thead>
|
| 593 | <tbody>
|
| 594 | <tr>
|
| 595 | <td><code>destdir</code></td>
|
Marc R. Hoffmann | 81f7920 | 2010-03-12 07:36:50 +0000 | [diff] [blame] | 596 | <td>Directory to create the report in. Either this property or
|
| 597 | <code>destfile</code> has to be supplied.</td>
|
| 598 | <td><i>none (required)</i></td>
|
| 599 | </tr>
|
| 600 | <tr>
|
| 601 | <td><code>destfile</code></td>
|
| 602 | <td>Zip file to create the report in. Either this property or
|
| 603 | <code>destdir</code> has to be supplied.</td>
|
Marc R. Hoffmann | 2bb6fca | 2009-08-13 14:04:21 +0000 | [diff] [blame] | 604 | <td><i>none (required)</i></td>
|
| 605 | </tr>
|
Marc R. Hoffmann | 2ecbea5 | 2009-09-03 14:19:11 +0000 | [diff] [blame] | 606 | <tr>
|
| 607 | <td><code>footer</code></td>
|
| 608 | <td>Footer text for each report page.</td>
|
Marc R. Hoffmann | ae8c2a8 | 2010-10-05 16:20:10 +0000 | [diff] [blame] | 609 | <td><i>no footer</i></td>
|
Marc R. Hoffmann | 2ecbea5 | 2009-09-03 14:19:11 +0000 | [diff] [blame] | 610 | </tr>
|
Marc R. Hoffmann | 2becd33 | 2009-10-07 16:13:17 +0000 | [diff] [blame] | 611 | <tr>
|
| 612 | <td><code>encoding</code></td>
|
Marc R. Hoffmann | ae8c2a8 | 2010-10-05 16:20:10 +0000 | [diff] [blame] | 613 | <td>Character encoding of generated HTML pages.</td>
|
Marc R. Hoffmann | 2becd33 | 2009-10-07 16:13:17 +0000 | [diff] [blame] | 614 | <td><code>UTF-8</code></td>
|
| 615 | </tr>
|
Marc R. Hoffmann | ae8c2a8 | 2010-10-05 16:20:10 +0000 | [diff] [blame] | 616 | <tr>
|
| 617 | <td><code>locale</code></td>
|
| 618 | <td>Locale specified as ISO code (en, fr, jp, ...) used for number formating.</td>
|
| 619 | <td><i>platform locale</i></td>
|
| 620 | </tr>
|
Marc R. Hoffmann | 2becd33 | 2009-10-07 16:13:17 +0000 | [diff] [blame] | 621 | </tbody>
|
| 622 | </table>
|
| 623 |
|
| 624 | <h3>Element <code>xml</code></h3>
|
| 625 |
|
| 626 | <p>
|
| 627 | Create a single-file report in XML format.
|
| 628 | </p>
|
| 629 |
|
| 630 | <table class="coverage">
|
| 631 | <thead>
|
| 632 | <tr>
|
| 633 | <td>Attribute</td>
|
| 634 | <td>Description</td>
|
| 635 | <td>Default</td>
|
| 636 | </tr>
|
| 637 | </thead>
|
| 638 | <tbody>
|
| 639 | <tr>
|
Marc R. Hoffmann | 88b3f2f | 2009-10-19 16:10:35 +0000 | [diff] [blame] | 640 | <td><code>destfile</code></td>
|
| 641 | <td>Location to write the report file to.</td>
|
Marc R. Hoffmann | 2becd33 | 2009-10-07 16:13:17 +0000 | [diff] [blame] | 642 | <td><i>none (required)</i></td>
|
| 643 | </tr>
|
| 644 | <tr>
|
| 645 | <td><code>encoding</code></td>
|
| 646 | <td>Encoding of the generated XML document.</td>
|
| 647 | <td><code>UTF-8</code></td>
|
| 648 | </tr>
|
Marc R. Hoffmann | 2bb6fca | 2009-08-13 14:04:21 +0000 | [diff] [blame] | 649 | </tbody>
|
| 650 | </table>
|
| 651 |
|
| 652 | <h3>Element <code>csv</code></h3>
|
| 653 |
|
| 654 | <p>
|
Marc R. Hoffmann | 2becd33 | 2009-10-07 16:13:17 +0000 | [diff] [blame] | 655 | Create single-file report in CSV format.
|
Marc R. Hoffmann | 2bb6fca | 2009-08-13 14:04:21 +0000 | [diff] [blame] | 656 | </p>
|
| 657 |
|
| 658 | <table class="coverage">
|
| 659 | <thead>
|
| 660 | <tr>
|
| 661 | <td>Attribute</td>
|
| 662 | <td>Description</td>
|
| 663 | <td>Default</td>
|
| 664 | </tr>
|
| 665 | </thead>
|
| 666 | <tbody>
|
| 667 | <tr>
|
Marc R. Hoffmann | 88b3f2f | 2009-10-19 16:10:35 +0000 | [diff] [blame] | 668 | <td><code>destfile</code></td>
|
| 669 | <td>Location to write the report file to.</td>
|
Marc R. Hoffmann | 2bb6fca | 2009-08-13 14:04:21 +0000 | [diff] [blame] | 670 | <td><i>none (required)</i></td>
|
| 671 | </tr>
|
Marc R. Hoffmann | e17fd11 | 2009-10-19 15:27:04 +0000 | [diff] [blame] | 672 | <tr>
|
| 673 | <td><code>encoding</code></td>
|
| 674 | <td>Encoding of the generated CSV document.</td>
|
| 675 | <td><code>UTF-8</code></td>
|
| 676 | </tr>
|
Marc R. Hoffmann | 2bb6fca | 2009-08-13 14:04:21 +0000 | [diff] [blame] | 677 | </tbody>
|
| 678 | </table>
|
| 679 |
|
Marc R. Hoffmann | 17be269 | 2010-02-02 05:44:47 +0000 | [diff] [blame] | 680 | </div>
|
Marc R. Hoffmann | f7d1752 | 2009-08-07 11:21:23 +0000 | [diff] [blame] | 681 | <div class="footer">
|
Marc R. Hoffmann | b623ffb | 2010-05-06 19:48:08 +0000 | [diff] [blame] | 682 | <span class="right"><a href="@jacoco.home.url@">JaCoCo</a> @qualified.bundle.version@</span>
|
Marc R. Hoffmann | df6ff96 | 2010-04-09 15:31:22 +0000 | [diff] [blame] | 683 | <a href="license.html">Copyright</a> © @copyright.years@ Mountainminds GmbH & Co. KG and Contributors
|
Marc R. Hoffmann | f7d1752 | 2009-08-07 11:21:23 +0000 | [diff] [blame] | 684 | </div>
|
| 685 |
|
| 686 | </body>
|
| 687 | </html> |