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