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