blob: 74dedfa6b120e51aba4c42b1cb9001500fff67a8 [file] [log] [blame]
Marc R. Hoffmanne571f3f2012-05-13 12:18:02 +00001<?xml version="1.0" encoding="UTF-8" ?>
Evgeny Mandrikov82a92ca2012-01-15 20:25:48 +00002<!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. Hoffmanne571f3f2012-05-13 12:18:02 +00005 <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 Mandrikov82a92ca2012-01-15 20:25:48 +00008 <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> &gt;
16 <a href="index.html" class="el_group">Documentation</a> &gt;
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. Hoffmann235a09e2012-12-23 15:57:16 +010031 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 Mandrikov82a92ca2012-01-15 20:25:48 +000035</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. Hoffmanna3aa78b2012-05-02 18:56:47 +000048 <a href="examples/build/build.xml">build script</a> compiles Java sources,
Marc R. Hoffmann78309272012-05-02 19:25:44 +000049 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 Mandrikov82a92ca2012-01-15 20:25:48 +000052</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&lt;project name="Example" xmlns:jacoco="antlib:org.jacoco.ant"&gt;
74
75 &lt;taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml"&gt;
76 &lt;classpath path="<i>path_to_jacoco</i>/lib/jacocoant.jar"/&gt;
77 &lt;/taskdef&gt;
78
79 ...
80
81&lt;/project&gt;
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&lt;jacoco:coverage>
110 &lt;java classname="org.jacoco.examples.HelloJaCoCo" fork="true"&gt;
111 &lt;classpath&gt;
112 &lt;pathelement location="./bin"/&gt;
113 &lt;/classpath&gt;
114 &lt;/java&gt;
115&lt;/jacoco:coverage&gt;
116
117
118&lt;jacoco:coverage>
119 &lt;junit fork="true" forkmode="once"&gt;
120 &lt;test name="org.jacoco.examples.HelloJaCoCoTest"/&gt;
121 &lt;classpath&gt;
122 &lt;pathelement location="./bin"/&gt;
123 &lt;/classpath&gt;
124 &lt;/junit&gt;
125&lt;/jacoco:coverage&gt;
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>
Marc R. Hoffmann1d8389b2014-05-20 13:44:17 +0200208 <td><code>inclbootstrapclasses</code></td>
Marc R. Hoffmann310b7d12014-05-16 20:30:20 +0200209 <td>Specifies whether also classes from the bootstrap classloader should
210 be instrumented. Use this feature with caution, it needs heavy
211 includes/excludes tuning.
212 </td>
213 <td><code>false</code></td>
214 </tr>
215 <tr>
Evgeny Mandrikov82a92ca2012-01-15 20:25:48 +0000216 <td><code>sessionid</code></td>
217 <td>A session identifier that is written with the execution data. Without
218 this parameter a random identifier is created by the agent.
219 </td>
220 <td><i>auto-generated</i></td>
221 </tr>
222 <tr>
223 <td><code>dumponexit</code></td>
224 <td>If set to <code>true</code> coverage data will be written on VM
225 shutdown.
226 </td>
227 <td><code>true</code></td>
228 </tr>
229 <tr>
230 <td><code>output</code></td>
231 <td>Output method to use for writing coverage data. Valid options are:
232 <ul>
233 <li><code>file</code>: At VM termination execution data is written to
234 the file specified in the <code>destfile</code> attribute.</li>
235 <li><code>tcpserver</code>: The agent listens for incoming connections
236 on the TCP port specified by the <code>address</code> and
237 <code>port</code> attribute. Execution data is written to this
238 TCP connection.</li>
239 <li><code>tcpclient</code>: At startup the agent connects to the TCP
240 port specified by the <code>address</code> and <code>port</code>
241 attribute. Execution data is written to this TCP connection.</li>
Evgeny Mandrikov8c614ba2013-01-09 16:07:13 +0100242 <li><code>none</code>: Do not produce any output.</li>
Evgeny Mandrikov82a92ca2012-01-15 20:25:48 +0000243 </ul>
244 </td>
245 <td><code>file</code></td>
246 </tr>
247 <tr>
248 <td><code>address</code></td>
249 <td>IP address or hostname to bind to when the output method is
250 <code>tcpserver</code> or connect to when the output method is
251 <code>tcpclient</code>. In <code>tcpserver</code> mode the value
252 "<code>*</code>" causes the agent to accept connections on any local
253 address.
254 </td>
255 <td><i>loopback interface</i></td>
256 </tr>
257 <tr>
258 <td><code>port</code></td>
259 <td>Port to bind to when the output method is <code>tcpserver</code> or
260 connect to when the output method is <code>tcpclient</code>. In
261 <code>tcpserver</code> mode the port must be available, which means
262 that if multiple JaCoCo agents should run on the same machine,
263 different ports have to be specified.
264 </td>
265 <td><code>6300</code></td>
266 </tr>
Marc R. Hoffmanncf41fc12012-06-30 00:15:43 +0000267 <tr>
268 <td><code>classdumpdir</code></td>
269 <td>Location relative to the working directory where all class files seen
270 by the agent are dumped to. This can be useful for debugging purposes
271 or in case of dynamically created classes for example when scripting
272 engines are used.
273 </td>
274 <td><i>no dumps</i></td>
275 </tr>
Marc R. Hoffmanne2930e72013-01-08 21:18:35 +0100276 <tr>
277 <td><code>jmx</code></td>
278 <td>If set to <code>true</code> the agent exposes
279 <a href="./api/org/jacoco/agent/rt/IAgent.html">functionality</a> via
280 JMX under the name <code>org.jacoco:type=Runtime</code>.
281 </td>
282 <td><code>false</code></td>
283 </tr>
Evgeny Mandrikov82a92ca2012-01-15 20:25:48 +0000284 </tbody>
285</table>
286
287
288<h2><a name="agent">Task <code>agent</code></a></h2>
289
290<p>
291 If the <code>coverage</code> task is not suitable for your launch target, you
292 might alternatively use the <code>agent</code> task to create the
293 <a href="agent.html">Java agent</a> parameter. The following example defines a
294 Ant property with the name <code>agentvmparam</code> that can be directly used
295 as a Java VM parameter:
296</p>
297
298<pre class="source lang-xml linenums">
299&lt;jacoco:agent property="agentvmparam"/&gt;
300</pre>
301
302<p>
303 This task has the same attributes as the <code>coverage</code> task plus an
304 additional property to specify the target property name:
305</p>
306
307<table class="coverage">
308 <thead>
309 <tr>
310 <td>Attribute</td>
311 <td>Description</td>
312 <td>Default</td>
313 </tr>
314 </thead>
315 <tbody>
316 <tr>
317 <td><code>enabled</code></td>
318 <td>When this variable is set to <code>false</code> the value of <code>property</code> will be set to an empty string, effectively
319 disabling coverage instrumentation for any tasks that used the value.</td>
320 <td><code>true</code></td>
321 </tr>
322 <tr>
323 <td><code>property</code></td>
324 <td>Name of the Ant property to set.</td>
325 <td><i>none (required)</i></td>
326 </tr>
327 <tr>
328 <td colspan="3"><i>All attributes of the <code>coverage</code> task.</i></td>
329 </tr>
330 </tbody>
331</table>
332
333
334<h2><a name="dump">Task <code>dump</code></a></h2>
335
336<p>
337 This task allows to remotely collect execution data from another JVM without
338 stopping it. For example:
339</p>
340
341<pre class="source lang-xml linenums">
342&lt;jacoco:dump address="server.example.com" reset="true" destfile="remote.exec"/&gt;
343</pre>
344
345<p>
346 Remote dumps are usefull for long running Java processes like application
347 servers.
348</p>
349
350<p class="hint">
351 The target JVM needs to have a <a href="agent.html">JaCoCo agent</a>
352 configured with <code>output</code> mode <code>tcpserver</code>. See
353 <a href="#coverage"><code>coverage</code></a> and
354 <a href="#agent"><code>agent</code></a> tasks above.
355</p>
356
357<p>
358 The <code>dump</code> task has the following attributes:
359</p>
360
361<table class="coverage">
362 <thead>
363 <tr>
364 <td>Attribute</td>
365 <td>Description</td>
366 <td>Default</td>
367 </tr>
368 </thead>
369 <tbody>
370 <tr>
371 <td><code>address</code></td>
372 <td>Target IP address or DNS name.</td>
373 <td><code>localhost</code></td>
374 </tr>
375 <tr>
376 <td><code>port</code></td>
377 <td>Target TCP port.</td>
378 <td><code>6300</code></td>
379 </tr>
380 <tr>
Marc R. Hoffmanna3a1f5a2013-11-10 14:05:33 +0100381 <td><code>retryCount</code></td>
382 <td>Number of retries which the goal will attempt to establish a
383 connection. This can be used to wait until the target JVM is
384 successfully launched.</td>
385 <td><code>10</code></td>
386 </tr>
387 <tr>
Evgeny Mandrikov82a92ca2012-01-15 20:25:48 +0000388 <td><code>dump</code></td>
389 <td>Flag whether execution data should be dumped.</td>
390 <td><code>true</code></td>
391 </tr>
392 <tr>
393 <td><code>reset</code></td>
394 <td>Flag whether execution data should be reset in the target agent after
395 the dump.</td>
396 <td><code>false</code></td>
397 </tr>
398 <tr>
399 <td><code>destfile</code></td>
400 <td>File location to write the collected execution data to.</td>
401 <td><i>none (required if dump=true)</i></td>
402 </tr>
403 <tr>
404 <td><code>append</code></td>
405 <td>If set to <code>true</code> and the execution data file already
406 exists, coverage data is appended to the existing file. If set to
407 <code>false</code>, an existing execution data file will be replaced.
408 </td>
409 <td><code>true</code></td>
410 </tr>
411 </tbody>
412</table>
413
414
415<h2><a name="merge">Task <code>merge</code></a></h2>
416
417<p>
418 This task can be used to merge the execution data from multiple test runs
419 into a single data store.
420</p>
421
422<pre class="source lang-xml linenums">
423&lt;jacoco:merge destfile="merged.exec"&gt;
424 &lt;fileset dir="executionData" includes="*.exec"/&gt;
425&lt;/jacoco:merge&gt;
426</pre>
427
428<p>
429 The task definition can contain any number of resource collection types and
430 has the following mandatory attribute:
431</p>
432
433<table class="coverage">
434 <thead>
435 <tr>
436 <td>Attribute</td>
437 <td>Description</td>
438 <td>Default</td>
439 </tr>
440 </thead>
441 <tbody>
442 <tr>
443 <td><code>destfile</code></td>
444 <td>File location to write the merged execution data to.</td>
445 <td><i>none (required)</i></td>
446 </tr>
447 </tbody>
448</table>
449
450
451<h2><a name="report">Task <code>report</code></a></h2>
452
453<p>
454 Finally different reports can be created with the <code>report</code> task.
455 A report task declaration consists of different sections, two specify the
456 input data, additional ones specify the output formats:
457</p>
458
459<pre class="source lang-xml linenums">
460&lt;jacoco:report&gt;
461
462 &lt;executiondata&gt;
463 &lt;file file="jacoco.exec"/&gt;
464 &lt;/executiondata&gt;
465
466 &lt;structure name="Example Project"&gt;
467 &lt;classfiles&gt;
468 &lt;fileset dir="classes"/&gt;
469 &lt;/classfiles&gt;
470 &lt;sourcefiles encoding="UTF-8"&gt;
471 &lt;fileset dir="src"/&gt;
472 &lt;/sourcefiles&gt;
473 &lt;/structure&gt;
474
475 &lt;html destdir="report"/&gt;
476
477&lt;/jacoco:report&gt;
478</pre>
479
480<p>
481 As you can see from the example above the <code>report</code> task is based
482 on several nested elements:
483</p>
484
485<h3>Element <code>executiondata</code></h3>
486
487<p>
488 Within this element Ant resources and resource collections can be specified,
489 that represent JaCoCo execution data files. If more than one execution data
490 file is specified, execution data is combined. A particular piece of code is
491 considered executed when it is marked as such in any of the input files.
492</p>
493
494<h3>Element <code>structure</code></h3>
495
496<p>
497 This element defines the report structure. It might contain the following
498 nested elements:
499</p>
500
501<ul>
502 <li><code>classfiles</code>: Container element for Ant resources and resource
Marc R. Hoffmannfc340a22013-03-22 11:13:24 +0100503 collections that can specify Java class files, archive files (jar, war, ear
504 etc. or Pack200) or folders containing class files. Archives and folders are
Evgeny Mandrikov82a92ca2012-01-15 20:25:48 +0000505 searched recursively for class files.</li>
506 <li><code>sourcefiles</code>: Optional container element for Ant resources and
507 resource collections that specify corresponding source files. If source
Marc R. Hoffmann8b5d6a32012-01-18 20:24:45 +0000508 files are specified, some report formats include highlighted source code.
509 Source files can be specified as individual files or as source directories.</li>
Evgeny Mandrikov82a92ca2012-01-15 20:25:48 +0000510</ul>
511
512<p>
513 The <code>sourcefiles</code> element has these optional attributes:
514</p>
515
516<table class="coverage">
517 <thead>
518 <tr>
519 <td>Attribute</td>
520 <td>Description</td>
521 <td>Default</td>
522 </tr>
523 </thead>
524 <tbody>
525 <tr>
526 <td><code>encoding</code></td>
527 <td>Character encoding of the source files.</td>
528 <td>Platform default encoding</td>
529 </tr>
530 <tr>
531 <td><code>tabwidth</code></td>
532 <td>Number of whitespace characters that represent a tab character.</td>
533 <td>4 characters</td>
534 </tr>
535 </tbody>
536</table>
537
Marc R. Hoffmann8b5d6a32012-01-18 20:24:45 +0000538<p class="hint">
539 <b>Important:</b> Source file resources must always be specified relative to
540 the respective source folder. If directory resources are given, they must
541 directly point to source folders. Otherwise source lookup will not succeed.
542</p>
543
Evgeny Mandrikov82a92ca2012-01-15 20:25:48 +0000544<p>
545 Note that the <code>classfiles</code> and <code>sourcefiles</code> elements
546 accept any
547 <a href="http://ant.apache.org/manual/Types/resources.html#collection">Ant
548 resource collection</a>. Therefore also filtering the class file set is
549 possible and allows to narrow the scope of the report, for example:
550</p>
551
552<pre class="source lang-xml linenums">
553&lt;classfiles&gt;
554 &lt;fileset dir="classes"&gt;
555 &lt;include name="org/jacoco/examples/important/**/*.class"/&gt;
556 &lt;/fileset&gt;
557&lt;/classfiles&gt;
558</pre>
559
560<p class="hint">
561 <b>Performance Warning:</b> Although it is technically possible and sometimes
562 convenient to use Ant's <code>zipfileset</code> to specify class or source
563 files, this resource type has poor performance characteristics and comes with
564 an huge memory overhead especially for large scale projects.
565</p>
566
567<p>
568 The structure can be refined with a hierarchy of <code>group</code> elements.
569 This way the coverage report can reflect different modules of a software
570 project. For each group element the corresponding class and source files can
571 be specified separately. For example:
572</p>
573
574<pre class="source lang-xml linenums">
575&lt;structure name="Example Project"&gt;
576 &lt;group name="Server"&gt;
577 &lt;classfiles&gt;
578 &lt;fileset dir="${workspace.dir}/org.jacoco.example.server/classes"/&gt;
579 &lt;/classfiles&gt;
580 &lt;sourcefiles&gt;
581 &lt;fileset dir="${workspace.dir}/org.jacoco.example.server/src"/&gt;
582 &lt;/sourcefiles&gt;
583 &lt;/group&gt;
584 &lt;group name="Client"&gt;
585 &lt;classfiles&gt;
586 &lt;fileset dir="${workspace.dir}/org.jacoco.example.client/classes"/&gt;
587 &lt;/classfiles&gt;
588 &lt;sourcefiles&gt;
589 &lt;fileset dir="${workspace.dir}/org.jacoco.example.client/src"/&gt;
590 &lt;/sourcefiles&gt;
591 &lt;/group&gt;
592
593 ...
594
595&lt;/structure&gt;
596</pre>
597
598<p>
599 Both <code>structure</code> and <code>group</code> elements have the following
600 mandatory attribute:
601</p>
602
603<table class="coverage">
604 <thead>
605 <tr>
606 <td>Attribute</td>
607 <td>Description</td>
608 <td>Default</td>
609 </tr>
610 </thead>
611 <tbody>
612 <tr>
613 <td><code>name</code></td>
614 <td>Name of the structure or group.</td>
615 <td><i>none (required)</i></td>
616 </tr>
617 </tbody>
618</table>
619
620<h3>Element <code>html</code></h3>
621
622<p>
623 Create a multi-page report in HTML format. The report can either be written as
624 multiple files into a directory or compressed into a single ZIP file.
625</p>
626
627<table class="coverage">
628 <thead>
629 <tr>
630 <td>Attribute</td>
631 <td>Description</td>
632 <td>Default</td>
633 </tr>
634 </thead>
635 <tbody>
636 <tr>
637 <td><code>destdir</code></td>
638 <td>Directory to create the report in. Either this property or
639 <code>destfile</code> has to be supplied.</td>
640 <td><i>none (required)</i></td>
641 </tr>
642 <tr>
643 <td><code>destfile</code></td>
644 <td>Zip file to create the report in. Either this property or
645 <code>destdir</code> has to be supplied.</td>
646 <td><i>none (required)</i></td>
647 </tr>
648 <tr>
649 <td><code>footer</code></td>
650 <td>Footer text for each report page.</td>
651 <td><i>no footer</i></td>
652 </tr>
653 <tr>
654 <td><code>encoding</code></td>
655 <td>Character encoding of generated HTML pages.</td>
656 <td><code>UTF-8</code></td>
657 </tr>
658 <tr>
659 <td><code>locale</code></td>
Marc R. Hoffmannd4ef46a2015-03-27 08:15:40 +0100660 <td>Locale specified as ISO code (en, fr, jp, ...) used for number
661 formating. Locale country and variant can be separated with an underscore
662 (de_CH).</td>
Evgeny Mandrikov82a92ca2012-01-15 20:25:48 +0000663 <td><i>platform locale</i></td>
664 </tr>
665 </tbody>
666</table>
667
668<h3>Element <code>xml</code></h3>
669
670<p>
671 Create a single-file report in XML format.
672</p>
673
674<table class="coverage">
675 <thead>
676 <tr>
677 <td>Attribute</td>
678 <td>Description</td>
679 <td>Default</td>
680 </tr>
681 </thead>
682 <tbody>
683 <tr>
684 <td><code>destfile</code></td>
685 <td>Location to write the report file to.</td>
686 <td><i>none (required)</i></td>
687 </tr>
688 <tr>
689 <td><code>encoding</code></td>
690 <td>Encoding of the generated XML document.</td>
691 <td><code>UTF-8</code></td>
692 </tr>
693 </tbody>
694</table>
695
696<h3>Element <code>csv</code></h3>
697
698<p>
699 Create single-file report in CSV format.
700</p>
701
702<table class="coverage">
703 <thead>
704 <tr>
705 <td>Attribute</td>
706 <td>Description</td>
707 <td>Default</td>
708 </tr>
709 </thead>
710 <tbody>
711 <tr>
712 <td><code>destfile</code></td>
713 <td>Location to write the report file to.</td>
714 <td><i>none (required)</i></td>
715 </tr>
716 <tr>
717 <td><code>encoding</code></td>
718 <td>Encoding of the generated CSV document.</td>
719 <td><code>UTF-8</code></td>
720 </tr>
721 </tbody>
722</table>
723
Marc R. Hoffmann55fae172013-03-20 11:55:53 +0100724<h3>Element <code>check</code></h3>
725
726<p>
727 This report type does not actually create a report. It checks coverage
728 counters and reports violations of configured rules. Every rule is applied to
729 elements of a given type (class, package, bundle, etc.) and has a list of
730 limits which are checked for every element. The following example checks that
731 for every package the line coverage is at least 80% and no class is missed:
732</p>
733
734<pre class="source lang-xml linenums">
735&lt;check&gt;
Marc R. Hoffmanncc075562013-05-25 15:39:12 +0200736 &lt;rule element="PACKAGE"&gt;
737 &lt;limit counter="LINE" value="COVEREDRATIO" minimum="0.80"/&gt;
738 &lt;limit counter="CLASS" value="MISSEDCOUNT" maximum="0"/&gt;
Marc R. Hoffmann55fae172013-03-20 11:55:53 +0100739 &lt;/rule&gt;
740&lt;/check&gt;
741</pre>
742
743<p>
744 The <code>check</code> element has the following attributes:
745</p>
746
747<table class="coverage">
748 <thead>
749 <tr>
750 <td>Attribute</td>
751 <td>Description</td>
752 <td>Default</td>
753 </tr>
754 </thead>
755 <tbody>
756 <tr>
757 <td><code>rules</code></td>
758 <td>List of rules to check.</td>
759 <td><i>none</i></td>
760 </tr>
761 <tr>
762 <td><code>failonviolation</code></td>
763 <td>Specifies whether build should fail in case of rule violations.</td>
764 <td><code>true</code></td>
765 </tr>
766 <tr>
767 <td><code>violationsproperty</code></td>
768 <td>The name of an Ant property which is filled with the violation
Marc R. Hoffmanncc075562013-05-25 15:39:12 +0200769 messages.</td>
Marc R. Hoffmann55fae172013-03-20 11:55:53 +0100770 <td><i>none</i></td>
771 </tr>
772 </tbody>
773</table>
774
775<p>
776 Within the <code>check</code> element any number of <code>rule</code> elements
777 can be nested:
778</p>
779
780<table class="coverage">
781 <thead>
782 <tr>
783 <td>Attribute</td>
784 <td>Description</td>
785 <td>Default</td>
786 </tr>
787 </thead>
788 <tbody>
789 <tr>
790 <td><code>element</code></td>
791 <td>The elements this rule applies to. Possible values are
792 <code>BUNLDE</code>, <code>PACKAGE</code>, <code>CLASS</code>,
793 <code>SOURCEFILE</code> and <code>METHOD</code>.</td>
794 <td><code>BUNLDE</code></td>
795 </tr>
796 <tr>
797 <td><code>includes</code></td>
798 <td>A list of element names that should be checked. The list entries are
799 separated by a colon (:) and may use wildcard characters (* and ?).</td>
800 <td><code>*</code></td>
801 </tr>
802 <tr>
803 <td><code>excludes</code></td>
804 <td>A list of element names that should not be checked. The list entries
805 are separated by a colon (:) and may use wildcard characters (* and ?).</td>
806 <td><i>empty (no excludes)</i></td>
807 </tr>
808 <tr>
809 <td><code>limits</code></td>
Marc R. Hoffmanncc075562013-05-25 15:39:12 +0200810 <td>List of limits to check.</td>
Marc R. Hoffmann55fae172013-03-20 11:55:53 +0100811 <td><i>none</i></td>
812 </tr>
813 </tbody>
814</table>
815
816<p>
817 Within the <code>rule</code> element any number of <code>limit</code> elements
818 can be nested:
819</p>
820
821<table class="coverage">
822 <thead>
823 <tr>
824 <td>Attribute</td>
825 <td>Description</td>
826 <td>Default</td>
827 </tr>
828 </thead>
829 <tbody>
830 <tr>
831 <td><code>counter</code></td>
832 <td>The <a href="counters.html">counter</a> which should be checked.
833 Possible options are <code>INSTRUCTION</code>, <code>LINE</code>,
834 <code>BRANCH</code>, <code>COMPLEXITY</code>, <code>METHOD</code> and
835 <code>CLASS</code>.</td>
836 <td><code>INSTRUCTION</code></td>
837 </tr>
838 <tr>
839 <td><code>value</code></td>
840 <td>The counter value that should be checked. Possible options are
841 <code>TOTALCOUNT</code>, <code>MISSEDCOUNT</code>,
842 <code>COVEREDCOUNT</code>, <code>MISSEDRATIO</code> and
Marc R. Hoffmanncc075562013-05-25 15:39:12 +0200843 <code>COVEREDRATIO</code>.</td>
Marc R. Hoffmann55fae172013-03-20 11:55:53 +0100844 <td><code>COVEREDRATIO</code></td>
845 </tr>
846 <tr>
847 <td><code>minimum</code></td>
Marc R. Hoffmanncc075562013-05-25 15:39:12 +0200848 <td>Expected minmimum value. If the minimum refers to a ratio the range is
849 from 0.0 to 1.0 where the number of decimal places will also determine
850 the precision in error messages.</td>
Marc R. Hoffmann55fae172013-03-20 11:55:53 +0100851 <td><i>none</i></td>
852 </tr>
853 <tr>
854 <td><code>maximum</code></td>
Marc R. Hoffmanncc075562013-05-25 15:39:12 +0200855 <td>Expected maximum value.</td>
Marc R. Hoffmann55fae172013-03-20 11:55:53 +0100856 <td><i>none</i></td>
857 </tr>
858 </tbody>
859</table>
Marc R. Hoffmann235a09e2012-12-23 15:57:16 +0100860
861<h2><a name="instrument">Task <code>instrument</code></a></h2>
862
Marc R. Hoffmann146716a2013-01-14 13:26:36 +0100863<p class="hint">
864 <b>Warning:</b> The preferred way for code coverage analysis with JaCoCo is
865 on-the-fly instrumentation. Offline instrumentation has several drawbacks and
866 should only be used if a specific scenario explicitly requires this mode.
867 Please consult <a href="offline.html">documentation</a> about offline
868 instrumentation before using this mode.
869</p>
870
Marc R. Hoffmann235a09e2012-12-23 15:57:16 +0100871<p>
872 This task is used for <a href="offline.html">offline instrumentation</a> of
Marc R. Hoffmannadf2bf62012-12-28 20:56:45 +0100873 class files. The task takes a set of files and writes instrumented
874 versions to a specified location. The task takes any file type as input. Java
Marc R. Hoffmannfc340a22013-03-22 11:13:24 +0100875 class files are instrumented. Archives (jar, war, ear etc. or Pack200) are
876 searched recursively for class files which then get instrumented. All other
877 files are copied without modification.
Marc R. Hoffmann235a09e2012-12-23 15:57:16 +0100878</p>
879
880<pre class="source lang-xml linenums">
James Anderson830d26d2013-01-26 09:00:32 -0600881&lt;jacoco:instrument destdir="target/classes-instr"&gt;
Marc R. Hoffmann235a09e2012-12-23 15:57:16 +0100882 &lt;fileset dir="target/classes" includes="**/*.class"/&gt;
883&lt;/jacoco:instrument&gt;
884</pre>
885
886<p>
887 The task definition can contain any number of resource collection types and
888 has the following mandatory attribute:
889</p>
890
891<table class="coverage">
892 <thead>
893 <tr>
894 <td>Attribute</td>
895 <td>Description</td>
896 <td>Default</td>
897 </tr>
898 </thead>
899 <tbody>
900 <tr>
901 <td><code>destdir</code></td>
Marc R. Hoffmannadf2bf62012-12-28 20:56:45 +0100902 <td>Directory location to write the instrumented files to.</td>
Marc R. Hoffmann235a09e2012-12-23 15:57:16 +0100903 <td><i>none (required)</i></td>
904 </tr>
Marc R. Hoffmann39d48af2014-02-22 10:26:53 +0100905 <tr>
906 <td><code>removesignatures</code></td>
907 <td>If set to <code>true</code> all signature related information is
908 stripped from JARs. This is typically necessary as instrumentation
909 breaks the signatures of the original class files.</td>
910 <td><code>true</code></td>
911 </tr>
Marc R. Hoffmann235a09e2012-12-23 15:57:16 +0100912 </tbody>
913</table>
914
Evgeny Mandrikov82a92ca2012-01-15 20:25:48 +0000915</div>
916<div class="footer">
917 <span class="right"><a href="@jacoco.home.url@">JaCoCo</a> @qualified.bundle.version@</span>
918 <a href="license.html">Copyright</a> &copy; @copyright.years@ Mountainminds GmbH &amp; Co. KG and Contributors
919</div>
920
921</body>
922</html>