Marc R. Hoffmann | e571f3f | 2012-05-13 12:18:02 +0000 | [diff] [blame] | 1 | <?xml version="1.0" encoding="UTF-8" ?> |
Evgeny Mandrikov | 82a92ca | 2012-01-15 20:25:48 +0000 | [diff] [blame] | 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> |
Marc R. Hoffmann | e571f3f | 2012-05-13 12:18:02 +0000 | [diff] [blame] | 5 | <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> |
Evgeny Mandrikov | 8b21298 | 2016-06-12 17:55:49 +0200 | [diff] [blame] | 6 | <link rel="stylesheet" href="resources/doc.css" charset="UTF-8" type="text/css" /> |
Evgeny Mandrikov | 28d5985 | 2016-06-11 12:41:17 +0200 | [diff] [blame] | 7 | <link rel="stylesheet" href="../coverage/jacoco-resources/prettify.css" charset="UTF-8" type="text/css" /> |
Evgeny Mandrikov | 8b21298 | 2016-06-12 17:55:49 +0200 | [diff] [blame] | 8 | <link rel="shortcut icon" href="resources/report.gif" type="image/gif" /> |
Evgeny Mandrikov | 28d5985 | 2016-06-11 12:41:17 +0200 | [diff] [blame] | 9 | <script type="text/javascript" src="../coverage/jacoco-resources/prettify.js"></script> |
Evgeny Mandrikov | 82a92ca | 2012-01-15 20:25:48 +0000 | [diff] [blame] | 10 | <title>JaCoCo - Ant Tasks</title> |
| 11 | </head> |
| 12 | <body onload="prettyPrint()"> |
| 13 | |
| 14 | <div class="breadcrumb"> |
| 15 | <a href="../index.html" class="el_report">JaCoCo</a> > |
| 16 | <a href="index.html" class="el_group">Documentation</a> > |
| 17 | <span class="el_source">Ant Tasks</span> |
| 18 | </div> |
| 19 | <div id="content"> |
| 20 | |
| 21 | <h1>Ant Tasks</h1> |
| 22 | |
| 23 | <p> |
| 24 | JaCoCo comes with Ant tasks to launch Java programs with execution recording |
| 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 |
Hemant Kumar | 02accc7 | 2016-12-13 03:44:15 +0530 | [diff] [blame] | 31 | created with the <a href="#report"><code>report</code></a> task. For |
Marc R. Hoffmann | 235a09e | 2012-12-23 15:57:16 +0100 | [diff] [blame] | 32 | <a href="offline.html">offline instrumentation</a> the task |
| 33 | <a href="#instrument"><code>instrument</code></a> can be used to prepare class |
| 34 | files. |
Evgeny Mandrikov | 82a92ca | 2012-01-15 20:25:48 +0000 | [diff] [blame] | 35 | </p> |
| 36 | |
| 37 | <p class="hint"> |
| 38 | If you want to have line number information included in the coverage reports |
| 39 | or you want source code highlighting the class files of the test target must |
| 40 | be compiled with debug information. |
| 41 | </p> |
| 42 | |
| 43 | <h2>Example</h2> |
| 44 | |
| 45 | <p> |
| 46 | The JaCoCo distribution contains a simple example how code coverage can be |
| 47 | added to a Ant based build. The |
Marc R. Hoffmann | a3aa78b | 2012-05-02 18:56:47 +0000 | [diff] [blame] | 48 | <a href="examples/build/build.xml">build script</a> compiles Java sources, |
Hemant Kumar | 02accc7 | 2016-12-13 03:44:15 +0530 | [diff] [blame] | 49 | runs an simple Java program and creates a coverage report. The complete |
Marc R. Hoffmann | 7830927 | 2012-05-02 19:25:44 +0000 | [diff] [blame] | 50 | example is located in the <code>./doc/examples/build</code> folder of the |
| 51 | distribution. |
Evgeny Mandrikov | 82a92ca | 2012-01-15 20:25:48 +0000 | [diff] [blame] | 52 | </p> |
| 53 | |
| 54 | |
| 55 | <h2>Prerequisites</h2> |
| 56 | |
| 57 | <p> |
| 58 | The JaCoCo Ant tasks require |
| 59 | </p> |
| 60 | |
| 61 | <ul> |
| 62 | <li>Ant 1.7.0 or higher and</li> |
| 63 | <li>Java 1.5 or higher (for both, the Ant runner and the test executor).</li> |
| 64 | </ul> |
| 65 | |
| 66 | |
| 67 | <p>All tasks are defined in <code>jacocoant.jar</code> (which is part of the |
| 68 | distribution) and can be included in your Ant scripts with the usual |
| 69 | <code>taskdef</code> declaration: |
| 70 | </p> |
| 71 | |
| 72 | <pre class="source lang-xml linenums"> |
| 73 | <project name="Example" xmlns:jacoco="antlib:org.jacoco.ant"> |
| 74 | |
| 75 | <taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml"> |
| 76 | <classpath path="<i>path_to_jacoco</i>/lib/jacocoant.jar"/> |
| 77 | </taskdef> |
| 78 | |
| 79 | ... |
| 80 | |
| 81 | </project> |
| 82 | </pre> |
| 83 | |
| 84 | <p> |
| 85 | Alternatively you might also place the <code>jacocoant.jar</code> in your |
| 86 | Ant <code><i>ANT_HOME</i>/lib</code> folder. If you use the name space URI |
| 87 | <code>antlib:org.jacoco.ant</code> for JaCoCo tasks Ant will find them |
| 88 | automatically without the <code>taskdef</code> declaration above. |
| 89 | </p> |
| 90 | |
| 91 | <p class="hint"> |
| 92 | Declaring a XML namespace for JaCoCo tasks is optional but always recommended |
| 93 | if you mix tasks from different libraries. All subsequent examples use the |
| 94 | <code>jacoco</code> prefix declared above. If you don't declare a separate |
| 95 | namespace the <code>jacoco</code> prefix must be removed from the following |
| 96 | examples. |
| 97 | </p> |
| 98 | |
| 99 | <h2><a name="coverage">Task <code>coverage</code></a></h2> |
| 100 | |
| 101 | <p> |
| 102 | The standard Ant tasks to launch Java programs are <code>java</code>, <code>junit</code> and |
| 103 | <code>testng</code>. To add code coverage recording to these tasks they can |
| 104 | simply be wrapped with the <code>coverage</code> task as shown in the |
| 105 | following examples: |
| 106 | </p> |
| 107 | |
| 108 | <pre class="source lang-xml linenums"> |
| 109 | <jacoco:coverage> |
| 110 | <java classname="org.jacoco.examples.HelloJaCoCo" fork="true"> |
| 111 | <classpath> |
| 112 | <pathelement location="./bin"/> |
| 113 | </classpath> |
| 114 | </java> |
| 115 | </jacoco:coverage> |
| 116 | |
| 117 | |
| 118 | <jacoco:coverage> |
| 119 | <junit fork="true" forkmode="once"> |
| 120 | <test name="org.jacoco.examples.HelloJaCoCoTest"/> |
| 121 | <classpath> |
| 122 | <pathelement location="./bin"/> |
| 123 | </classpath> |
| 124 | </junit> |
| 125 | </jacoco:coverage> |
| 126 | </pre> |
| 127 | |
| 128 | <p> |
| 129 | Resulting coverage information is collected during execution and written |
| 130 | to a file when the process terminates. Note the <code>fork</code> attribute |
| 131 | above in the wrapped <code>java</code> task. |
| 132 | </p> |
| 133 | |
| 134 | <p class="hint"> |
| 135 | The nested task always has to declare <code>fork="true"</code>, otherwise the |
| 136 | <code>coverage</code> task can't record coverage information and will fail. |
| 137 | In addition the <code>junit</code> task should declare |
| 138 | <code>forkmode="once"</code> to avoid starting a new JVM for every single test |
| 139 | case and decreasing execution performance dramatically (unless this is |
Marc R. Hoffmann | 73e36a1 | 2015-05-28 11:35:50 +0200 | [diff] [blame] | 140 | required by the nature of the test cases). Note that |
| 141 | <code>forkmode="perTest"</code> or <code>forkmode="perBatch"</code> should not |
| 142 | be combined with <code>append="false"</code> as the execution data file is |
| 143 | overwritten with the execution of every test. |
Evgeny Mandrikov | 82a92ca | 2012-01-15 20:25:48 +0000 | [diff] [blame] | 144 | </p> |
| 145 | |
| 146 | <p> |
| 147 | The coverage task must wrap exactly one task. While it typically works without |
| 148 | any configuration, the behavior can be adjusted with some optional attributes: |
| 149 | </p> |
| 150 | |
| 151 | <table class="coverage"> |
| 152 | <thead> |
| 153 | <tr> |
| 154 | <td>Attribute</td> |
| 155 | <td>Description</td> |
| 156 | <td>Default</td> |
| 157 | </tr> |
| 158 | </thead> |
| 159 | <tbody> |
| 160 | <tr> |
| 161 | <td><code>enabled</code></td> |
| 162 | <td>If set to <code>true</code> coverage data will be collected for the contained task.</td> |
| 163 | <td><code>true</code></td> |
| 164 | </tr> |
| 165 | <tr> |
| 166 | <td><code>destfile</code></td> |
| 167 | <td>Path to the output file for execution data.</td> |
| 168 | <td><code>jacoco.exec</code></td> |
| 169 | </tr> |
| 170 | <tr> |
| 171 | <td><code>append</code></td> |
| 172 | <td>If set to <code>true</code> and the execution data file already |
| 173 | exists, coverage data is appended to the existing file. If set to |
| 174 | <code>false</code>, an existing execution data file will be replaced. |
| 175 | </td> |
| 176 | <td><code>true</code></td> |
| 177 | </tr> |
| 178 | <tr> |
| 179 | <td><code>includes</code></td> |
| 180 | <td>A list of class names that should be included in execution analysis. |
| 181 | The list entries are separated by a colon (<code>:</code>) and |
| 182 | may use wildcard characters (<code>*</code> and <code>?</code>). |
| 183 | Except for performance optimization or technical corner cases this |
| 184 | option is normally not required. |
| 185 | </td> |
| 186 | <td><code>*</code> (all classes)</td> |
| 187 | </tr> |
| 188 | <tr> |
| 189 | <td><code>excludes</code></td> |
| 190 | <td>A list of class names that should be excluded from execution analysis. |
| 191 | The list entries are separated by a colon (<code>:</code>) and |
| 192 | may use wildcard characters (<code>*</code> and <code>?</code>). |
| 193 | Except for performance optimization or technical corner cases this |
| 194 | option is normally not required. |
| 195 | </td> |
| 196 | <td><i>empty</i> (no excluded classes)</td> |
| 197 | </tr> |
| 198 | <tr> |
| 199 | <td><code>exclclassloader</code></td> |
| 200 | <td>A list of class loader names, that should be excluded from execution |
| 201 | analysis. The list entries are separated by a colon |
| 202 | (<code>:</code>) and may use wildcard characters (<code>*</code> and |
| 203 | <code>?</code>). This option might be required in case of special |
| 204 | frameworks that conflict with JaCoCo code instrumentation, in |
| 205 | particular class loaders that do not have access to the Java runtime |
| 206 | classes. |
| 207 | </td> |
| 208 | <td><code>sun.reflect.DelegatingClassLoader</code></td> |
| 209 | </tr> |
| 210 | <tr> |
Marc R. Hoffmann | 1d8389b | 2014-05-20 13:44:17 +0200 | [diff] [blame] | 211 | <td><code>inclbootstrapclasses</code></td> |
Marc R. Hoffmann | 310b7d1 | 2014-05-16 20:30:20 +0200 | [diff] [blame] | 212 | <td>Specifies whether also classes from the bootstrap classloader should |
| 213 | be instrumented. Use this feature with caution, it needs heavy |
| 214 | includes/excludes tuning. |
| 215 | </td> |
| 216 | <td><code>false</code></td> |
| 217 | </tr> |
| 218 | <tr> |
Marc R. Hoffmann | 26daee4 | 2016-01-12 22:33:05 +0100 | [diff] [blame] | 219 | <td><code>inclnolocationclasses</code></td> |
| 220 | <td>Specifies whether also classes without a source location should be |
| 221 | instrumented. Normally such classes are generated at runtime e.g. by |
| 222 | mocking frameworks and are therefore excluded by default. |
| 223 | </td> |
| 224 | <td><code>false</code></td> |
| 225 | </tr> |
| 226 | <tr> |
Evgeny Mandrikov | 82a92ca | 2012-01-15 20:25:48 +0000 | [diff] [blame] | 227 | <td><code>sessionid</code></td> |
| 228 | <td>A session identifier that is written with the execution data. Without |
| 229 | this parameter a random identifier is created by the agent. |
| 230 | </td> |
| 231 | <td><i>auto-generated</i></td> |
| 232 | </tr> |
| 233 | <tr> |
| 234 | <td><code>dumponexit</code></td> |
| 235 | <td>If set to <code>true</code> coverage data will be written on VM |
| 236 | shutdown. |
| 237 | </td> |
| 238 | <td><code>true</code></td> |
| 239 | </tr> |
| 240 | <tr> |
| 241 | <td><code>output</code></td> |
| 242 | <td>Output method to use for writing coverage data. Valid options are: |
| 243 | <ul> |
| 244 | <li><code>file</code>: At VM termination execution data is written to |
| 245 | the file specified in the <code>destfile</code> attribute.</li> |
| 246 | <li><code>tcpserver</code>: The agent listens for incoming connections |
| 247 | on the TCP port specified by the <code>address</code> and |
| 248 | <code>port</code> attribute. Execution data is written to this |
| 249 | TCP connection.</li> |
| 250 | <li><code>tcpclient</code>: At startup the agent connects to the TCP |
| 251 | port specified by the <code>address</code> and <code>port</code> |
| 252 | attribute. Execution data is written to this TCP connection.</li> |
Evgeny Mandrikov | 8c614ba | 2013-01-09 16:07:13 +0100 | [diff] [blame] | 253 | <li><code>none</code>: Do not produce any output.</li> |
Evgeny Mandrikov | 82a92ca | 2012-01-15 20:25:48 +0000 | [diff] [blame] | 254 | </ul> |
| 255 | </td> |
| 256 | <td><code>file</code></td> |
| 257 | </tr> |
| 258 | <tr> |
| 259 | <td><code>address</code></td> |
| 260 | <td>IP address or hostname to bind to when the output method is |
| 261 | <code>tcpserver</code> or connect to when the output method is |
| 262 | <code>tcpclient</code>. In <code>tcpserver</code> mode the value |
| 263 | "<code>*</code>" causes the agent to accept connections on any local |
| 264 | address. |
| 265 | </td> |
| 266 | <td><i>loopback interface</i></td> |
| 267 | </tr> |
| 268 | <tr> |
| 269 | <td><code>port</code></td> |
| 270 | <td>Port to bind to when the output method is <code>tcpserver</code> or |
| 271 | connect to when the output method is <code>tcpclient</code>. In |
| 272 | <code>tcpserver</code> mode the port must be available, which means |
| 273 | that if multiple JaCoCo agents should run on the same machine, |
| 274 | different ports have to be specified. |
| 275 | </td> |
| 276 | <td><code>6300</code></td> |
| 277 | </tr> |
Marc R. Hoffmann | cf41fc1 | 2012-06-30 00:15:43 +0000 | [diff] [blame] | 278 | <tr> |
| 279 | <td><code>classdumpdir</code></td> |
| 280 | <td>Location relative to the working directory where all class files seen |
| 281 | by the agent are dumped to. This can be useful for debugging purposes |
| 282 | or in case of dynamically created classes for example when scripting |
| 283 | engines are used. |
| 284 | </td> |
| 285 | <td><i>no dumps</i></td> |
| 286 | </tr> |
Marc R. Hoffmann | e2930e7 | 2013-01-08 21:18:35 +0100 | [diff] [blame] | 287 | <tr> |
| 288 | <td><code>jmx</code></td> |
| 289 | <td>If set to <code>true</code> the agent exposes |
| 290 | <a href="./api/org/jacoco/agent/rt/IAgent.html">functionality</a> via |
| 291 | JMX under the name <code>org.jacoco:type=Runtime</code>. |
| 292 | </td> |
| 293 | <td><code>false</code></td> |
| 294 | </tr> |
Evgeny Mandrikov | 82a92ca | 2012-01-15 20:25:48 +0000 | [diff] [blame] | 295 | </tbody> |
| 296 | </table> |
| 297 | |
| 298 | |
| 299 | <h2><a name="agent">Task <code>agent</code></a></h2> |
| 300 | |
| 301 | <p> |
| 302 | If the <code>coverage</code> task is not suitable for your launch target, you |
| 303 | might alternatively use the <code>agent</code> task to create the |
| 304 | <a href="agent.html">Java agent</a> parameter. The following example defines a |
| 305 | Ant property with the name <code>agentvmparam</code> that can be directly used |
| 306 | as a Java VM parameter: |
| 307 | </p> |
| 308 | |
| 309 | <pre class="source lang-xml linenums"> |
| 310 | <jacoco:agent property="agentvmparam"/> |
| 311 | </pre> |
| 312 | |
| 313 | <p> |
| 314 | This task has the same attributes as the <code>coverage</code> task plus an |
| 315 | additional property to specify the target property name: |
| 316 | </p> |
| 317 | |
| 318 | <table class="coverage"> |
| 319 | <thead> |
| 320 | <tr> |
| 321 | <td>Attribute</td> |
| 322 | <td>Description</td> |
| 323 | <td>Default</td> |
| 324 | </tr> |
| 325 | </thead> |
| 326 | <tbody> |
| 327 | <tr> |
| 328 | <td><code>enabled</code></td> |
| 329 | <td>When this variable is set to <code>false</code> the value of <code>property</code> will be set to an empty string, effectively |
| 330 | disabling coverage instrumentation for any tasks that used the value.</td> |
| 331 | <td><code>true</code></td> |
| 332 | </tr> |
| 333 | <tr> |
| 334 | <td><code>property</code></td> |
| 335 | <td>Name of the Ant property to set.</td> |
| 336 | <td><i>none (required)</i></td> |
| 337 | </tr> |
| 338 | <tr> |
| 339 | <td colspan="3"><i>All attributes of the <code>coverage</code> task.</i></td> |
| 340 | </tr> |
| 341 | </tbody> |
| 342 | </table> |
| 343 | |
| 344 | |
| 345 | <h2><a name="dump">Task <code>dump</code></a></h2> |
| 346 | |
| 347 | <p> |
| 348 | This task allows to remotely collect execution data from another JVM without |
| 349 | stopping it. For example: |
| 350 | </p> |
| 351 | |
| 352 | <pre class="source lang-xml linenums"> |
| 353 | <jacoco:dump address="server.example.com" reset="true" destfile="remote.exec"/> |
| 354 | </pre> |
| 355 | |
| 356 | <p> |
| 357 | Remote dumps are usefull for long running Java processes like application |
| 358 | servers. |
| 359 | </p> |
| 360 | |
| 361 | <p class="hint"> |
| 362 | The target JVM needs to have a <a href="agent.html">JaCoCo agent</a> |
| 363 | configured with <code>output</code> mode <code>tcpserver</code>. See |
| 364 | <a href="#coverage"><code>coverage</code></a> and |
| 365 | <a href="#agent"><code>agent</code></a> tasks above. |
| 366 | </p> |
| 367 | |
| 368 | <p> |
| 369 | The <code>dump</code> task has the following attributes: |
| 370 | </p> |
| 371 | |
| 372 | <table class="coverage"> |
| 373 | <thead> |
| 374 | <tr> |
| 375 | <td>Attribute</td> |
| 376 | <td>Description</td> |
| 377 | <td>Default</td> |
| 378 | </tr> |
| 379 | </thead> |
| 380 | <tbody> |
| 381 | <tr> |
| 382 | <td><code>address</code></td> |
| 383 | <td>Target IP address or DNS name.</td> |
| 384 | <td><code>localhost</code></td> |
| 385 | </tr> |
| 386 | <tr> |
| 387 | <td><code>port</code></td> |
| 388 | <td>Target TCP port.</td> |
| 389 | <td><code>6300</code></td> |
| 390 | </tr> |
| 391 | <tr> |
Marc R. Hoffmann | a3a1f5a | 2013-11-10 14:05:33 +0100 | [diff] [blame] | 392 | <td><code>retryCount</code></td> |
| 393 | <td>Number of retries which the goal will attempt to establish a |
| 394 | connection. This can be used to wait until the target JVM is |
| 395 | successfully launched.</td> |
| 396 | <td><code>10</code></td> |
| 397 | </tr> |
| 398 | <tr> |
Evgeny Mandrikov | 82a92ca | 2012-01-15 20:25:48 +0000 | [diff] [blame] | 399 | <td><code>dump</code></td> |
| 400 | <td>Flag whether execution data should be dumped.</td> |
| 401 | <td><code>true</code></td> |
| 402 | </tr> |
| 403 | <tr> |
| 404 | <td><code>reset</code></td> |
| 405 | <td>Flag whether execution data should be reset in the target agent after |
| 406 | the dump.</td> |
| 407 | <td><code>false</code></td> |
| 408 | </tr> |
| 409 | <tr> |
| 410 | <td><code>destfile</code></td> |
| 411 | <td>File location to write the collected execution data to.</td> |
| 412 | <td><i>none (required if dump=true)</i></td> |
| 413 | </tr> |
| 414 | <tr> |
| 415 | <td><code>append</code></td> |
| 416 | <td>If set to <code>true</code> and the execution data file already |
| 417 | exists, coverage data is appended to the existing file. If set to |
| 418 | <code>false</code>, an existing execution data file will be replaced. |
| 419 | </td> |
| 420 | <td><code>true</code></td> |
| 421 | </tr> |
| 422 | </tbody> |
| 423 | </table> |
| 424 | |
| 425 | |
| 426 | <h2><a name="merge">Task <code>merge</code></a></h2> |
| 427 | |
| 428 | <p> |
| 429 | This task can be used to merge the execution data from multiple test runs |
| 430 | into a single data store. |
| 431 | </p> |
| 432 | |
| 433 | <pre class="source lang-xml linenums"> |
| 434 | <jacoco:merge destfile="merged.exec"> |
| 435 | <fileset dir="executionData" includes="*.exec"/> |
| 436 | </jacoco:merge> |
| 437 | </pre> |
| 438 | |
| 439 | <p> |
| 440 | The task definition can contain any number of resource collection types and |
| 441 | has the following mandatory attribute: |
| 442 | </p> |
| 443 | |
| 444 | <table class="coverage"> |
| 445 | <thead> |
| 446 | <tr> |
| 447 | <td>Attribute</td> |
| 448 | <td>Description</td> |
| 449 | <td>Default</td> |
| 450 | </tr> |
| 451 | </thead> |
| 452 | <tbody> |
| 453 | <tr> |
| 454 | <td><code>destfile</code></td> |
| 455 | <td>File location to write the merged execution data to.</td> |
| 456 | <td><i>none (required)</i></td> |
| 457 | </tr> |
| 458 | </tbody> |
| 459 | </table> |
| 460 | |
| 461 | |
| 462 | <h2><a name="report">Task <code>report</code></a></h2> |
| 463 | |
| 464 | <p> |
| 465 | Finally different reports can be created with the <code>report</code> task. |
| 466 | A report task declaration consists of different sections, two specify the |
| 467 | input data, additional ones specify the output formats: |
| 468 | </p> |
| 469 | |
| 470 | <pre class="source lang-xml linenums"> |
| 471 | <jacoco:report> |
| 472 | |
| 473 | <executiondata> |
| 474 | <file file="jacoco.exec"/> |
| 475 | </executiondata> |
| 476 | |
| 477 | <structure name="Example Project"> |
| 478 | <classfiles> |
| 479 | <fileset dir="classes"/> |
| 480 | </classfiles> |
| 481 | <sourcefiles encoding="UTF-8"> |
| 482 | <fileset dir="src"/> |
| 483 | </sourcefiles> |
| 484 | </structure> |
| 485 | |
| 486 | <html destdir="report"/> |
| 487 | |
| 488 | </jacoco:report> |
| 489 | </pre> |
| 490 | |
| 491 | <p> |
| 492 | As you can see from the example above the <code>report</code> task is based |
| 493 | on several nested elements: |
| 494 | </p> |
| 495 | |
| 496 | <h3>Element <code>executiondata</code></h3> |
| 497 | |
| 498 | <p> |
| 499 | Within this element Ant resources and resource collections can be specified, |
| 500 | that represent JaCoCo execution data files. If more than one execution data |
| 501 | file is specified, execution data is combined. A particular piece of code is |
| 502 | considered executed when it is marked as such in any of the input files. |
| 503 | </p> |
| 504 | |
| 505 | <h3>Element <code>structure</code></h3> |
| 506 | |
| 507 | <p> |
| 508 | This element defines the report structure. It might contain the following |
| 509 | nested elements: |
| 510 | </p> |
| 511 | |
| 512 | <ul> |
| 513 | <li><code>classfiles</code>: Container element for Ant resources and resource |
Marc R. Hoffmann | fc340a2 | 2013-03-22 11:13:24 +0100 | [diff] [blame] | 514 | collections that can specify Java class files, archive files (jar, war, ear |
| 515 | etc. or Pack200) or folders containing class files. Archives and folders are |
Evgeny Mandrikov | 82a92ca | 2012-01-15 20:25:48 +0000 | [diff] [blame] | 516 | searched recursively for class files.</li> |
| 517 | <li><code>sourcefiles</code>: Optional container element for Ant resources and |
| 518 | resource collections that specify corresponding source files. If source |
Marc R. Hoffmann | 8b5d6a3 | 2012-01-18 20:24:45 +0000 | [diff] [blame] | 519 | files are specified, some report formats include highlighted source code. |
| 520 | Source files can be specified as individual files or as source directories.</li> |
Evgeny Mandrikov | 82a92ca | 2012-01-15 20:25:48 +0000 | [diff] [blame] | 521 | </ul> |
| 522 | |
| 523 | <p> |
| 524 | The <code>sourcefiles</code> element has these optional attributes: |
| 525 | </p> |
| 526 | |
| 527 | <table class="coverage"> |
| 528 | <thead> |
| 529 | <tr> |
| 530 | <td>Attribute</td> |
| 531 | <td>Description</td> |
| 532 | <td>Default</td> |
| 533 | </tr> |
| 534 | </thead> |
| 535 | <tbody> |
| 536 | <tr> |
| 537 | <td><code>encoding</code></td> |
| 538 | <td>Character encoding of the source files.</td> |
| 539 | <td>Platform default encoding</td> |
| 540 | </tr> |
| 541 | <tr> |
| 542 | <td><code>tabwidth</code></td> |
| 543 | <td>Number of whitespace characters that represent a tab character.</td> |
| 544 | <td>4 characters</td> |
| 545 | </tr> |
| 546 | </tbody> |
| 547 | </table> |
| 548 | |
Marc R. Hoffmann | 8b5d6a3 | 2012-01-18 20:24:45 +0000 | [diff] [blame] | 549 | <p class="hint"> |
| 550 | <b>Important:</b> Source file resources must always be specified relative to |
| 551 | the respective source folder. If directory resources are given, they must |
| 552 | directly point to source folders. Otherwise source lookup will not succeed. |
| 553 | </p> |
| 554 | |
Evgeny Mandrikov | 82a92ca | 2012-01-15 20:25:48 +0000 | [diff] [blame] | 555 | <p> |
| 556 | Note that the <code>classfiles</code> and <code>sourcefiles</code> elements |
| 557 | accept any |
| 558 | <a href="http://ant.apache.org/manual/Types/resources.html#collection">Ant |
| 559 | resource collection</a>. Therefore also filtering the class file set is |
| 560 | possible and allows to narrow the scope of the report, for example: |
| 561 | </p> |
| 562 | |
| 563 | <pre class="source lang-xml linenums"> |
| 564 | <classfiles> |
| 565 | <fileset dir="classes"> |
| 566 | <include name="org/jacoco/examples/important/**/*.class"/> |
| 567 | </fileset> |
| 568 | </classfiles> |
| 569 | </pre> |
| 570 | |
| 571 | <p class="hint"> |
| 572 | <b>Performance Warning:</b> Although it is technically possible and sometimes |
| 573 | convenient to use Ant's <code>zipfileset</code> to specify class or source |
| 574 | files, this resource type has poor performance characteristics and comes with |
| 575 | an huge memory overhead especially for large scale projects. |
| 576 | </p> |
| 577 | |
| 578 | <p> |
| 579 | The structure can be refined with a hierarchy of <code>group</code> elements. |
| 580 | This way the coverage report can reflect different modules of a software |
| 581 | project. For each group element the corresponding class and source files can |
| 582 | be specified separately. For example: |
| 583 | </p> |
| 584 | |
| 585 | <pre class="source lang-xml linenums"> |
| 586 | <structure name="Example Project"> |
| 587 | <group name="Server"> |
| 588 | <classfiles> |
| 589 | <fileset dir="${workspace.dir}/org.jacoco.example.server/classes"/> |
| 590 | </classfiles> |
| 591 | <sourcefiles> |
| 592 | <fileset dir="${workspace.dir}/org.jacoco.example.server/src"/> |
| 593 | </sourcefiles> |
| 594 | </group> |
| 595 | <group name="Client"> |
| 596 | <classfiles> |
| 597 | <fileset dir="${workspace.dir}/org.jacoco.example.client/classes"/> |
| 598 | </classfiles> |
| 599 | <sourcefiles> |
| 600 | <fileset dir="${workspace.dir}/org.jacoco.example.client/src"/> |
| 601 | </sourcefiles> |
| 602 | </group> |
| 603 | |
| 604 | ... |
| 605 | |
| 606 | </structure> |
| 607 | </pre> |
| 608 | |
| 609 | <p> |
| 610 | Both <code>structure</code> and <code>group</code> elements have the following |
| 611 | mandatory attribute: |
| 612 | </p> |
| 613 | |
| 614 | <table class="coverage"> |
| 615 | <thead> |
| 616 | <tr> |
| 617 | <td>Attribute</td> |
| 618 | <td>Description</td> |
| 619 | <td>Default</td> |
| 620 | </tr> |
| 621 | </thead> |
| 622 | <tbody> |
| 623 | <tr> |
| 624 | <td><code>name</code></td> |
| 625 | <td>Name of the structure or group.</td> |
| 626 | <td><i>none (required)</i></td> |
| 627 | </tr> |
| 628 | </tbody> |
| 629 | </table> |
| 630 | |
| 631 | <h3>Element <code>html</code></h3> |
| 632 | |
| 633 | <p> |
| 634 | Create a multi-page report in HTML format. The report can either be written as |
| 635 | multiple files into a directory or compressed into a single ZIP file. |
| 636 | </p> |
| 637 | |
| 638 | <table class="coverage"> |
| 639 | <thead> |
| 640 | <tr> |
| 641 | <td>Attribute</td> |
| 642 | <td>Description</td> |
| 643 | <td>Default</td> |
| 644 | </tr> |
| 645 | </thead> |
| 646 | <tbody> |
| 647 | <tr> |
| 648 | <td><code>destdir</code></td> |
| 649 | <td>Directory to create the report in. Either this property or |
| 650 | <code>destfile</code> has to be supplied.</td> |
| 651 | <td><i>none (required)</i></td> |
| 652 | </tr> |
| 653 | <tr> |
| 654 | <td><code>destfile</code></td> |
| 655 | <td>Zip file to create the report in. Either this property or |
| 656 | <code>destdir</code> has to be supplied.</td> |
| 657 | <td><i>none (required)</i></td> |
| 658 | </tr> |
| 659 | <tr> |
| 660 | <td><code>footer</code></td> |
| 661 | <td>Footer text for each report page.</td> |
| 662 | <td><i>no footer</i></td> |
| 663 | </tr> |
| 664 | <tr> |
| 665 | <td><code>encoding</code></td> |
| 666 | <td>Character encoding of generated HTML pages.</td> |
| 667 | <td><code>UTF-8</code></td> |
| 668 | </tr> |
| 669 | <tr> |
| 670 | <td><code>locale</code></td> |
Marc R. Hoffmann | d4ef46a | 2015-03-27 08:15:40 +0100 | [diff] [blame] | 671 | <td>Locale specified as ISO code (en, fr, jp, ...) used for number |
Hemant Kumar | 02accc7 | 2016-12-13 03:44:15 +0530 | [diff] [blame] | 672 | formatting. Locale country and variant can be separated with an underscore |
Marc R. Hoffmann | d4ef46a | 2015-03-27 08:15:40 +0100 | [diff] [blame] | 673 | (de_CH).</td> |
Evgeny Mandrikov | 82a92ca | 2012-01-15 20:25:48 +0000 | [diff] [blame] | 674 | <td><i>platform locale</i></td> |
| 675 | </tr> |
| 676 | </tbody> |
| 677 | </table> |
| 678 | |
| 679 | <h3>Element <code>xml</code></h3> |
| 680 | |
| 681 | <p> |
| 682 | Create a single-file report in XML format. |
| 683 | </p> |
| 684 | |
| 685 | <table class="coverage"> |
| 686 | <thead> |
| 687 | <tr> |
| 688 | <td>Attribute</td> |
| 689 | <td>Description</td> |
| 690 | <td>Default</td> |
| 691 | </tr> |
| 692 | </thead> |
| 693 | <tbody> |
| 694 | <tr> |
| 695 | <td><code>destfile</code></td> |
| 696 | <td>Location to write the report file to.</td> |
| 697 | <td><i>none (required)</i></td> |
| 698 | </tr> |
| 699 | <tr> |
| 700 | <td><code>encoding</code></td> |
| 701 | <td>Encoding of the generated XML document.</td> |
| 702 | <td><code>UTF-8</code></td> |
| 703 | </tr> |
| 704 | </tbody> |
| 705 | </table> |
| 706 | |
| 707 | <h3>Element <code>csv</code></h3> |
| 708 | |
| 709 | <p> |
| 710 | Create single-file report in CSV format. |
| 711 | </p> |
| 712 | |
| 713 | <table class="coverage"> |
| 714 | <thead> |
| 715 | <tr> |
| 716 | <td>Attribute</td> |
| 717 | <td>Description</td> |
| 718 | <td>Default</td> |
| 719 | </tr> |
| 720 | </thead> |
| 721 | <tbody> |
| 722 | <tr> |
| 723 | <td><code>destfile</code></td> |
| 724 | <td>Location to write the report file to.</td> |
| 725 | <td><i>none (required)</i></td> |
| 726 | </tr> |
| 727 | <tr> |
| 728 | <td><code>encoding</code></td> |
| 729 | <td>Encoding of the generated CSV document.</td> |
| 730 | <td><code>UTF-8</code></td> |
| 731 | </tr> |
| 732 | </tbody> |
| 733 | </table> |
| 734 | |
Marc R. Hoffmann | 55fae17 | 2013-03-20 11:55:53 +0100 | [diff] [blame] | 735 | <h3>Element <code>check</code></h3> |
| 736 | |
| 737 | <p> |
| 738 | This report type does not actually create a report. It checks coverage |
| 739 | counters and reports violations of configured rules. Every rule is applied to |
| 740 | elements of a given type (class, package, bundle, etc.) and has a list of |
| 741 | limits which are checked for every element. The following example checks that |
| 742 | for every package the line coverage is at least 80% and no class is missed: |
| 743 | </p> |
| 744 | |
| 745 | <pre class="source lang-xml linenums"> |
| 746 | <check> |
Marc R. Hoffmann | cc07556 | 2013-05-25 15:39:12 +0200 | [diff] [blame] | 747 | <rule element="PACKAGE"> |
Marc R. Hoffmann | 129201d | 2017-05-18 21:07:07 +0200 | [diff] [blame] | 748 | <limit counter="LINE" value="COVEREDRATIO" minimum="80%"/> |
Marc R. Hoffmann | cc07556 | 2013-05-25 15:39:12 +0200 | [diff] [blame] | 749 | <limit counter="CLASS" value="MISSEDCOUNT" maximum="0"/> |
Marc R. Hoffmann | 55fae17 | 2013-03-20 11:55:53 +0100 | [diff] [blame] | 750 | </rule> |
| 751 | </check> |
| 752 | </pre> |
| 753 | |
| 754 | <p> |
| 755 | The <code>check</code> element has the following attributes: |
| 756 | </p> |
| 757 | |
| 758 | <table class="coverage"> |
| 759 | <thead> |
| 760 | <tr> |
| 761 | <td>Attribute</td> |
| 762 | <td>Description</td> |
| 763 | <td>Default</td> |
| 764 | </tr> |
| 765 | </thead> |
| 766 | <tbody> |
| 767 | <tr> |
| 768 | <td><code>rules</code></td> |
| 769 | <td>List of rules to check.</td> |
| 770 | <td><i>none</i></td> |
| 771 | </tr> |
| 772 | <tr> |
| 773 | <td><code>failonviolation</code></td> |
| 774 | <td>Specifies whether build should fail in case of rule violations.</td> |
| 775 | <td><code>true</code></td> |
| 776 | </tr> |
| 777 | <tr> |
| 778 | <td><code>violationsproperty</code></td> |
| 779 | <td>The name of an Ant property which is filled with the violation |
Marc R. Hoffmann | cc07556 | 2013-05-25 15:39:12 +0200 | [diff] [blame] | 780 | messages.</td> |
Marc R. Hoffmann | 55fae17 | 2013-03-20 11:55:53 +0100 | [diff] [blame] | 781 | <td><i>none</i></td> |
| 782 | </tr> |
| 783 | </tbody> |
| 784 | </table> |
| 785 | |
| 786 | <p> |
| 787 | Within the <code>check</code> element any number of <code>rule</code> elements |
| 788 | can be nested: |
| 789 | </p> |
| 790 | |
| 791 | <table class="coverage"> |
| 792 | <thead> |
| 793 | <tr> |
| 794 | <td>Attribute</td> |
| 795 | <td>Description</td> |
| 796 | <td>Default</td> |
| 797 | </tr> |
| 798 | </thead> |
| 799 | <tbody> |
| 800 | <tr> |
| 801 | <td><code>element</code></td> |
| 802 | <td>The elements this rule applies to. Possible values are |
Hemant Kumar | 02accc7 | 2016-12-13 03:44:15 +0530 | [diff] [blame] | 803 | <code>BUNDLE</code>, <code>PACKAGE</code>, <code>CLASS</code>, |
Marc R. Hoffmann | 55fae17 | 2013-03-20 11:55:53 +0100 | [diff] [blame] | 804 | <code>SOURCEFILE</code> and <code>METHOD</code>.</td> |
Hemant Kumar | 02accc7 | 2016-12-13 03:44:15 +0530 | [diff] [blame] | 805 | <td><code>BUNDLE</code></td> |
Marc R. Hoffmann | 55fae17 | 2013-03-20 11:55:53 +0100 | [diff] [blame] | 806 | </tr> |
| 807 | <tr> |
| 808 | <td><code>includes</code></td> |
| 809 | <td>A list of element names that should be checked. The list entries are |
| 810 | separated by a colon (:) and may use wildcard characters (* and ?).</td> |
| 811 | <td><code>*</code></td> |
| 812 | </tr> |
| 813 | <tr> |
| 814 | <td><code>excludes</code></td> |
| 815 | <td>A list of element names that should not be checked. The list entries |
| 816 | are separated by a colon (:) and may use wildcard characters (* and ?).</td> |
| 817 | <td><i>empty (no excludes)</i></td> |
| 818 | </tr> |
| 819 | <tr> |
| 820 | <td><code>limits</code></td> |
Marc R. Hoffmann | cc07556 | 2013-05-25 15:39:12 +0200 | [diff] [blame] | 821 | <td>List of limits to check.</td> |
Marc R. Hoffmann | 55fae17 | 2013-03-20 11:55:53 +0100 | [diff] [blame] | 822 | <td><i>none</i></td> |
| 823 | </tr> |
| 824 | </tbody> |
| 825 | </table> |
| 826 | |
| 827 | <p> |
| 828 | Within the <code>rule</code> element any number of <code>limit</code> elements |
| 829 | can be nested: |
| 830 | </p> |
| 831 | |
| 832 | <table class="coverage"> |
| 833 | <thead> |
| 834 | <tr> |
| 835 | <td>Attribute</td> |
| 836 | <td>Description</td> |
| 837 | <td>Default</td> |
| 838 | </tr> |
| 839 | </thead> |
| 840 | <tbody> |
| 841 | <tr> |
| 842 | <td><code>counter</code></td> |
| 843 | <td>The <a href="counters.html">counter</a> which should be checked. |
| 844 | Possible options are <code>INSTRUCTION</code>, <code>LINE</code>, |
| 845 | <code>BRANCH</code>, <code>COMPLEXITY</code>, <code>METHOD</code> and |
| 846 | <code>CLASS</code>.</td> |
| 847 | <td><code>INSTRUCTION</code></td> |
| 848 | </tr> |
| 849 | <tr> |
| 850 | <td><code>value</code></td> |
| 851 | <td>The counter value that should be checked. Possible options are |
| 852 | <code>TOTALCOUNT</code>, <code>MISSEDCOUNT</code>, |
| 853 | <code>COVEREDCOUNT</code>, <code>MISSEDRATIO</code> and |
Marc R. Hoffmann | cc07556 | 2013-05-25 15:39:12 +0200 | [diff] [blame] | 854 | <code>COVEREDRATIO</code>.</td> |
Marc R. Hoffmann | 55fae17 | 2013-03-20 11:55:53 +0100 | [diff] [blame] | 855 | <td><code>COVEREDRATIO</code></td> |
| 856 | </tr> |
| 857 | <tr> |
| 858 | <td><code>minimum</code></td> |
Hemant Kumar | 02accc7 | 2016-12-13 03:44:15 +0530 | [diff] [blame] | 859 | <td>Expected minimum value. If the minimum refers to a ratio the range is |
Marc R. Hoffmann | cc07556 | 2013-05-25 15:39:12 +0200 | [diff] [blame] | 860 | from 0.0 to 1.0 where the number of decimal places will also determine |
Marc R. Hoffmann | 129201d | 2017-05-18 21:07:07 +0200 | [diff] [blame] | 861 | the precision in error messages. A limit ratio may optionally be |
| 862 | declared as a percentage where 0.80 and 80% represent the same value, |
| 863 | the value must end with %.</td> |
Marc R. Hoffmann | 55fae17 | 2013-03-20 11:55:53 +0100 | [diff] [blame] | 864 | <td><i>none</i></td> |
| 865 | </tr> |
| 866 | <tr> |
| 867 | <td><code>maximum</code></td> |
Marc R. Hoffmann | 129201d | 2017-05-18 21:07:07 +0200 | [diff] [blame] | 868 | <td>Expected maximum value, see <code>minimum</code> for details.</td> |
Marc R. Hoffmann | 55fae17 | 2013-03-20 11:55:53 +0100 | [diff] [blame] | 869 | <td><i>none</i></td> |
| 870 | </tr> |
| 871 | </tbody> |
| 872 | </table> |
Marc R. Hoffmann | 235a09e | 2012-12-23 15:57:16 +0100 | [diff] [blame] | 873 | |
| 874 | <h2><a name="instrument">Task <code>instrument</code></a></h2> |
| 875 | |
Marc R. Hoffmann | 146716a | 2013-01-14 13:26:36 +0100 | [diff] [blame] | 876 | <p class="hint"> |
| 877 | <b>Warning:</b> The preferred way for code coverage analysis with JaCoCo is |
| 878 | on-the-fly instrumentation. Offline instrumentation has several drawbacks and |
| 879 | should only be used if a specific scenario explicitly requires this mode. |
| 880 | Please consult <a href="offline.html">documentation</a> about offline |
| 881 | instrumentation before using this mode. |
| 882 | </p> |
| 883 | |
Marc R. Hoffmann | 235a09e | 2012-12-23 15:57:16 +0100 | [diff] [blame] | 884 | <p> |
| 885 | This task is used for <a href="offline.html">offline instrumentation</a> of |
Marc R. Hoffmann | adf2bf6 | 2012-12-28 20:56:45 +0100 | [diff] [blame] | 886 | class files. The task takes a set of files and writes instrumented |
| 887 | versions to a specified location. The task takes any file type as input. Java |
Marc R. Hoffmann | fc340a2 | 2013-03-22 11:13:24 +0100 | [diff] [blame] | 888 | class files are instrumented. Archives (jar, war, ear etc. or Pack200) are |
| 889 | searched recursively for class files which then get instrumented. All other |
| 890 | files are copied without modification. |
Marc R. Hoffmann | 235a09e | 2012-12-23 15:57:16 +0100 | [diff] [blame] | 891 | </p> |
| 892 | |
| 893 | <pre class="source lang-xml linenums"> |
James Anderson | 830d26d | 2013-01-26 09:00:32 -0600 | [diff] [blame] | 894 | <jacoco:instrument destdir="target/classes-instr"> |
Marc R. Hoffmann | 235a09e | 2012-12-23 15:57:16 +0100 | [diff] [blame] | 895 | <fileset dir="target/classes" includes="**/*.class"/> |
| 896 | </jacoco:instrument> |
| 897 | </pre> |
| 898 | |
| 899 | <p> |
| 900 | The task definition can contain any number of resource collection types and |
| 901 | has the following mandatory attribute: |
| 902 | </p> |
| 903 | |
| 904 | <table class="coverage"> |
| 905 | <thead> |
| 906 | <tr> |
| 907 | <td>Attribute</td> |
| 908 | <td>Description</td> |
| 909 | <td>Default</td> |
| 910 | </tr> |
| 911 | </thead> |
| 912 | <tbody> |
| 913 | <tr> |
| 914 | <td><code>destdir</code></td> |
Marc R. Hoffmann | adf2bf6 | 2012-12-28 20:56:45 +0100 | [diff] [blame] | 915 | <td>Directory location to write the instrumented files to.</td> |
Marc R. Hoffmann | 235a09e | 2012-12-23 15:57:16 +0100 | [diff] [blame] | 916 | <td><i>none (required)</i></td> |
| 917 | </tr> |
Marc R. Hoffmann | 39d48af | 2014-02-22 10:26:53 +0100 | [diff] [blame] | 918 | <tr> |
| 919 | <td><code>removesignatures</code></td> |
| 920 | <td>If set to <code>true</code> all signature related information is |
| 921 | stripped from JARs. This is typically necessary as instrumentation |
| 922 | breaks the signatures of the original class files.</td> |
| 923 | <td><code>true</code></td> |
| 924 | </tr> |
Marc R. Hoffmann | 235a09e | 2012-12-23 15:57:16 +0100 | [diff] [blame] | 925 | </tbody> |
| 926 | </table> |
| 927 | |
Evgeny Mandrikov | 82a92ca | 2012-01-15 20:25:48 +0000 | [diff] [blame] | 928 | </div> |
| 929 | <div class="footer"> |
| 930 | <span class="right"><a href="@jacoco.home.url@">JaCoCo</a> @qualified.bundle.version@</span> |
| 931 | <a href="license.html">Copyright</a> © @copyright.years@ Mountainminds GmbH & Co. KG and Contributors |
| 932 | </div> |
| 933 | |
| 934 | </body> |
| 935 | </html> |