blob: d2fc5e021df5438953297616d0db08fb8457d0f4 [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>
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>
Evgeny Mandrikov8c614ba2013-01-09 16:07:13 +0100234 <li><code>none</code>: Do not produce any output.</li>
Evgeny Mandrikov82a92ca2012-01-15 20:25:48 +0000235 </ul>
236 </td>
237 <td><code>file</code></td>
238 </tr>
239 <tr>
240 <td><code>address</code></td>
241 <td>IP address or hostname to bind to when the output method is
242 <code>tcpserver</code> or connect to when the output method is
243 <code>tcpclient</code>. In <code>tcpserver</code> mode the value
244 "<code>*</code>" causes the agent to accept connections on any local
245 address.
246 </td>
247 <td><i>loopback interface</i></td>
248 </tr>
249 <tr>
250 <td><code>port</code></td>
251 <td>Port to bind to when the output method is <code>tcpserver</code> or
252 connect to when the output method is <code>tcpclient</code>. In
253 <code>tcpserver</code> mode the port must be available, which means
254 that if multiple JaCoCo agents should run on the same machine,
255 different ports have to be specified.
256 </td>
257 <td><code>6300</code></td>
258 </tr>
Marc R. Hoffmanncf41fc12012-06-30 00:15:43 +0000259 <tr>
260 <td><code>classdumpdir</code></td>
261 <td>Location relative to the working directory where all class files seen
262 by the agent are dumped to. This can be useful for debugging purposes
263 or in case of dynamically created classes for example when scripting
264 engines are used.
265 </td>
266 <td><i>no dumps</i></td>
267 </tr>
Marc R. Hoffmanne2930e72013-01-08 21:18:35 +0100268 <tr>
269 <td><code>jmx</code></td>
270 <td>If set to <code>true</code> the agent exposes
271 <a href="./api/org/jacoco/agent/rt/IAgent.html">functionality</a> via
272 JMX under the name <code>org.jacoco:type=Runtime</code>.
273 </td>
274 <td><code>false</code></td>
275 </tr>
Evgeny Mandrikov82a92ca2012-01-15 20:25:48 +0000276 </tbody>
277</table>
278
279
280<h2><a name="agent">Task <code>agent</code></a></h2>
281
282<p>
283 If the <code>coverage</code> task is not suitable for your launch target, you
284 might alternatively use the <code>agent</code> task to create the
285 <a href="agent.html">Java agent</a> parameter. The following example defines a
286 Ant property with the name <code>agentvmparam</code> that can be directly used
287 as a Java VM parameter:
288</p>
289
290<pre class="source lang-xml linenums">
291&lt;jacoco:agent property="agentvmparam"/&gt;
292</pre>
293
294<p>
295 This task has the same attributes as the <code>coverage</code> task plus an
296 additional property to specify the target property name:
297</p>
298
299<table class="coverage">
300 <thead>
301 <tr>
302 <td>Attribute</td>
303 <td>Description</td>
304 <td>Default</td>
305 </tr>
306 </thead>
307 <tbody>
308 <tr>
309 <td><code>enabled</code></td>
310 <td>When this variable is set to <code>false</code> the value of <code>property</code> will be set to an empty string, effectively
311 disabling coverage instrumentation for any tasks that used the value.</td>
312 <td><code>true</code></td>
313 </tr>
314 <tr>
315 <td><code>property</code></td>
316 <td>Name of the Ant property to set.</td>
317 <td><i>none (required)</i></td>
318 </tr>
319 <tr>
320 <td colspan="3"><i>All attributes of the <code>coverage</code> task.</i></td>
321 </tr>
322 </tbody>
323</table>
324
325
326<h2><a name="dump">Task <code>dump</code></a></h2>
327
328<p>
329 This task allows to remotely collect execution data from another JVM without
330 stopping it. For example:
331</p>
332
333<pre class="source lang-xml linenums">
334&lt;jacoco:dump address="server.example.com" reset="true" destfile="remote.exec"/&gt;
335</pre>
336
337<p>
338 Remote dumps are usefull for long running Java processes like application
339 servers.
340</p>
341
342<p class="hint">
343 The target JVM needs to have a <a href="agent.html">JaCoCo agent</a>
344 configured with <code>output</code> mode <code>tcpserver</code>. See
345 <a href="#coverage"><code>coverage</code></a> and
346 <a href="#agent"><code>agent</code></a> tasks above.
347</p>
348
349<p>
350 The <code>dump</code> task has the following attributes:
351</p>
352
353<table class="coverage">
354 <thead>
355 <tr>
356 <td>Attribute</td>
357 <td>Description</td>
358 <td>Default</td>
359 </tr>
360 </thead>
361 <tbody>
362 <tr>
363 <td><code>address</code></td>
364 <td>Target IP address or DNS name.</td>
365 <td><code>localhost</code></td>
366 </tr>
367 <tr>
368 <td><code>port</code></td>
369 <td>Target TCP port.</td>
370 <td><code>6300</code></td>
371 </tr>
372 <tr>
373 <td><code>dump</code></td>
374 <td>Flag whether execution data should be dumped.</td>
375 <td><code>true</code></td>
376 </tr>
377 <tr>
378 <td><code>reset</code></td>
379 <td>Flag whether execution data should be reset in the target agent after
380 the dump.</td>
381 <td><code>false</code></td>
382 </tr>
383 <tr>
384 <td><code>destfile</code></td>
385 <td>File location to write the collected execution data to.</td>
386 <td><i>none (required if dump=true)</i></td>
387 </tr>
388 <tr>
389 <td><code>append</code></td>
390 <td>If set to <code>true</code> and the execution data file already
391 exists, coverage data is appended to the existing file. If set to
392 <code>false</code>, an existing execution data file will be replaced.
393 </td>
394 <td><code>true</code></td>
395 </tr>
396 </tbody>
397</table>
398
399
400<h2><a name="merge">Task <code>merge</code></a></h2>
401
402<p>
403 This task can be used to merge the execution data from multiple test runs
404 into a single data store.
405</p>
406
407<pre class="source lang-xml linenums">
408&lt;jacoco:merge destfile="merged.exec"&gt;
409 &lt;fileset dir="executionData" includes="*.exec"/&gt;
410&lt;/jacoco:merge&gt;
411</pre>
412
413<p>
414 The task definition can contain any number of resource collection types and
415 has the following mandatory attribute:
416</p>
417
418<table class="coverage">
419 <thead>
420 <tr>
421 <td>Attribute</td>
422 <td>Description</td>
423 <td>Default</td>
424 </tr>
425 </thead>
426 <tbody>
427 <tr>
428 <td><code>destfile</code></td>
429 <td>File location to write the merged execution data to.</td>
430 <td><i>none (required)</i></td>
431 </tr>
432 </tbody>
433</table>
434
435
436<h2><a name="report">Task <code>report</code></a></h2>
437
438<p>
439 Finally different reports can be created with the <code>report</code> task.
440 A report task declaration consists of different sections, two specify the
441 input data, additional ones specify the output formats:
442</p>
443
444<pre class="source lang-xml linenums">
445&lt;jacoco:report&gt;
446
447 &lt;executiondata&gt;
448 &lt;file file="jacoco.exec"/&gt;
449 &lt;/executiondata&gt;
450
451 &lt;structure name="Example Project"&gt;
452 &lt;classfiles&gt;
453 &lt;fileset dir="classes"/&gt;
454 &lt;/classfiles&gt;
455 &lt;sourcefiles encoding="UTF-8"&gt;
456 &lt;fileset dir="src"/&gt;
457 &lt;/sourcefiles&gt;
458 &lt;/structure&gt;
459
460 &lt;html destdir="report"/&gt;
461
462&lt;/jacoco:report&gt;
463</pre>
464
465<p>
466 As you can see from the example above the <code>report</code> task is based
467 on several nested elements:
468</p>
469
470<h3>Element <code>executiondata</code></h3>
471
472<p>
473 Within this element Ant resources and resource collections can be specified,
474 that represent JaCoCo execution data files. If more than one execution data
475 file is specified, execution data is combined. A particular piece of code is
476 considered executed when it is marked as such in any of the input files.
477</p>
478
479<h3>Element <code>structure</code></h3>
480
481<p>
482 This element defines the report structure. It might contain the following
483 nested elements:
484</p>
485
486<ul>
487 <li><code>classfiles</code>: Container element for Ant resources and resource
Marc R. Hoffmannfc340a22013-03-22 11:13:24 +0100488 collections that can specify Java class files, archive files (jar, war, ear
489 etc. or Pack200) or folders containing class files. Archives and folders are
Evgeny Mandrikov82a92ca2012-01-15 20:25:48 +0000490 searched recursively for class files.</li>
491 <li><code>sourcefiles</code>: Optional container element for Ant resources and
492 resource collections that specify corresponding source files. If source
Marc R. Hoffmann8b5d6a32012-01-18 20:24:45 +0000493 files are specified, some report formats include highlighted source code.
494 Source files can be specified as individual files or as source directories.</li>
Evgeny Mandrikov82a92ca2012-01-15 20:25:48 +0000495</ul>
496
497<p>
498 The <code>sourcefiles</code> element has these optional attributes:
499</p>
500
501<table class="coverage">
502 <thead>
503 <tr>
504 <td>Attribute</td>
505 <td>Description</td>
506 <td>Default</td>
507 </tr>
508 </thead>
509 <tbody>
510 <tr>
511 <td><code>encoding</code></td>
512 <td>Character encoding of the source files.</td>
513 <td>Platform default encoding</td>
514 </tr>
515 <tr>
516 <td><code>tabwidth</code></td>
517 <td>Number of whitespace characters that represent a tab character.</td>
518 <td>4 characters</td>
519 </tr>
520 </tbody>
521</table>
522
Marc R. Hoffmann8b5d6a32012-01-18 20:24:45 +0000523<p class="hint">
524 <b>Important:</b> Source file resources must always be specified relative to
525 the respective source folder. If directory resources are given, they must
526 directly point to source folders. Otherwise source lookup will not succeed.
527</p>
528
Evgeny Mandrikov82a92ca2012-01-15 20:25:48 +0000529<p>
530 Note that the <code>classfiles</code> and <code>sourcefiles</code> elements
531 accept any
532 <a href="http://ant.apache.org/manual/Types/resources.html#collection">Ant
533 resource collection</a>. Therefore also filtering the class file set is
534 possible and allows to narrow the scope of the report, for example:
535</p>
536
537<pre class="source lang-xml linenums">
538&lt;classfiles&gt;
539 &lt;fileset dir="classes"&gt;
540 &lt;include name="org/jacoco/examples/important/**/*.class"/&gt;
541 &lt;/fileset&gt;
542&lt;/classfiles&gt;
543</pre>
544
545<p class="hint">
546 <b>Performance Warning:</b> Although it is technically possible and sometimes
547 convenient to use Ant's <code>zipfileset</code> to specify class or source
548 files, this resource type has poor performance characteristics and comes with
549 an huge memory overhead especially for large scale projects.
550</p>
551
552<p>
553 The structure can be refined with a hierarchy of <code>group</code> elements.
554 This way the coverage report can reflect different modules of a software
555 project. For each group element the corresponding class and source files can
556 be specified separately. For example:
557</p>
558
559<pre class="source lang-xml linenums">
560&lt;structure name="Example Project"&gt;
561 &lt;group name="Server"&gt;
562 &lt;classfiles&gt;
563 &lt;fileset dir="${workspace.dir}/org.jacoco.example.server/classes"/&gt;
564 &lt;/classfiles&gt;
565 &lt;sourcefiles&gt;
566 &lt;fileset dir="${workspace.dir}/org.jacoco.example.server/src"/&gt;
567 &lt;/sourcefiles&gt;
568 &lt;/group&gt;
569 &lt;group name="Client"&gt;
570 &lt;classfiles&gt;
571 &lt;fileset dir="${workspace.dir}/org.jacoco.example.client/classes"/&gt;
572 &lt;/classfiles&gt;
573 &lt;sourcefiles&gt;
574 &lt;fileset dir="${workspace.dir}/org.jacoco.example.client/src"/&gt;
575 &lt;/sourcefiles&gt;
576 &lt;/group&gt;
577
578 ...
579
580&lt;/structure&gt;
581</pre>
582
583<p>
584 Both <code>structure</code> and <code>group</code> elements have the following
585 mandatory attribute:
586</p>
587
588<table class="coverage">
589 <thead>
590 <tr>
591 <td>Attribute</td>
592 <td>Description</td>
593 <td>Default</td>
594 </tr>
595 </thead>
596 <tbody>
597 <tr>
598 <td><code>name</code></td>
599 <td>Name of the structure or group.</td>
600 <td><i>none (required)</i></td>
601 </tr>
602 </tbody>
603</table>
604
605<h3>Element <code>html</code></h3>
606
607<p>
608 Create a multi-page report in HTML format. The report can either be written as
609 multiple files into a directory or compressed into a single ZIP file.
610</p>
611
612<table class="coverage">
613 <thead>
614 <tr>
615 <td>Attribute</td>
616 <td>Description</td>
617 <td>Default</td>
618 </tr>
619 </thead>
620 <tbody>
621 <tr>
622 <td><code>destdir</code></td>
623 <td>Directory to create the report in. Either this property or
624 <code>destfile</code> has to be supplied.</td>
625 <td><i>none (required)</i></td>
626 </tr>
627 <tr>
628 <td><code>destfile</code></td>
629 <td>Zip file to create the report in. Either this property or
630 <code>destdir</code> has to be supplied.</td>
631 <td><i>none (required)</i></td>
632 </tr>
633 <tr>
634 <td><code>footer</code></td>
635 <td>Footer text for each report page.</td>
636 <td><i>no footer</i></td>
637 </tr>
638 <tr>
639 <td><code>encoding</code></td>
640 <td>Character encoding of generated HTML pages.</td>
641 <td><code>UTF-8</code></td>
642 </tr>
643 <tr>
644 <td><code>locale</code></td>
645 <td>Locale specified as ISO code (en, fr, jp, ...) used for number formating.</td>
646 <td><i>platform locale</i></td>
647 </tr>
648 </tbody>
649</table>
650
651<h3>Element <code>xml</code></h3>
652
653<p>
654 Create a single-file report in XML format.
655</p>
656
657<table class="coverage">
658 <thead>
659 <tr>
660 <td>Attribute</td>
661 <td>Description</td>
662 <td>Default</td>
663 </tr>
664 </thead>
665 <tbody>
666 <tr>
667 <td><code>destfile</code></td>
668 <td>Location to write the report file to.</td>
669 <td><i>none (required)</i></td>
670 </tr>
671 <tr>
672 <td><code>encoding</code></td>
673 <td>Encoding of the generated XML document.</td>
674 <td><code>UTF-8</code></td>
675 </tr>
676 </tbody>
677</table>
678
679<h3>Element <code>csv</code></h3>
680
681<p>
682 Create single-file report in CSV format.
683</p>
684
685<table class="coverage">
686 <thead>
687 <tr>
688 <td>Attribute</td>
689 <td>Description</td>
690 <td>Default</td>
691 </tr>
692 </thead>
693 <tbody>
694 <tr>
695 <td><code>destfile</code></td>
696 <td>Location to write the report file to.</td>
697 <td><i>none (required)</i></td>
698 </tr>
699 <tr>
700 <td><code>encoding</code></td>
701 <td>Encoding of the generated CSV document.</td>
702 <td><code>UTF-8</code></td>
703 </tr>
704 </tbody>
705</table>
706
Marc R. Hoffmann235a09e2012-12-23 15:57:16 +0100707
708<h2><a name="instrument">Task <code>instrument</code></a></h2>
709
Marc R. Hoffmann146716a2013-01-14 13:26:36 +0100710<p class="hint">
711 <b>Warning:</b> The preferred way for code coverage analysis with JaCoCo is
712 on-the-fly instrumentation. Offline instrumentation has several drawbacks and
713 should only be used if a specific scenario explicitly requires this mode.
714 Please consult <a href="offline.html">documentation</a> about offline
715 instrumentation before using this mode.
716</p>
717
Marc R. Hoffmann235a09e2012-12-23 15:57:16 +0100718<p>
719 This task is used for <a href="offline.html">offline instrumentation</a> of
Marc R. Hoffmannadf2bf62012-12-28 20:56:45 +0100720 class files. The task takes a set of files and writes instrumented
721 versions to a specified location. The task takes any file type as input. Java
Marc R. Hoffmannfc340a22013-03-22 11:13:24 +0100722 class files are instrumented. Archives (jar, war, ear etc. or Pack200) are
723 searched recursively for class files which then get instrumented. All other
724 files are copied without modification.
Marc R. Hoffmann235a09e2012-12-23 15:57:16 +0100725</p>
726
727<pre class="source lang-xml linenums">
James Anderson830d26d2013-01-26 09:00:32 -0600728&lt;jacoco:instrument destdir="target/classes-instr"&gt;
Marc R. Hoffmann235a09e2012-12-23 15:57:16 +0100729 &lt;fileset dir="target/classes" includes="**/*.class"/&gt;
730&lt;/jacoco:instrument&gt;
731</pre>
732
733<p>
734 The task definition can contain any number of resource collection types and
735 has the following mandatory attribute:
736</p>
737
738<table class="coverage">
739 <thead>
740 <tr>
741 <td>Attribute</td>
742 <td>Description</td>
743 <td>Default</td>
744 </tr>
745 </thead>
746 <tbody>
747 <tr>
748 <td><code>destdir</code></td>
Marc R. Hoffmannadf2bf62012-12-28 20:56:45 +0100749 <td>Directory location to write the instrumented files to.</td>
Marc R. Hoffmann235a09e2012-12-23 15:57:16 +0100750 <td><i>none (required)</i></td>
751 </tr>
752 </tbody>
753</table>
754
Evgeny Mandrikov82a92ca2012-01-15 20:25:48 +0000755</div>
756<div class="footer">
757 <span class="right"><a href="@jacoco.home.url@">JaCoCo</a> @qualified.bundle.version@</span>
758 <a href="license.html">Copyright</a> &copy; @copyright.years@ Mountainminds GmbH &amp; Co. KG and Contributors
759</div>
760
761</body>
762</html>