OLD | NEW |
1 <html><head> | 1 <html><head> |
2 <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> | 2 <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> |
3 <title>Chapter 6. Using the FindBugs™ Ant task</title><meta n
ame="generator" content="DocBook XSL Stylesheets V1.76.1"><link rel="home" href=
"index.html" title="FindBugs™ Manual"><link rel="up" href="index.html" tit
le="FindBugs™ Manual"><link rel="prev" href="gui.html" title="Chapter 
;5. Using the FindBugs GUI"><link rel="next" href="eclipse.html" title="Cha
pter 7. Using the FindBugs™ Eclipse plugin"></head><body bgcolor
="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class=
"navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3"
align="center">Chapter 6. Using the <span class="application">FindBugs
</span>™ <span class="application">Ant</span> task</th></tr><tr><td width=
"20%" align="left"><a accesskey="p" href="gui.html">Prev</a> </td><th width
="60%" align="center"> </th><td width="20%" align="right"> <a accesske
y="n" href="eclipse.html">Next</a></td></tr></table><hr></div><div class="chapte
r" title="Chapter 6. Using the FindBugs™ Ant task"><div class="t
itlepage"><div><div><h2 class="title"><a name="anttask"></a>Chapter 6. 
;Using the <span class="application">FindBugs</span>™ <span class="applica
tion">Ant</span> task</h2></div></div></div><div class="toc"><p><b>Table of Cont
ents</b></p><dl><dt><span class="sect1"><a href="anttask.html#d0e1205">1. Instal
ling the <span class="application">Ant</span> task</a></span></dt><dt><span clas
s="sect1"><a href="anttask.html#d0e1243">2. Modifying build.xml</a></span></dt><
dt><span class="sect1"><a href="anttask.html#d0e1314">3. Executing the task</a><
/span></dt><dt><span class="sect1"><a href="anttask.html#d0e1339">4. Parameters<
/a></span></dt></dl></div><p> | 3 <title>Chapter 6. Using the FindBugs™ Ant task</title><meta n
ame="generator" content="DocBook XSL Stylesheets V1.76.1"><link rel="home" href=
"index.html" title="FindBugs™ Manual"><link rel="up" href="index.html" tit
le="FindBugs™ Manual"><link rel="prev" href="gui.html" title="Chapter 
;5. Using the FindBugs GUI"><link rel="next" href="eclipse.html" title="Cha
pter 7. Using the FindBugs™ Eclipse plugin"></head><body bgcolor
="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class=
"navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3"
align="center">Chapter 6. Using the <span class="application">FindBugs
</span>™ <span class="application">Ant</span> task</th></tr><tr><td width=
"20%" align="left"><a accesskey="p" href="gui.html">Prev</a> </td><th width
="60%" align="center"> </th><td width="20%" align="right"> <a accesske
y="n" href="eclipse.html">Next</a></td></tr></table><hr></div><div class="chapte
r" title="Chapter 6. Using the FindBugs™ Ant task"><div class="t
itlepage"><div><div><h2 class="title"><a name="anttask"></a>Chapter 6. 
;Using the <span class="application">FindBugs</span>™ <span class="applica
tion">Ant</span> task</h2></div></div></div><div class="toc"><p><b>Table of Cont
ents</b></p><dl><dt><span class="sect1"><a href="anttask.html#d0e1233">1. Instal
ling the <span class="application">Ant</span> task</a></span></dt><dt><span clas
s="sect1"><a href="anttask.html#d0e1271">2. Modifying build.xml</a></span></dt><
dt><span class="sect1"><a href="anttask.html#d0e1342">3. Executing the task</a><
/span></dt><dt><span class="sect1"><a href="anttask.html#d0e1367">4. Parameters<
/a></span></dt></dl></div><p> |
4 This chapter describes how to integrate <span class="application">FindBugs</span
> into a build script | 4 This chapter describes how to integrate <span class="application">FindBugs</span
> into a build script |
5 for <a class="ulink" href="http://ant.apache.org/" target="_top"><span class="ap
plication">Ant</span></a>, which is a popular Java build | 5 for <a class="ulink" href="http://ant.apache.org/" target="_top"><span class="ap
plication">Ant</span></a>, which is a popular Java build |
6 and deployment tool. Using the <span class="application">FindBugs</span> <span
class="application">Ant</span> task, your build script can | 6 and deployment tool. Using the <span class="application">FindBugs</span> <span
class="application">Ant</span> task, your build script can |
7 automatically run <span class="application">FindBugs</span> on your Java code. | 7 automatically run <span class="application">FindBugs</span> on your Java code. |
8 </p><p> | 8 </p><p> |
9 The <span class="application">Ant</span> task was generously contributed by Mike
Fagan. | 9 The <span class="application">Ant</span> task was generously contributed by Mike
Fagan. |
10 </p><div class="sect1" title="1. Installing the Ant task"><div class="title
page"><div><div><h2 class="title" style="clear: both"><a name="d0e1205"></a>1.&n
bsp;Installing the <span class="application">Ant</span> task</h2></div></div></d
iv><p> | 10 </p><div class="sect1" title="1. Installing the Ant task"><div class="title
page"><div><div><h2 class="title" style="clear: both"><a name="d0e1233"></a>1.&n
bsp;Installing the <span class="application">Ant</span> task</h2></div></div></d
iv><p> |
11 To install the <span class="application">Ant</span> task, simply copy <code clas
s="filename"><em class="replaceable"><code>$FINDBUGS_HOME</code></em>/lib/findbu
gs-ant.jar</code> | 11 To install the <span class="application">Ant</span> task, simply copy <code clas
s="filename"><em class="replaceable"><code>$FINDBUGS_HOME</code></em>/lib/findbu
gs-ant.jar</code> |
12 into the <code class="filename">lib</code> subdirectory of your <span class="app
lication">Ant</span> installation. | 12 into the <code class="filename">lib</code> subdirectory of your <span class="app
lication">Ant</span> installation. |
13 | 13 |
14 </p><div class="note" title="Note" style="margin-left: 0.5in; margin-right: 0.5i
n;"><table border="0" summary="Note"><tr><td rowspan="2" align="center" valign="
top" width="25"><img alt="[Note]" src="note.png"></td><th align="left">Note</th>
</tr><tr><td align="left" valign="top"><p>It is strongly recommended that you us
e the <span class="application">Ant</span> task with the version | 14 </p><div class="note" title="Note" style="margin-left: 0.5in; margin-right: 0.5i
n;"><table border="0" summary="Note"><tr><td rowspan="2" align="center" valign="
top" width="25"><img alt="[Note]" src="note.png"></td><th align="left">Note</th>
</tr><tr><td align="left" valign="top"><p>It is strongly recommended that you us
e the <span class="application">Ant</span> task with the version |
15 of <span class="application">FindBugs</span> it was included with. We do not gu
arantee that the <span class="application">Ant</span> task Jar file | 15 of <span class="application">FindBugs</span> it was included with. We do not gu
arantee that the <span class="application">Ant</span> task Jar file |
16 will work with any version of <span class="application">FindBugs</span> other th
an the one it was included with.</p></td></tr></table></div><p> | 16 will work with any version of <span class="application">FindBugs</span> other th
an the one it was included with.</p></td></tr></table></div><p> |
17 </p></div><div class="sect1" title="2. Modifying build.xml"><div class="tit
lepage"><div><div><h2 class="title" style="clear: both"><a name="d0e1243"></a>2.
Modifying build.xml</h2></div></div></div><p> | 17 </p></div><div class="sect1" title="2. Modifying build.xml"><div class="tit
lepage"><div><div><h2 class="title" style="clear: both"><a name="d0e1271"></a>2.
Modifying build.xml</h2></div></div></div><p> |
18 To incorporate <span class="application">FindBugs</span> into <code class="filen
ame">build.xml</code> (the build script | 18 To incorporate <span class="application">FindBugs</span> into <code class="filen
ame">build.xml</code> (the build script |
19 for <span class="application">Ant</span>), you first need to add a task definiti
on. This should appear as follows: | 19 for <span class="application">Ant</span>), you first need to add a task definiti
on. This should appear as follows: |
20 | 20 |
21 </p><pre class="screen"> | 21 </p><pre class="screen"> |
22 <taskdef name="findbugs" classname="edu.umd.cs.findbugs.anttask.FindBugsTas
k"/> | 22 <taskdef name="findbugs" classname="edu.umd.cs.findbugs.anttask.FindBugsTas
k"/> |
23 </pre><p> | 23 </pre><p> |
24 | 24 |
25 The task definition specifies that when a <code class="literal">findbugs</code>
element is | 25 The task definition specifies that when a <code class="literal">findbugs</code>
element is |
26 seen in <code class="filename">build.xml</code>, it should use the indicated cla
ss to execute the task. | 26 seen in <code class="filename">build.xml</code>, it should use the indicated cla
ss to execute the task. |
27 </p><p> | 27 </p><p> |
(...skipping 21 matching lines...) Expand all Loading... |
49 <em class="replaceable"><code>$FINDBUGS_HOME</code></em>. See <a class="xref" h
ref="installing.html" title="Chapter 2. Installing FindBugs™">Ch
apter 2, <i>Installing <span class="application">FindBugs</span>™</i>
</a>. | 49 <em class="replaceable"><code>$FINDBUGS_HOME</code></em>. See <a class="xref" h
ref="installing.html" title="Chapter 2. Installing FindBugs™">Ch
apter 2, <i>Installing <span class="application">FindBugs</span>™</i>
</a>. |
50 </p><p> | 50 </p><p> |
51 This target will execute <span class="application">FindBugs</span> on <code clas
s="filename">bcel.jar</code>, which is the | 51 This target will execute <span class="application">FindBugs</span> on <code clas
s="filename">bcel.jar</code>, which is the |
52 Jar file produced by BCEL's build script. (By making it depend on the "jar" | 52 Jar file produced by BCEL's build script. (By making it depend on the "jar" |
53 target, we ensure that the library is fully compiled before running <span class=
"application">FindBugs</span> on it.) | 53 target, we ensure that the library is fully compiled before running <span class=
"application">FindBugs</span> on it.) |
54 The output of <span class="application">FindBugs</span> will be saved in XML for
mat to a file called | 54 The output of <span class="application">FindBugs</span> will be saved in XML for
mat to a file called |
55 <code class="filename">bcel-fb.xml</code>. | 55 <code class="filename">bcel-fb.xml</code>. |
56 An auxiliary Jar file, <code class="filename">Regex.jar</code>, is added to the
aux classpath, | 56 An auxiliary Jar file, <code class="filename">Regex.jar</code>, is added to the
aux classpath, |
57 because it is referenced by the main BCEL library. A source path is specified | 57 because it is referenced by the main BCEL library. A source path is specified |
58 so that the saved bug data will have accurate references to the BCEL source code
. | 58 so that the saved bug data will have accurate references to the BCEL source code
. |
59 </p></div><div class="sect1" title="3. Executing the task"><div class="titl
epage"><div><div><h2 class="title" style="clear: both"><a name="d0e1314"></a>3.&
nbsp;Executing the task</h2></div></div></div><p> | 59 </p></div><div class="sect1" title="3. Executing the task"><div class="titl
epage"><div><div><h2 class="title" style="clear: both"><a name="d0e1342"></a>3.&
nbsp;Executing the task</h2></div></div></div><p> |
60 Here is an example of invoking <span class="application">Ant</span> from the com
mand line, using the <code class="literal">findbugs</code> | 60 Here is an example of invoking <span class="application">Ant</span> from the com
mand line, using the <code class="literal">findbugs</code> |
61 target defined above. | 61 target defined above. |
62 | 62 |
63 </p><pre class="screen"> | 63 </p><pre class="screen"> |
64 <code class="prompt">[daveho@noir]$</code> <span class="command"><strong>ant f
indbugs</strong></span> | 64 <code class="prompt">[daveho@noir]$</code> <span class="command"><strong>ant f
indbugs</strong></span> |
65 Buildfile: build.xml | 65 Buildfile: build.xml |
66 | 66 |
67 init: | 67 init: |
68 | 68 |
69 compile: | 69 compile: |
70 | 70 |
71 examples: | 71 examples: |
72 | 72 |
73 jar: | 73 jar: |
74 | 74 |
75 findbugs: | 75 findbugs: |
76 [findbugs] Running FindBugs... | 76 [findbugs] Running FindBugs... |
77 [findbugs] Bugs were found | 77 [findbugs] Bugs were found |
78 [findbugs] Output saved to bcel-fb.xml | 78 [findbugs] Output saved to bcel-fb.xml |
79 | 79 |
80 BUILD SUCCESSFUL | 80 BUILD SUCCESSFUL |
81 Total time: 35 seconds | 81 Total time: 35 seconds |
82 </pre><p> | 82 </pre><p> |
83 | 83 |
84 In this case, because we saved the bug results in an XML file, we can | 84 In this case, because we saved the bug results in an XML file, we can |
85 use the <span class="application">FindBugs</span> GUI to view the results; see <
a class="xref" href="running.html" title="Chapter 4. Running FindBugs&
#8482;">Chapter 4, <i>Running <span class="application">FindBugs</span>T
82;</i></a>. | 85 use the <span class="application">FindBugs</span> GUI to view the results; see <
a class="xref" href="running.html" title="Chapter 4. Running FindBugs&
#8482;">Chapter 4, <i>Running <span class="application">FindBugs</span>T
82;</i></a>. |
86 </p></div><div class="sect1" title="4. Parameters"><div class="titlepage"><
div><div><h2 class="title" style="clear: both"><a name="d0e1339"></a>4. Par
ameters</h2></div></div></div><p>This section describes the parameters that may
be specified when | 86 </p></div><div class="sect1" title="4. Parameters"><div class="titlepage"><
div><div><h2 class="title" style="clear: both"><a name="d0e1367"></a>4. Par
ameters</h2></div></div></div><p>This section describes the parameters that may
be specified when |
87 using the <span class="application">FindBugs</span> task. | 87 using the <span class="application">FindBugs</span> task. |
88 | 88 |
89 </p><div class="variablelist"><dl><dt><span class="term"><code class="literal">c
lass</code></span></dt><dd><p> | 89 </p><div class="variablelist"><dl><dt><span class="term"><code class="literal">c
lass</code></span></dt><dd><p> |
90 A optional nested element specifying which classes to analyze. The <code
class="literal">class</code> | 90 A optional nested element specifying which classes to analyze. The <code
class="literal">class</code> |
91 element must specify a <code class="literal">location</code> attribute wh
ich names the | 91 element must specify a <code class="literal">location</code> attribute wh
ich names the |
92 archive file (jar, zip, etc.), directory, or class file to be analyzed.
Multiple <code class="literal">class</code> | 92 archive file (jar, zip, etc.), directory, or class file to be analyzed.
Multiple <code class="literal">class</code> |
93 elements may be specified as children of a single <code class="literal">f
indbugs</code> element. | 93 elements may be specified as children of a single <code class="literal">f
indbugs</code> element. |
94 </p><p>In addition to or instead of specifying a <code class="literal">cl
ass</code> element, | 94 </p><p>In addition to or instead of specifying a <code class="literal">cl
ass</code> element, |
95 the <span class="application">FindBugs</span> task can contain one or mo
re <code class="literal">fileset</code> element(s) that | 95 the <span class="application">FindBugs</span> task can contain one or mo
re <code class="literal">fileset</code> element(s) that |
96 specify files to be analyzed. | 96 specify files to be analyzed. |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 Set the analysis effort level. The value specified should be | 152 Set the analysis effort level. The value specified should be |
153 one of <code class="literal">min</code>, <code class="literal">def
ault</code>, | 153 one of <code class="literal">min</code>, <code class="literal">def
ault</code>, |
154 or <code class="literal">max</code>. See <a class="xref" href="ru
nning.html#commandLineOptions" title="3. Command-line Options">Section 
;3, “Command-line Options”</a> | 154 or <code class="literal">max</code>. See <a class="xref" href="ru
nning.html#commandLineOptions" title="3. Command-line Options">Section 
;3, “Command-line Options”</a> |
155 for more information about setting the analysis level. | 155 for more information about setting the analysis level. |
156 </p></dd><dt><span class="term"><code class="literal">conserveSpace</c
ode></span></dt><dd><p>Synonym for effort="min".</p></dd><dt><span class="term">
<code class="literal">workHard</code></span></dt><dd><p>Synonym for effort="max"
.</p></dd><dt><span class="term"><code class="literal">visitors</code></span></d
t><dd><p> | 156 </p></dd><dt><span class="term"><code class="literal">conserveSpace</c
ode></span></dt><dd><p>Synonym for effort="min".</p></dd><dt><span class="term">
<code class="literal">workHard</code></span></dt><dd><p>Synonym for effort="max"
.</p></dd><dt><span class="term"><code class="literal">visitors</code></span></d
t><dd><p> |
157 Optional attribute. It specifies a comma-separated list of bug detectors | 157 Optional attribute. It specifies a comma-separated list of bug detectors |
158 which should be run. The bug detectors are specified by their class name
s, | 158 which should be run. The bug detectors are specified by their class name
s, |
159 without any package qualification. By default, all detectors which are | 159 without any package qualification. By default, all detectors which are |
160 not disabled by default are run. | 160 not disabled by default are run. |
161 </p></dd><dt><span class="term"><code class="literal">omitVisitors</code>
</span></dt><dd><p> | 161 </p></dd><dt><span class="term"><code class="literal">omitVisitors</code>
</span></dt><dd><p> |
162 Optional attribute. It is like the <code class="literal">visitors</code>
attribute, | 162 Optional attribute. It specifies a comma-separated list of bug detectors. |
| 163 It is like the <code class="literal">visitors</code> attribute, |
163 except it specifies detectors which will <span class="emphasis"><em>not</
em></span> be run. | 164 except it specifies detectors which will <span class="emphasis"><em>not</
em></span> be run. |
| 165 </p></dd><dt><span class="term"><code class="literal">chooseVisitors</cod
e></span></dt><dd><p> |
| 166 Optional attribute. It specifies a comma-separated list of bug detectors |
| 167 prefixed with "+" or "-" to selectively enable/disable them. |
164 </p></dd><dt><span class="term"><code class="literal">excludeFilter</code
></span></dt><dd><p> | 168 </p></dd><dt><span class="term"><code class="literal">excludeFilter</code
></span></dt><dd><p> |
165 Optional attribute. It specifies the filename of a filter specifying bug
s | 169 Optional attribute. It specifies the filename of a filter specifying bug
s |
166 to exclude from being reported. See <a class="xref" href="filter.html" t
itle="Chapter 8. Filter Files">Chapter 8, <i>Filter Files</i></a>
. | 170 to exclude from being reported. See <a class="xref" href="filter.html" t
itle="Chapter 8. Filter Files">Chapter 8, <i>Filter Files</i></a>
. |
167 </p></dd><dt><span class="term"><code class="literal">includeFilter</code
></span></dt><dd><p> | 171 </p></dd><dt><span class="term"><code class="literal">includeFilter</code
></span></dt><dd><p> |
168 Optional attribute. It specifies the filename of a filter specifying | 172 Optional attribute. It specifies the filename of a filter specifying |
169 which bugs are reported. See <a class="xref" href="filter.html" title="C
hapter 8. Filter Files">Chapter 8, <i>Filter Files</i></a>. | 173 which bugs are reported. See <a class="xref" href="filter.html" title="C
hapter 8. Filter Files">Chapter 8, <i>Filter Files</i></a>. |
170 </p></dd><dt><span class="term"><code class="literal">projectFile</code><
/span></dt><dd><p> | 174 </p></dd><dt><span class="term"><code class="literal">projectFile</code><
/span></dt><dd><p> |
171 Optional attribute. It specifies the name of a project file. | 175 Optional attribute. It specifies the name of a project file. |
172 Project files are created by the <span class="application">FindBugs</span
> GUI, and specify classes, | 176 Project files are created by the <span class="application">FindBugs</span
> GUI, and specify classes, |
173 aux classpath entries, and source directories. By naming a project, | 177 aux classpath entries, and source directories. By naming a project, |
(...skipping 27 matching lines...) Expand all Loading... |
201 </p></dd><dt><span class="term"><code class="literal">warningsProperty</c
ode></span></dt><dd><p> | 205 </p></dd><dt><span class="term"><code class="literal">warningsProperty</c
ode></span></dt><dd><p> |
202 Optional attribute which specifies the name of a property | 206 Optional attribute which specifies the name of a property |
203 that will be set to "true" if any warnings are reported by | 207 that will be set to "true" if any warnings are reported by |
204 <span class="application">FindBugs</span> on the analyzed program. | 208 <span class="application">FindBugs</span> on the analyzed program. |
205 </p></dd><dt><span class="term"><code class="literal">userPreferencesF
ile</code></span></dt><dd><p> | 209 </p></dd><dt><span class="term"><code class="literal">userPreferencesF
ile</code></span></dt><dd><p> |
206 Optional attribute. Set the path of the user preferences file to u
se, which might override some of the options abobe. | 210 Optional attribute. Set the path of the user preferences file to u
se, which might override some of the options abobe. |
207 Specifying <code class="literal">userPreferencesFile</code> as fir
st argument would mean some later | 211 Specifying <code class="literal">userPreferencesFile</code> as fir
st argument would mean some later |
208 options will override them, as last argument would mean they will
override some previous options). | 212 options will override them, as last argument would mean they will
override some previous options). |
209 This rationale behind this option is to reuse FindBugs Eclipse pro
ject settings for command | 213 This rationale behind this option is to reuse FindBugs Eclipse pro
ject settings for command |
210 line execution. | 214 line execution. |
211 </p></dd></dl></div><p> | 215 </p></dd><dt><span class="term"><code class="literal">nested</code><
/span></dt><dd><p> |
| 216 Optional attribute which enables or disables scanning of nested ja
r and zip files found in |
| 217 the list of files and directories to be analyzed. |
| 218 By default, scanning of nested jar/zip files is enabled. |
| 219 </p></dd></dl></div><p> |
212 | 220 |
213 | 221 |
214 </p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigati
on footer"><tr><td width="40%" align="left"><a accesskey="p" href="gui.html">Pre
v</a> </td><td width="20%" align="center"> </td><td width="40%" align=
"right"> <a accesskey="n" href="eclipse.html">Next</a></td></tr><tr><td wid
th="40%" align="left" valign="top">Chapter 5. Using the <span class="a
pplication">FindBugs</span> GUI </td><td width="20%" align="center"><a acce
sskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="t
op"> Chapter 7. Using the <span class="application">FindBugs</spa
n>™ Eclipse plugin</td></tr></table></div></body></html> | 222 </p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigati
on footer"><tr><td width="40%" align="left"><a accesskey="p" href="gui.html">Pre
v</a> </td><td width="20%" align="center"> </td><td width="40%" align=
"right"> <a accesskey="n" href="eclipse.html">Next</a></td></tr><tr><td wid
th="40%" align="left" valign="top">Chapter 5. Using the <span class="a
pplication">FindBugs</span> GUI </td><td width="20%" align="center"><a acce
sskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="t
op"> Chapter 7. Using the <span class="application">FindBugs</spa
n>™ Eclipse plugin</td></tr></table></div></body></html> |
OLD | NEW |