?? anttask.html
字號:
<html><head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Chapter 6. Using the FindBugs™ Ant task</title><meta name="generator" content="DocBook XSL Stylesheets V1.71.1"><link rel="start" href="index.html" title="FindBugs™ Manual"><link rel="up" href="index.html" title="FindBugs™ Manual"><link rel="prev" href="gui.html" title="Chapter 5. Using the FindBugs GUI"><link rel="next" href="eclipse.html" title="Chapter 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 accesskey="n" href="eclipse.html">Next</a></td></tr></table><hr></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="anttask"></a>Chapter 6. Using the <span class="application">FindBugs</span>™ <span class="application">Ant</span> task</h2></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="sect1"><a href="anttask.html#d0e1200">1. Installing the <span class="application">Ant</span> task</a></span></dt><dt><span class="sect1"><a href="anttask.html#d0e1238">2. Modifying build.xml</a></span></dt><dt><span class="sect1"><a href="anttask.html#d0e1309">3. Executing the task</a></span></dt><dt><span class="sect1"><a href="anttask.html#d0e1334">4. Parameters</a></span></dt></dl></div><p>This chapter describes how to integrate <span class="application">FindBugs</span> into a build scriptfor <a href="http://ant.apache.org/" target="_top"><span class="application">Ant</span></a>, which is a popular Java buildand deployment tool. Using the <span class="application">FindBugs</span> <span class="application">Ant</span> task, your build script canautomatically run <span class="application">FindBugs</span> on your Java code.</p><p>The <span class="application">Ant</span> task was generously contributed by Mike Fagan.</p><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e1200"></a>1. Installing the <span class="application">Ant</span> task</h2></div></div></div><p>To install the <span class="application">Ant</span> task, simply copy <code class="filename"><em class="replaceable"><code>$FINDBUGS_HOME</code></em>/lib/findbugs-ant.jar</code>into the <code class="filename">lib</code> subdirectory of your <span class="application">Ant</span> installation.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><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 use the <span class="application">Ant</span> task with the versionof <span class="application">FindBugs</span> it was included with. We do not guarantee that the <span class="application">Ant</span> task Jar filewill work with any version of <span class="application">FindBugs</span> other than the one it was included with.</p></td></tr></table></div><p></p></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e1238"></a>2. Modifying build.xml</h2></div></div></div><p>To incorporate <span class="application">FindBugs</span> into <code class="filename">build.xml</code> (the build scriptfor <span class="application">Ant</span>), you first need to add a task definition. This should appear as follows:</p><pre class="screen"> <taskdef name="findbugs" classname="edu.umd.cs.findbugs.anttask.FindBugsTask"/></pre><p>The task definition specifies that when a <code class="literal">findbugs</code> element isseen in <code class="filename">build.xml</code>, it should use the indicated class to execute the task.</p><p>After you have added the task definition, you can define a targetwhich uses the <code class="literal">findbugs</code> task. Here is an examplewhich could be added to the <code class="filename">build.xml</code> for theApache <a href="http://jakarta.apache.org/bcel/" target="_top">BCEL</a> library.</p><pre class="screen"> <property name="findbugs.home" value="/export/home/daveho/work/findbugs" /> <target name="findbugs" depends="jar"> <findbugs home="${findbugs.home}" output="xml" outputFile="bcel-fb.xml" > <auxClasspath path="${basedir}/lib/Regex.jar" /> <sourcePath path="${basedir}/src/java" /> <class location="${basedir}/bin/bcel.jar" /> </findbugs> </target></pre><p>The <code class="literal">findbugs</code> element must have the <code class="literal">home</code>attribute set to the directory in which <span class="application">FindBugs</span> is installed; in other words,<em class="replaceable"><code>$FINDBUGS_HOME</code></em>. See <a href="installing.html" title="Chapter 2. Installing FindBugs™">Chapter 2, <i>Installing <span class="application">FindBugs</span>™</i></a>.</p><p>This target will execute <span class="application">FindBugs</span> on <code class="filename">bcel.jar</code>, which is theJar file produced by BCEL's build script. (By making it depend on the "jar"target, we ensure that the library is fully compiled before running <span class="application">FindBugs</span> on it.)The output of <span class="application">FindBugs</span> will be saved in XML format to a file called<code class="filename">bcel-fb.xml</code>.An auxiliary Jar file, <code class="filename">Regex.jar</code>, is added to the aux classpath,because it is referenced by the main BCEL library. A source path is specifiedso that the saved bug data will have accurate references to the BCEL source code.</p></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e1309"></a>3. Executing the task</h2></div></div></div><p>Here is an example of invoking <span class="application">Ant</span> from the command line, using the <code class="literal">findbugs</code>target defined above.</p><pre class="screen"> <code class="prompt">[daveho@noir]$</code> <span><strong class="command">ant findbugs</strong></span> Buildfile: build.xml init: compile: examples: jar: findbugs: [findbugs] Running FindBugs... [findbugs] Bugs were found [findbugs] Output saved to bcel-fb.xml BUILD SUCCESSFUL Total time: 35 seconds</pre><p>In this case, because we saved the bug results in an XML file, we canuse the <span class="application">FindBugs</span> GUI to view the results; see <a href="running.html" title="Chapter 4. Running FindBugs™">Chapter 4, <i>Running <span class="application">FindBugs</span>™</i></a>.</p></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e1334"></a>4. Parameters</h2></div></div></div><p>This section describes the parameters that may be specified whenusing the <span class="application">FindBugs</span> task.</p><div class="variablelist"><dl><dt><span class="term"><code class="literal">class</code></span></dt><dd><p> A nested element specifying which classes to analyze. The <code class="literal">class</code> element must specify a <code class="literal">location</code> attribute which names the archive file (jar, zip, etc.), directory, or class file to be analyzed. Multiple <code class="literal">class</code> elements may be specified as children of a single <code class="literal">findbugs</code> element. </p></dd><dt><span class="term"><code class="literal">auxClasspath</code></span></dt><dd><p> An optional nested element which specifies a classpath (Jar files or directories) containing classes used by the analyzed library or application, but which you don't want to analyze. It is specified the same way as <span class="application">Ant</span>'s <code class="literal">classpath</code> element for the Java task. </p></dd><dt><span class="term"><code class="literal">sourcePath</code></span></dt><dd><p> An optional nested element which specifies a source directory path containing source files used to compile the Java code being analyzed. By specifying a source path, any generated XML bug output will have
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -