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" /> |
| 6 | <link rel="stylesheet" href=".resources/doc.css" charset="UTF-8" type="text/css" /> |
| 7 | <link rel="stylesheet" href="../coverage/.resources/prettify.css" charset="UTF-8" type="text/css" /> |
Evgeny Mandrikov | 82a92ca | 2012-01-15 20:25:48 +0000 | [diff] [blame] | 8 | <link rel="shortcut icon" href=".resources/report.gif" type="image/gif" /> |
| 9 | <script type="text/javascript" src="../coverage/.resources/prettify.js"></script> |
| 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 |
Marc R. Hoffmann | 235a09e | 2012-12-23 15:57:16 +0100 | [diff] [blame] | 31 | creates with the <a href="#report"><code>report</code></a> task. For |
| 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, |
Marc R. Hoffmann | 7830927 | 2012-05-02 19:25:44 +0000 | [diff] [blame] | 49 | runs an simple Java programm and creates a coverage report. The complete |
| 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 |
| 140 | required by the nature of the test cases). |
| 141 | </p> |
| 142 | |
| 143 | <p> |
| 144 | The coverage task must wrap exactly one task. While it typically works without |
| 145 | any configuration, the behavior can be adjusted with some optional attributes: |
| 146 | </p> |
| 147 | |
| 148 | <table class="coverage"> |
| 149 | <thead> |
| 150 | <tr> |
| 151 | <td>Attribute</td> |
| 152 | <td>Description</td> |
| 153 | <td>Default</td> |
| 154 | </tr> |
| 155 | </thead> |
| 156 | <tbody> |
| 157 | <tr> |
| 158 | <td><code>enabled</code></td> |
| 159 | <td>If set to <code>true</code> coverage data will be collected for the contained task.</td> |
| 160 | <td><code>true</code></td> |
| 161 | </tr> |
| 162 | <tr> |
| 163 | <td><code>destfile</code></td> |
| 164 | <td>Path to the output file for execution data.</td> |
| 165 | <td><code>jacoco.exec</code></td> |
| 166 | </tr> |
| 167 | <tr> |
| 168 | <td><code>append</code></td> |
| 169 | <td>If set to <code>true</code> and the execution data file already |
| 170 | exists, coverage data is appended to the existing file. If set to |
| 171 | <code>false</code>, an existing execution data file will be replaced. |
| 172 | </td> |
| 173 | <td><code>true</code></td> |
| 174 | </tr> |
| 175 | <tr> |
| 176 | <td><code>includes</code></td> |
| 177 | <td>A list of class names that should be included in execution analysis. |
| 178 | The list entries are separated by a colon (<code>:</code>) and |
| 179 | may use wildcard characters (<code>*</code> and <code>?</code>). |
| 180 | Except for performance optimization or technical corner cases this |
| 181 | option is normally not required. |
| 182 | </td> |
| 183 | <td><code>*</code> (all classes)</td> |
| 184 | </tr> |
| 185 | <tr> |
| 186 | <td><code>excludes</code></td> |
| 187 | <td>A list of class names that should be excluded from execution analysis. |
| 188 | The list entries are separated by a colon (<code>:</code>) and |
| 189 | may use wildcard characters (<code>*</code> and <code>?</code>). |
| 190 | Except for performance optimization or technical corner cases this |
| 191 | option is normally not required. |
| 192 | </td> |
| 193 | <td><i>empty</i> (no excluded classes)</td> |
| 194 | </tr> |
| 195 | <tr> |
| 196 | <td><code>exclclassloader</code></td> |
| 197 | <td>A list of class loader names, that should be excluded from execution |
| 198 | analysis. The list entries are separated by a colon |
| 199 | (<code>:</code>) and may use wildcard characters (<code>*</code> and |
| 200 | <code>?</code>). This option might be required in case of special |
| 201 | frameworks that conflict with JaCoCo code instrumentation, in |
| 202 | particular class loaders that do not have access to the Java runtime |
| 203 | classes. |
| 204 | </td> |
| 205 | <td><code>sun.reflect.DelegatingClassLoader</code></td> |
| 206 | </tr> |
| 207 | <tr> |
| 208 | <td><code>sessionid</code></td> |
| 209 | <td>A session identifier that is written with the execution data. Without |
| 210 | this parameter a random identifier is created by the agent. |
| 211 | </td> |
| 212 | <td><i>auto-generated</i></td> |
| 213 | </tr> |
| 214 | <tr> |
| 215 | <td><code>dumponexit</code></td> |
| 216 | <td>If set to <code>true</code> coverage data will be written on VM |
| 217 | shutdown. |
| 218 | </td> |
| 219 | <td><code>true</code></td> |
| 220 | </tr> |
| 221 | <tr> |
| 222 | <td><code>output</code></td> |
| 223 | <td>Output method to use for writing coverage data. Valid options are: |
| 224 | <ul> |
| 225 | <li><code>file</code>: At VM termination execution data is written to |
| 226 | the file specified in the <code>destfile</code> attribute.</li> |
| 227 | <li><code>tcpserver</code>: The agent listens for incoming connections |
| 228 | on the TCP port specified by the <code>address</code> and |
| 229 | <code>port</code> attribute. Execution data is written to this |
| 230 | TCP connection.</li> |
| 231 | <li><code>tcpclient</code>: At startup the agent connects to the TCP |
| 232 | port specified by the <code>address</code> and <code>port</code> |
| 233 | attribute. Execution data is written to this TCP connection.</li> |
| 234 | <li><code>mbean</code>: The agent registers an JMX MBean under the |
| 235 | name <code>org.jacoco:type=Runtime</code>.</li> |
| 236 | </ul> |
| 237 | </td> |
| 238 | <td><code>file</code></td> |
| 239 | </tr> |
| 240 | <tr> |
| 241 | <td><code>address</code></td> |
| 242 | <td>IP address or hostname to bind to when the output method is |
| 243 | <code>tcpserver</code> or connect to when the output method is |
| 244 | <code>tcpclient</code>. In <code>tcpserver</code> mode the value |
| 245 | "<code>*</code>" causes the agent to accept connections on any local |
| 246 | address. |
| 247 | </td> |
| 248 | <td><i>loopback interface</i></td> |
| 249 | </tr> |
| 250 | <tr> |
| 251 | <td><code>port</code></td> |
| 252 | <td>Port to bind to when the output method is <code>tcpserver</code> or |
| 253 | connect to when the output method is <code>tcpclient</code>. In |
| 254 | <code>tcpserver</code> mode the port must be available, which means |
| 255 | that if multiple JaCoCo agents should run on the same machine, |
| 256 | different ports have to be specified. |
| 257 | </td> |
| 258 | <td><code>6300</code></td> |
| 259 | </tr> |
Marc R. Hoffmann | cf41fc1 | 2012-06-30 00:15:43 +0000 | [diff] [blame] | 260 | <tr> |
| 261 | <td><code>classdumpdir</code></td> |
| 262 | <td>Location relative to the working directory where all class files seen |
| 263 | by the agent are dumped to. This can be useful for debugging purposes |
| 264 | or in case of dynamically created classes for example when scripting |
| 265 | engines are used. |
| 266 | </td> |
| 267 | <td><i>no dumps</i></td> |
| 268 | </tr> |
Evgeny Mandrikov | 82a92ca | 2012-01-15 20:25:48 +0000 | [diff] [blame] | 269 | </tbody> |
| 270 | </table> |
| 271 | |
| 272 | |
| 273 | <h2><a name="agent">Task <code>agent</code></a></h2> |
| 274 | |
| 275 | <p> |
| 276 | If the <code>coverage</code> task is not suitable for your launch target, you |
| 277 | might alternatively use the <code>agent</code> task to create the |
| 278 | <a href="agent.html">Java agent</a> parameter. The following example defines a |
| 279 | Ant property with the name <code>agentvmparam</code> that can be directly used |
| 280 | as a Java VM parameter: |
| 281 | </p> |
| 282 | |
| 283 | <pre class="source lang-xml linenums"> |
| 284 | <jacoco:agent property="agentvmparam"/> |
| 285 | </pre> |
| 286 | |
| 287 | <p> |
| 288 | This task has the same attributes as the <code>coverage</code> task plus an |
| 289 | additional property to specify the target property name: |
| 290 | </p> |
| 291 | |
| 292 | <table class="coverage"> |
| 293 | <thead> |
| 294 | <tr> |
| 295 | <td>Attribute</td> |
| 296 | <td>Description</td> |
| 297 | <td>Default</td> |
| 298 | </tr> |
| 299 | </thead> |
| 300 | <tbody> |
| 301 | <tr> |
| 302 | <td><code>enabled</code></td> |
| 303 | <td>When this variable is set to <code>false</code> the value of <code>property</code> will be set to an empty string, effectively |
| 304 | disabling coverage instrumentation for any tasks that used the value.</td> |
| 305 | <td><code>true</code></td> |
| 306 | </tr> |
| 307 | <tr> |
| 308 | <td><code>property</code></td> |
| 309 | <td>Name of the Ant property to set.</td> |
| 310 | <td><i>none (required)</i></td> |
| 311 | </tr> |
| 312 | <tr> |
| 313 | <td colspan="3"><i>All attributes of the <code>coverage</code> task.</i></td> |
| 314 | </tr> |
| 315 | </tbody> |
| 316 | </table> |
| 317 | |
| 318 | |
| 319 | <h2><a name="dump">Task <code>dump</code></a></h2> |
| 320 | |
| 321 | <p> |
| 322 | This task allows to remotely collect execution data from another JVM without |
| 323 | stopping it. For example: |
| 324 | </p> |
| 325 | |
| 326 | <pre class="source lang-xml linenums"> |
| 327 | <jacoco:dump address="server.example.com" reset="true" destfile="remote.exec"/> |
| 328 | </pre> |
| 329 | |
| 330 | <p> |
| 331 | Remote dumps are usefull for long running Java processes like application |
| 332 | servers. |
| 333 | </p> |
| 334 | |
| 335 | <p class="hint"> |
| 336 | The target JVM needs to have a <a href="agent.html">JaCoCo agent</a> |
| 337 | configured with <code>output</code> mode <code>tcpserver</code>. See |
| 338 | <a href="#coverage"><code>coverage</code></a> and |
| 339 | <a href="#agent"><code>agent</code></a> tasks above. |
| 340 | </p> |
| 341 | |
| 342 | <p> |
| 343 | The <code>dump</code> task has the following attributes: |
| 344 | </p> |
| 345 | |
| 346 | <table class="coverage"> |
| 347 | <thead> |
| 348 | <tr> |
| 349 | <td>Attribute</td> |
| 350 | <td>Description</td> |
| 351 | <td>Default</td> |
| 352 | </tr> |
| 353 | </thead> |
| 354 | <tbody> |
| 355 | <tr> |
| 356 | <td><code>address</code></td> |
| 357 | <td>Target IP address or DNS name.</td> |
| 358 | <td><code>localhost</code></td> |
| 359 | </tr> |
| 360 | <tr> |
| 361 | <td><code>port</code></td> |
| 362 | <td>Target TCP port.</td> |
| 363 | <td><code>6300</code></td> |
| 364 | </tr> |
| 365 | <tr> |
| 366 | <td><code>dump</code></td> |
| 367 | <td>Flag whether execution data should be dumped.</td> |
| 368 | <td><code>true</code></td> |
| 369 | </tr> |
| 370 | <tr> |
| 371 | <td><code>reset</code></td> |
| 372 | <td>Flag whether execution data should be reset in the target agent after |
| 373 | the dump.</td> |
| 374 | <td><code>false</code></td> |
| 375 | </tr> |
| 376 | <tr> |
| 377 | <td><code>destfile</code></td> |
| 378 | <td>File location to write the collected execution data to.</td> |
| 379 | <td><i>none (required if dump=true)</i></td> |
| 380 | </tr> |
| 381 | <tr> |
| 382 | <td><code>append</code></td> |
| 383 | <td>If set to <code>true</code> and the execution data file already |
| 384 | exists, coverage data is appended to the existing file. If set to |
| 385 | <code>false</code>, an existing execution data file will be replaced. |
| 386 | </td> |
| 387 | <td><code>true</code></td> |
| 388 | </tr> |
| 389 | </tbody> |
| 390 | </table> |
| 391 | |
| 392 | |
| 393 | <h2><a name="merge">Task <code>merge</code></a></h2> |
| 394 | |
| 395 | <p> |
| 396 | This task can be used to merge the execution data from multiple test runs |
| 397 | into a single data store. |
| 398 | </p> |
| 399 | |
| 400 | <pre class="source lang-xml linenums"> |
| 401 | <jacoco:merge destfile="merged.exec"> |
| 402 | <fileset dir="executionData" includes="*.exec"/> |
| 403 | </jacoco:merge> |
| 404 | </pre> |
| 405 | |
| 406 | <p> |
| 407 | The task definition can contain any number of resource collection types and |
| 408 | has the following mandatory attribute: |
| 409 | </p> |
| 410 | |
| 411 | <table class="coverage"> |
| 412 | <thead> |
| 413 | <tr> |
| 414 | <td>Attribute</td> |
| 415 | <td>Description</td> |
| 416 | <td>Default</td> |
| 417 | </tr> |
| 418 | </thead> |
| 419 | <tbody> |
| 420 | <tr> |
| 421 | <td><code>destfile</code></td> |
| 422 | <td>File location to write the merged execution data to.</td> |
| 423 | <td><i>none (required)</i></td> |
| 424 | </tr> |
| 425 | </tbody> |
| 426 | </table> |
| 427 | |
| 428 | |
| 429 | <h2><a name="report">Task <code>report</code></a></h2> |
| 430 | |
| 431 | <p> |
| 432 | Finally different reports can be created with the <code>report</code> task. |
| 433 | A report task declaration consists of different sections, two specify the |
| 434 | input data, additional ones specify the output formats: |
| 435 | </p> |
| 436 | |
| 437 | <pre class="source lang-xml linenums"> |
| 438 | <jacoco:report> |
| 439 | |
| 440 | <executiondata> |
| 441 | <file file="jacoco.exec"/> |
| 442 | </executiondata> |
| 443 | |
| 444 | <structure name="Example Project"> |
| 445 | <classfiles> |
| 446 | <fileset dir="classes"/> |
| 447 | </classfiles> |
| 448 | <sourcefiles encoding="UTF-8"> |
| 449 | <fileset dir="src"/> |
| 450 | </sourcefiles> |
| 451 | </structure> |
| 452 | |
| 453 | <html destdir="report"/> |
| 454 | |
| 455 | </jacoco:report> |
| 456 | </pre> |
| 457 | |
| 458 | <p> |
| 459 | As you can see from the example above the <code>report</code> task is based |
| 460 | on several nested elements: |
| 461 | </p> |
| 462 | |
| 463 | <h3>Element <code>executiondata</code></h3> |
| 464 | |
| 465 | <p> |
| 466 | Within this element Ant resources and resource collections can be specified, |
| 467 | that represent JaCoCo execution data files. If more than one execution data |
| 468 | file is specified, execution data is combined. A particular piece of code is |
| 469 | considered executed when it is marked as such in any of the input files. |
| 470 | </p> |
| 471 | |
| 472 | <h3>Element <code>structure</code></h3> |
| 473 | |
| 474 | <p> |
| 475 | This element defines the report structure. It might contain the following |
| 476 | nested elements: |
| 477 | </p> |
| 478 | |
| 479 | <ul> |
| 480 | <li><code>classfiles</code>: Container element for Ant resources and resource |
| 481 | collections that can specify Java class files, ZIP archive files (jar, war, |
| 482 | ear etc.) or folders containing class files. Archives and folders are |
| 483 | searched recursively for class files.</li> |
| 484 | <li><code>sourcefiles</code>: Optional container element for Ant resources and |
| 485 | resource collections that specify corresponding source files. If source |
Marc R. Hoffmann | 8b5d6a3 | 2012-01-18 20:24:45 +0000 | [diff] [blame] | 486 | files are specified, some report formats include highlighted source code. |
| 487 | 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] | 488 | </ul> |
| 489 | |
| 490 | <p> |
| 491 | The <code>sourcefiles</code> element has these optional attributes: |
| 492 | </p> |
| 493 | |
| 494 | <table class="coverage"> |
| 495 | <thead> |
| 496 | <tr> |
| 497 | <td>Attribute</td> |
| 498 | <td>Description</td> |
| 499 | <td>Default</td> |
| 500 | </tr> |
| 501 | </thead> |
| 502 | <tbody> |
| 503 | <tr> |
| 504 | <td><code>encoding</code></td> |
| 505 | <td>Character encoding of the source files.</td> |
| 506 | <td>Platform default encoding</td> |
| 507 | </tr> |
| 508 | <tr> |
| 509 | <td><code>tabwidth</code></td> |
| 510 | <td>Number of whitespace characters that represent a tab character.</td> |
| 511 | <td>4 characters</td> |
| 512 | </tr> |
| 513 | </tbody> |
| 514 | </table> |
| 515 | |
Marc R. Hoffmann | 8b5d6a3 | 2012-01-18 20:24:45 +0000 | [diff] [blame] | 516 | <p class="hint"> |
| 517 | <b>Important:</b> Source file resources must always be specified relative to |
| 518 | the respective source folder. If directory resources are given, they must |
| 519 | directly point to source folders. Otherwise source lookup will not succeed. |
| 520 | </p> |
| 521 | |
Evgeny Mandrikov | 82a92ca | 2012-01-15 20:25:48 +0000 | [diff] [blame] | 522 | <p> |
| 523 | Note that the <code>classfiles</code> and <code>sourcefiles</code> elements |
| 524 | accept any |
| 525 | <a href="http://ant.apache.org/manual/Types/resources.html#collection">Ant |
| 526 | resource collection</a>. Therefore also filtering the class file set is |
| 527 | possible and allows to narrow the scope of the report, for example: |
| 528 | </p> |
| 529 | |
| 530 | <pre class="source lang-xml linenums"> |
| 531 | <classfiles> |
| 532 | <fileset dir="classes"> |
| 533 | <include name="org/jacoco/examples/important/**/*.class"/> |
| 534 | </fileset> |
| 535 | </classfiles> |
| 536 | </pre> |
| 537 | |
| 538 | <p class="hint"> |
| 539 | <b>Performance Warning:</b> Although it is technically possible and sometimes |
| 540 | convenient to use Ant's <code>zipfileset</code> to specify class or source |
| 541 | files, this resource type has poor performance characteristics and comes with |
| 542 | an huge memory overhead especially for large scale projects. |
| 543 | </p> |
| 544 | |
| 545 | <p> |
| 546 | The structure can be refined with a hierarchy of <code>group</code> elements. |
| 547 | This way the coverage report can reflect different modules of a software |
| 548 | project. For each group element the corresponding class and source files can |
| 549 | be specified separately. For example: |
| 550 | </p> |
| 551 | |
| 552 | <pre class="source lang-xml linenums"> |
| 553 | <structure name="Example Project"> |
| 554 | <group name="Server"> |
| 555 | <classfiles> |
| 556 | <fileset dir="${workspace.dir}/org.jacoco.example.server/classes"/> |
| 557 | </classfiles> |
| 558 | <sourcefiles> |
| 559 | <fileset dir="${workspace.dir}/org.jacoco.example.server/src"/> |
| 560 | </sourcefiles> |
| 561 | </group> |
| 562 | <group name="Client"> |
| 563 | <classfiles> |
| 564 | <fileset dir="${workspace.dir}/org.jacoco.example.client/classes"/> |
| 565 | </classfiles> |
| 566 | <sourcefiles> |
| 567 | <fileset dir="${workspace.dir}/org.jacoco.example.client/src"/> |
| 568 | </sourcefiles> |
| 569 | </group> |
| 570 | |
| 571 | ... |
| 572 | |
| 573 | </structure> |
| 574 | </pre> |
| 575 | |
| 576 | <p> |
| 577 | Both <code>structure</code> and <code>group</code> elements have the following |
| 578 | mandatory attribute: |
| 579 | </p> |
| 580 | |
| 581 | <table class="coverage"> |
| 582 | <thead> |
| 583 | <tr> |
| 584 | <td>Attribute</td> |
| 585 | <td>Description</td> |
| 586 | <td>Default</td> |
| 587 | </tr> |
| 588 | </thead> |
| 589 | <tbody> |
| 590 | <tr> |
| 591 | <td><code>name</code></td> |
| 592 | <td>Name of the structure or group.</td> |
| 593 | <td><i>none (required)</i></td> |
| 594 | </tr> |
| 595 | </tbody> |
| 596 | </table> |
| 597 | |
| 598 | <h3>Element <code>html</code></h3> |
| 599 | |
| 600 | <p> |
| 601 | Create a multi-page report in HTML format. The report can either be written as |
| 602 | multiple files into a directory or compressed into a single ZIP file. |
| 603 | </p> |
| 604 | |
| 605 | <table class="coverage"> |
| 606 | <thead> |
| 607 | <tr> |
| 608 | <td>Attribute</td> |
| 609 | <td>Description</td> |
| 610 | <td>Default</td> |
| 611 | </tr> |
| 612 | </thead> |
| 613 | <tbody> |
| 614 | <tr> |
| 615 | <td><code>destdir</code></td> |
| 616 | <td>Directory to create the report in. Either this property or |
| 617 | <code>destfile</code> has to be supplied.</td> |
| 618 | <td><i>none (required)</i></td> |
| 619 | </tr> |
| 620 | <tr> |
| 621 | <td><code>destfile</code></td> |
| 622 | <td>Zip file to create the report in. Either this property or |
| 623 | <code>destdir</code> has to be supplied.</td> |
| 624 | <td><i>none (required)</i></td> |
| 625 | </tr> |
| 626 | <tr> |
| 627 | <td><code>footer</code></td> |
| 628 | <td>Footer text for each report page.</td> |
| 629 | <td><i>no footer</i></td> |
| 630 | </tr> |
| 631 | <tr> |
| 632 | <td><code>encoding</code></td> |
| 633 | <td>Character encoding of generated HTML pages.</td> |
| 634 | <td><code>UTF-8</code></td> |
| 635 | </tr> |
| 636 | <tr> |
| 637 | <td><code>locale</code></td> |
| 638 | <td>Locale specified as ISO code (en, fr, jp, ...) used for number formating.</td> |
| 639 | <td><i>platform locale</i></td> |
| 640 | </tr> |
| 641 | </tbody> |
| 642 | </table> |
| 643 | |
| 644 | <h3>Element <code>xml</code></h3> |
| 645 | |
| 646 | <p> |
| 647 | Create a single-file report in XML format. |
| 648 | </p> |
| 649 | |
| 650 | <table class="coverage"> |
| 651 | <thead> |
| 652 | <tr> |
| 653 | <td>Attribute</td> |
| 654 | <td>Description</td> |
| 655 | <td>Default</td> |
| 656 | </tr> |
| 657 | </thead> |
| 658 | <tbody> |
| 659 | <tr> |
| 660 | <td><code>destfile</code></td> |
| 661 | <td>Location to write the report file to.</td> |
| 662 | <td><i>none (required)</i></td> |
| 663 | </tr> |
| 664 | <tr> |
| 665 | <td><code>encoding</code></td> |
| 666 | <td>Encoding of the generated XML document.</td> |
| 667 | <td><code>UTF-8</code></td> |
| 668 | </tr> |
| 669 | </tbody> |
| 670 | </table> |
| 671 | |
| 672 | <h3>Element <code>csv</code></h3> |
| 673 | |
| 674 | <p> |
| 675 | Create single-file report in CSV format. |
| 676 | </p> |
| 677 | |
| 678 | <table class="coverage"> |
| 679 | <thead> |
| 680 | <tr> |
| 681 | <td>Attribute</td> |
| 682 | <td>Description</td> |
| 683 | <td>Default</td> |
| 684 | </tr> |
| 685 | </thead> |
| 686 | <tbody> |
| 687 | <tr> |
| 688 | <td><code>destfile</code></td> |
| 689 | <td>Location to write the report file to.</td> |
| 690 | <td><i>none (required)</i></td> |
| 691 | </tr> |
| 692 | <tr> |
| 693 | <td><code>encoding</code></td> |
| 694 | <td>Encoding of the generated CSV document.</td> |
| 695 | <td><code>UTF-8</code></td> |
| 696 | </tr> |
| 697 | </tbody> |
| 698 | </table> |
| 699 | |
Marc R. Hoffmann | 235a09e | 2012-12-23 15:57:16 +0100 | [diff] [blame] | 700 | |
| 701 | <h2><a name="instrument">Task <code>instrument</code></a></h2> |
| 702 | |
| 703 | <p> |
| 704 | 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^] | 705 | class files. The task takes a set of files and writes instrumented |
| 706 | versions to a specified location. The task takes any file type as input. Java |
| 707 | class files are instrumented. Archives are searched recursively for class files |
| 708 | which then get instrumented. All other files are copied without modification. |
Marc R. Hoffmann | 235a09e | 2012-12-23 15:57:16 +0100 | [diff] [blame] | 709 | </p> |
| 710 | |
| 711 | <pre class="source lang-xml linenums"> |
| 712 | <jacoco:instrument destfile="target/classes-instr"> |
| 713 | <fileset dir="target/classes" includes="**/*.class"/> |
| 714 | </jacoco:instrument> |
| 715 | </pre> |
| 716 | |
| 717 | <p> |
| 718 | The task definition can contain any number of resource collection types and |
| 719 | has the following mandatory attribute: |
| 720 | </p> |
| 721 | |
| 722 | <table class="coverage"> |
| 723 | <thead> |
| 724 | <tr> |
| 725 | <td>Attribute</td> |
| 726 | <td>Description</td> |
| 727 | <td>Default</td> |
| 728 | </tr> |
| 729 | </thead> |
| 730 | <tbody> |
| 731 | <tr> |
| 732 | <td><code>destdir</code></td> |
Marc R. Hoffmann | adf2bf6 | 2012-12-28 20:56:45 +0100 | [diff] [blame^] | 733 | <td>Directory location to write the instrumented files to.</td> |
Marc R. Hoffmann | 235a09e | 2012-12-23 15:57:16 +0100 | [diff] [blame] | 734 | <td><i>none (required)</i></td> |
| 735 | </tr> |
| 736 | </tbody> |
| 737 | </table> |
| 738 | |
Evgeny Mandrikov | 82a92ca | 2012-01-15 20:25:48 +0000 | [diff] [blame] | 739 | </div> |
| 740 | <div class="footer"> |
| 741 | <span class="right"><a href="@jacoco.home.url@">JaCoCo</a> @qualified.bundle.version@</span> |
| 742 | <a href="license.html">Copyright</a> © @copyright.years@ Mountainminds GmbH & Co. KG and Contributors |
| 743 | </div> |
| 744 | |
| 745 | </body> |
| 746 | </html> |