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#d0e1192">1. Instal
ling the <span class="application">Ant</span> task</a></span></dt><dt><span clas
s="sect1"><a href="anttask.html#d0e1230">2. Modifying build.xml</a></span></dt><
dt><span class="sect1"><a href="anttask.html#d0e1301">3. Executing the task</a><
/span></dt><dt><span class="sect1"><a href="anttask.html#d0e1326">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#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> |
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="d0e1192"></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="d0e1205"></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="d0e1230"></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="d0e1243"></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="d0e1301"></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="d0e1314"></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="d0e1326"></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="d0e1339"></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. |
97 For example, you might use a fileset to specify that all of the jar files
in a directory | 97 For example, you might use a fileset to specify that all of the jar files
in a directory |
98 should be analyzed. | 98 should be analyzed. |
99 </p></dd><dt><span class="term"><code class="literal">auxClasspath</code>
</span></dt><dd><p> | 99 </p></dd><dt><span class="term"><code class="literal">auxClasspath</code>
</span></dt><dd><p> |
100 An optional nested element which specifies a classpath (Jar files or dire
ctories) | 100 An optional nested element which specifies a classpath (Jar files or dire
ctories) |
101 containing classes used by the analyzed library or application, but which | 101 containing classes used by the analyzed library or application, but which |
102 you don't want to analyze. It is specified the same way as | 102 you don't want to analyze. It is specified the same way as |
103 <span class="application">Ant</span>'s <code class="literal">classpath</c
ode> element for the Java task. | 103 <span class="application">Ant</span>'s <code class="literal">classpath</c
ode> element for the Java task. |
104 </p></dd><dt><span class="term"><code class="literal">sourcePath</code></
span></dt><dd><p> | 104 </p></dd><dt><span class="term"><code class="literal">sourcePath</code></
span></dt><dd><p> |
105 An optional nested element which specifies a source directory path | 105 An optional nested element which specifies a source directory path |
106 containing source files used to compile the Java code being analyzed. | 106 containing source files used to compile the Java code being analyzed. |
107 By specifying a source path, any generated XML bug output will have | 107 By specifying a source path, any generated XML bug output will have |
108 complete source information, which allows later viewing in the | 108 complete source information, which allows later viewing in the |
109 GUI. | 109 GUI. |
110 </p></dd><dt><span class="term"><code class="literal">home</code></span><
/dt><dd><p> | 110 </p></dd><dt><span class="term"><code class="literal">home</code></span><
/dt><dd><p> |
111 A required attribute. | 111 A required attribute. |
112 It must be set to the name of the directory where <span class="applicatio
n">FindBugs</span> is installed. | 112 It must be set to the name of the directory where <span class="applicatio
n">FindBugs</span> is installed. |
113 </p></dd><dt><span class="term"><code class="literal">quietErrors</code><
/span></dt><dd><p> | 113 </p></dd><dt><span class="term"><code class="literal">quietErrors</code><
/span></dt><dd><p> |
114 An optional boolean attribute. | 114 An optional boolean attribute. |
115 If true, reports of serious analysis errors and missing classes will | 115 If true, reports of serious analysis errors and missing classes will |
116 be suppressed in the <span class="application">FindBugs</span> output. D
efault is false. | 116 be suppressed in the <span class="application">FindBugs</span> output. D
efault is false. |
117 </p></dd><dt><span class="term"><code class="literal">reportLevel</code><
/span></dt><dd><p> | 117 </p></dd><dt><span class="term"><code class="literal">reportLevel</code><
/span></dt><dd><p> |
118 An optional attribute. It specifies | 118 An optional attribute. It specifies |
119 the confidence/priority threshold for reporting issues. If set to "low",
confidence is not used to filter bugs. | 119 the confidence/priority threshold for reporting issues. If set to "low",
confidence is not used to filter bugs. |
120 If set to "medium" (the default), low confidence issues are supressed. | 120 If set to "medium" (the default), low confidence issues are supressed. |
121 If set to "high", only high confidence bugs are reported. | 121 If set to "high", only high confidence bugs are reported. |
122 </p></dd><dt><span class="term"><code class="literal">output</code></span
></dt><dd><p> | 122 </p></dd><dt><span class="term"><code class="literal">output</code></span
></dt><dd><p> |
123 Optional attribute. | 123 Optional attribute. |
124 It specifies the output format. If set to "xml" (the default), output | 124 It specifies the output format. If set to "xml" (the default), output |
125 is in XML format. | 125 is in XML format. |
126 If set to "xml:withMessages", output is in XML format augmented with | 126 If set to "xml:withMessages", output is in XML format augmented with |
127 human-readable messages. (You should use this format if you plan | 127 human-readable messages. (You should use this format if you plan |
128 to generate a report using an XSL stylesheet.) | 128 to generate a report using an XSL stylesheet.) |
129 If set to "html", output is in HTML formatted (default stylesheet is defa
ult.xsl). | 129 If set to "html", output is in HTML formatted (default stylesheet is defa
ult.xsl). |
130 If set to "text", output is in ad-hoc text format. | 130 If set to "text", output is in ad-hoc text format. |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 </p></dd><dt><span class="term"><code class="literal">failOnError</code><
/span></dt><dd><p> | 195 </p></dd><dt><span class="term"><code class="literal">failOnError</code><
/span></dt><dd><p> |
196 Optional boolean attribute. Whether to abort the build process if there
is an | 196 Optional boolean attribute. Whether to abort the build process if there
is an |
197 error running <span class="application">FindBugs</span>. Defaults to "fal
se" | 197 error running <span class="application">FindBugs</span>. Defaults to "fal
se" |
198 </p></dd><dt><span class="term"><code class="literal">errorProperty</code
></span></dt><dd><p> | 198 </p></dd><dt><span class="term"><code class="literal">errorProperty</code
></span></dt><dd><p> |
199 Optional attribute which specifies the name of a property that | 199 Optional attribute which specifies the name of a property that |
200 will be set to "true" if an error occurs while running <span class="appli
cation">FindBugs</span>. | 200 will be set to "true" if an error occurs while running <span class="appli
cation">FindBugs</span>. |
201 </p></dd><dt><span class="term"><code class="literal">warningsProperty</c
ode></span></dt><dd><p> | 201 </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 | 202 Optional attribute which specifies the name of a property |
203 that will be set to "true" if any warnings are reported by | 203 that will be set to "true" if any warnings are reported by |
204 <span class="application">FindBugs</span> on the analyzed program. | 204 <span class="application">FindBugs</span> on the analyzed program. |
205 </p></dd></dl></div><p> | 205 </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. |
| 207 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). |
| 209 This rationale behind this option is to reuse FindBugs Eclipse pro
ject settings for command |
| 210 line execution. |
| 211 </p></dd></dl></div><p> |
206 | 212 |
207 | 213 |
208 </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> | 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> |
OLD | NEW |