?? datamining.html
字號:
<html><head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Chapter 12. Data mining of bugs with FindBugs™</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="rejarForAnalysis.html" title="Chapter 11. Using rejarForAnalysis"><link rel="next" href="license.html" title="Chapter 13. License"></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 12. Data mining of bugs with <span class="application">FindBugs</span>™</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="rejarForAnalysis.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="license.html">Next</a></td></tr></table><hr></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="datamining"></a>Chapter 12. Data mining of bugs with <span class="application">FindBugs</span>™</h2></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="sect1"><a href="datamining.html#commands">1. Commands</a></span></dt><dt><span class="sect1"><a href="datamining.html#examples">2. Examples</a></span></dt><dt><span class="sect1"><a href="datamining.html#antexample">3. Ant example</a></span></dt></dl></div><p>FindBugs incorporates an ability to perform sophisticated queries on bugdatabases and track warnings across multiple versions of code beingstudied, allowing you to do things such as seeing when a bug was first introduced, examiningjust the warnings that have been introduced since the last release, or graphing the numberof infinite recursive loops in your code over time.</p><p>These techniques all depend upon the XML format used by FindBugs for storing warnings.These XML files usually contain just the warnings from one particular analysis run, butthey can also store the results from analyzing a sequence of software builds or versions. </p><p>Any FindBugs XML bug database contains a version name and timestamp. FindBugs tries to compute a timestamp from the timestamps of the files thatare analyzed (e.g., the timestamp is intended to be the time the class fileswere generated, not analyzed). Each bug database also contains a version name.Both the version name and timestamp can be set manually using the <span><strong class="command">setBugDatabaseInfo</strong></span> (<a href="datamining.html#setBugDatabaseInfo" title="1.7. setBugDatabaseInfo">Section 1.7, “setBugDatabaseInfo”</a>) command. </p><p>A multiversion bug database assigns a sequence number to each version ofthe analyzed code. These sequence numbers are simply successive integers,starting at 0 (e.g., a bug database for 4 versions of the code will containversions 0..3). The bug database will also record the name and timestamp foreach version. The <span><strong class="command">filterBugs</strong></span> command allows you to referto a version by sequence number, name or timestamp.</p><p>You can take a sequence (or pair) of single version bug databases and createfrom them a multiversion bug database, or combine a multiversion bug databasewith a sequence of later single-version bug databases.</p><p>Some of these commands can be invoked as ant tasks. See below for specificson how to invoke them and what attributes and arguments they take. All ofthe examples assume that the <code class="literal">findbugs.lib</code><code class="literal">refid</code> is set correctly. Here is one way to set it:</p><pre class="programlisting"> <!-- findbugs task definition --> <property name="findbugs.home" value="/your/path/to/findbugs" /> <path id="findbugs.lib"> <fileset dir="${findbugs.home}/lib"> <include name="findbugs-ant.jar"/> </fileset> </path></pre><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="commands"></a>1. Commands</h2></div></div></div><p>All tools for FindBugs data mining are can be invoked from the command line,and some of the more useful tools can also be invoked from anant build file.</p><p>Briefly, the command-line tools are:</p><div class="variablelist"><dl><dt><span class="term"><span><strong class="command"><a href="datamining.html#unionBugs" title="1.1. unionBugs">unionBugs</a></strong></span></span></dt><dd><p> combine the results from separate analysis of disjoint classes </p></dd><dt><span class="term"><span><strong class="command"><a href="datamining.html#computeBugHistory" title="1.2. computeBugHistory">computeBugHistory</a></strong></span></span></dt><dd><p>Merge bug warnings from multiple versions of analyzed code into a single multiversion bug database. This can either be used to add more versions to an existing multiversion database, or to create a multiversion database from a sequence of single version bug warning databases.</p></dd><dt><span class="term"><span><strong class="command"><a href="datamining.html#setBugDatabaseInfo" title="1.7. setBugDatabaseInfo">setBugDatabaseInfo</a></strong></span></span></dt><dd><p>Set information such as the revision name ortimestamp in an XML bug database</p></dd><dt><span class="term"><span><strong class="command"><a href="datamining.html#listBugDatabaseInfo" title="1.8. listBugDatabaseInfo">listBugDatabaseInfo</a></strong></span></span></dt><dd><p>List information such as the revision name andtimestamp for a list of XML bug databases</p></dd><dt><span class="term"><span><strong class="command"><a href="datamining.html#filterBugs" title="1.3. filterBugs">filterBugs</a></strong></span></span></dt><dd><p>Select a subset of a bug database</p></dd><dt><span class="term"><span><strong class="command"><a href="datamining.html#mineBugHistory" title="1.4. mineBugHistory">mineBugHistory</a></strong></span></span></dt><dd><p>Generate a tabular listing of the number of warnings in each version of a multiversion bug database</p></dd><dt><span class="term"><span><strong class="command"><a href="datamining.html#defectDensity" title="1.5. defectDensity">defectDensity</a></strong></span></span></dt><dd><p>List information about defect density (warnings per 1000 NCSS) for the entire project and each class and package</p></dd><dt><span class="term"><span><strong class="command"><a href="datamining.html#convertXmlToText" title="1.6. convertXmlToText">convertXmlToText</a></strong></span></span></dt><dd><p>Convert bug warnings in XML format to a textual one-line-per-bug format, or to HTML</p></dd></dl></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="unionBugs"></a>1.1. unionBugs</h3></div></div></div><p> If you have, for example, separately analyzing each jar file used in an application, you can use this command to combine the separately generated xml bug warning files into a single file containing all of the warnings.</p><p>Do <span class="emphasis"><em>not</em></span> use this command to combine results from analyzing different versions of the same file; use <span><strong class="command">computeBugHistory</strong></span> instead.</p><p>Specify the xml files on the command line. The result is sent to standard output.</p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="computeBugHistory"></a>1.2. computeBugHistory</h3></div></div></div><p>Use this command to generate a bug database containing information from different builds or versionsof software you are analyzing.History is taken from the first file provided as input; any followingfiles should be single version bug databases (if they contain history, the history in thosefiles will be ignored).</p><p>By default, output is written to the standard output.</p><p>This functionality may also can be accessed from ant.First create a taskdef for <span><strong class="command">computeBugHistory</strong></span> in yourbuild file:</p><pre class="programlisting"><taskdef name="computeBugHistory" classname="edu.umd.cs.findbugs.anttask.ComputeBugHistoryTask"> <classpath refid="findbugs.lib" /></taskdef></pre><p>Attributes for this ant task are listed in the following table.To specify input files, nest them inside with a<code class="literal"><datafile></code> element. For example:</p><pre class="programlisting"><computeBugHistory home="${findbugs.home}" ...> <datafile name="analyze1.xml"/> <datafile name="analyze2.xml"/></computeBugHistory></pre><div class="table"><a name="computeBugHistoryTable"></a><p class="title"><b>Table 12.1. Options for computeBugHistory command</b></p><div class="table-contents"><table summary="Options for computeBugHistory command" border="1"><colgroup><col><col><col></colgroup><thead><tr><th align="left">Command-line option</th><th align="left">Ant attribute</th><th align="left">Meaning</th></tr></thead><tbody><tr><td align="left">-output <file></td><td align="left">output="<file>"</td><td align="left">save output in the named file (may also be an input file)</td></tr><tr><td align="left">-overrideRevisionNames[:truth]</td><td align="left">overrideRevisionNames="[true|false]"</td><td align="left">override revision names for each version with names computed from the filenames</td></tr><tr><td align="left">-noPackageMoves[:truth]</td><td align="left">noPackageMoves="[true|false]"</td><td align="left">if a class has moved to another package, treat warnings in that class as seperate</td></tr><tr><td align="left">-preciseMatch[:truth]</td><td align="left">preciseMatch="[true|false]"</td><td align="left">require bug patterns to match precisely</td></tr><tr><td align="left">-precisePriorityMatch[:truth]</td><td align="left">precisePriorityMatch="[true|false]"</td><td align="left">consider two warnings as the same only if priorities match exactly</td></tr><tr><td align="left">-quiet[:truth]</td><td align="left">quiet="[true|false]"</td><td align="left">don't generate any output to standard out unless there is an error</td></tr><tr><td align="left">-withMessages[:truth]</td><td align="left">withMessages="[true|false]"</td><td align="left">include human-readable messages describing the warnings in XML output</td></tr></tbody></table></div></div><br class="table-break"></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="filterBugs"></a>1.3. filterBugs</h3></div></div></div><p>This command is used to select a subset of warnings from a FindBugs XML warning fileand write the selected subset to a new FindBugs warning file.</p><p>This command takes a sequence of options, and either zero, one or twofilenames of findbugs xml bug files on the command line.</p><p>If no file names are provided, the command reads from standard inputand writes to standard output. If one file name is provided,it reads from the file and writes to standard output.If two file names are provided, it reads from the first and writes the outputto the second file name.</p><p>This functionality may also can be accessed from ant.First create a taskdef for <span><strong class="command">filterBugs</strong></span> in yourbuild file:</p><pre class="programlisting"><taskdef name="filterBugs" classname="edu.umd.cs.findbugs.anttask.FilterBugsTask"> <classpath refid="findbugs.lib" /></taskdef></pre><p>Attributes for this ant task are listed in the following table.To specify an input file either use the input attribute or nest it insidethe ant call with a <code class="literal"><datafile></code> element. For example:</p><pre class="programlisting"><filterBugs home="${findbugs.home}" ...> <datafile name="analyze.xml"/></filterBugs></pre><div class="table"><a name="filterOptionsTable"></a><p class="title"><b>Table 12.2. Options for filterBugs command</b></p><div class="table-contents"><table summary="Options for filterBugs command" border="1"><colgroup><col><col><col></colgroup><thead><tr><th align="left">Command-line option</th><th align="left">Ant attribute</th><th align="left">Meaning</th></tr></thead><tbody><tr><td align="left"> </td><td align="left">input="<file>"</td><td align="left">use file as input</td></tr><tr><td align="left"> </td><td align="left">output="<file>"</td><td align="left">output results to file</td></tr><tr><td align="left">-not</td><td align="left">not="[true|false]"</td><td align="left">reverse (all) switches for the filter</td></tr><tr><td align="left">-withSource[:truth]</td><td align="left">withSource="[true|false]"</td><td align="left">only warnings for switch source is available</td></tr><tr><td align="left">-exclude <filter file></td><td align="left">exclude="<filter file>"</td><td align="left">exclude bugs matching given filter</td></tr><tr><td align="left">-include <filter file></td><td align="left">include="<filter file>"</td><td align="left">include only bugs matching given filter</td></tr><tr><td align="left">-annotation <text></td><td align="left">annotation="<text>"</td><td align="left">allow only warnings containing this text in a manual annotation</td></tr><tr><td align="left">-after <when></td><td align="left">after="<when>"</td><td align="left">allow only warnings that first occurred after this version</td></tr><tr><td align="left">-before <when></td><td align="left">before="<when>"</td><td align="left">allow only warnings that first occurred before this version</td></tr><tr><td align="left">-first <when></td><td align="left">first="<when>"</td><td align="left">allow only warnings that first occurred in this version</td></tr><tr><td align="left">-last <when></td><td align="left">last="<when>"</td><td align="left">allow only warnings that last occurred in this version</td></tr><tr><td align="left">-fixed <when></td><td align="left">fixed="<when>"</td><td align="left">allow only warnings that last occurred in the previous version (clobbers <code class="option">-last</code>)</td></tr><tr><td align="left">-present <when></td><td align="left">present="<when>"</td><td align="left">allow only warnings present in this version</td></tr><tr><td align="left">-absent <when></td><td align="left">absent="<when>"</td><td align="left">allow only warnings absent in this version</td></tr><tr><td align="left">-active[:truth]</td><td align="left">active="[true|false]"</td><td align="left">allow only warnings alive in the last sequence number</td></tr><tr><td align="left">-introducedByChange[:truth]</td><td align="left">introducedByChange="[true|false]"</td><td align="left">allow only warnings introduced by a change of an existing class</td></tr><tr><td align="left">-removedByChange[:truth]</td><td align="left">removedByChange="[true|false]"</td><td align="left">allow only warnings removed by a change of a persisting class</td></tr><tr><td align="left">-newCode[:truth]</td><td align="left">newCode="[true|false]"</td><td align="left">allow only warnings introduced by the addition of a new class</td></tr><tr><td align="left">-removedCode[:truth]</td><td align="left">removedCode="[true|false]"</td><td align="left">allow only warnings removed by removal of a class</td></tr><tr><td align="left">-priority <level></td><td align="left">priority="<level>"</td><td align="left">allow only warnings with this priority or higher</td></tr><tr><td align="left">-class <pattern></td><td align="left">class="<class>"</td><td align="left">allow only bugs whose primary class name matches this pattern</td></tr><tr><td align="left">-bugPattern <pattern></td><td align="left">bugPattern="<pattern>"</td><td align="left">allow only bugs whose type matches this pattern</td></tr><tr><td align="left">-category <category></td><td align="left">category="<category>"</td><td align="left">allow only warnings with a category that starts with this string</td></tr><tr><td align="left">-designation <designation></td><td align="left">designation="<designation>"</td><td align="left">allow only warnings with this designation (e.g., -designation SHOULD_FIX)</td></tr><tr><td align="left">-withMessages[:truth] </td><td align="left">withMessages="[true|false]"</td><td align="left">the generated XML should contain textual messages</td></tr></tbody></table></div></div><br class="table-break"></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="mineBugHistory"></a>1.4. mineBugHistory</h3></div></div></div><p>This command generates a table containing counts of the numbers of warningsin each version of a multiversion bug database.</p><p>This functionality may also can be accessed from ant.First create a taskdef for <span><strong class="command">mineBugHistory</strong></span> in yourbuild file:</p><pre class="programlisting"><taskdef name="mineBugHistory" classname="edu.umd.cs.findbugs.anttask.MineBugHistoryTask"> <classpath refid="findbugs.lib" /></taskdef></pre><p>Attributes for this ant task are listed in the following table.To specify an input file either use the <code class="literal">input</code>attribute or nest it inside the ant call with a<code class="literal"><datafile></code> element. For example:</p><pre class="programlisting"><mineBugHistory home="${findbugs.home}" ...> <datafile name="analyze.xml"/></mineBugHistory></pre><div class="table"><a name="mineBugHistoryOptionsTable"></a><p class="title"><b>Table 12.3. Options for mineBugHistory command</b></p><div class="table-contents"><table summary="Options for mineBugHistory command" border="1"><colgroup><col><col><col></colgroup><thead><tr><th align="left">Command-line option</th><th align="left">Ant attribute</th><th align="left">Meaning</th></tr></thead><tbody><tr><td align="left"> </td><td align="left">input="<file>"</td><td align="left">use file as input</td></tr><tr><td align="left"> </td><td align="left">output="<file>"</td><td align="left">write output to file</td></tr><tr><td align="left">-formatDates</td><td align="left">formatDates="[true|false]"</td><td align="left">render dates in textual form</td></tr><tr><td align="left">-noTabs</td><td align="left">noTabs="[true|false]"</td><td align="left">delimit columns with groups of spaces instead of tabs (see below)</td></tr><tr><td align="left">-summary</td><td align="left">summary="[true|false]"</td><td align="left">output terse summary of changes over the last ten entries</td></tr></tbody></table></div></div><br class="table-break"><p> The <code class="option">-noTabs</code> output can be easier to read from a shell with a fixed-width font. Because numeric columns are right-justified, spaces may precede the first column value. This option also causes <code class="option">-formatDates</code> to render dates in terser format without embedded whitespace. </p><p>The table is a tab-separated (barring <code class="option">-noTabs</code>) table with the following columns:</p><div class="table"><a name="mineBugHistoryColumns"></a><p class="title"><b>Table 12.4. Columns in mineBugHistory output</b></p><div class="table-contents"><table summary="Columns in mineBugHistory output" border="1"><colgroup><col><col></colgroup><thead><tr><th align="left">Title</th><th align="left">Meaning</th></tr></thead><tbody><tr><td align="left">seq</td><td align="left">Sequence number (successive integers, starting at 0)</td></tr><tr><td align="left">version</td><td align="left">Version name</td></tr><tr><td align="left">time</td><td align="left">Release timestamp</td></tr><tr><td align="left">classes</td><td align="left">Number of classes analyzed</td></tr><tr><td align="left">NCSS</td><td align="left">Non Commenting Source Statements</td></tr><tr><td align="left">added</td><td align="left">Count of new warnings for a class that existed in the previous version</td></tr><tr><td align="left">newCode</td><td align="left">Count of new warnings for a class that did not exist in the previous version</td></tr><tr><td align="left">fixed</td><td align="left">Count of warnings removed from a class that remains in the current version</td></tr><tr><td align="left">removed</td><td align="left">Count of warnings in the previous version for a class that is not present in the current version</td></tr><tr><td align="left">retained</td><td align="left">Count of warnings that were in both the previous and current version</td></tr><tr><td align="left">dead</td><td align="left">Warnings that were present in earlier versions but in neither the current version or the immediately preceeding version</td></tr><tr><td align="left">active</td><td align="left">Total warnings present in the current version</td></tr></tbody></table></div></div><br class="table-break"></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="defectDensity"></a>1.5. defectDensity</h3></div></div></div><p>This command lists information about defect density (warnings per 1000 NCSS) for the entire project and each class and package.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -