Chapter 12. Data mining of bugs with FindBugs™
Prev |  | Next

## Chapter 12. Data mining of bugs with FindBugs™

FindBugs incorporates an ability to perform sophisticated queries on bug databases and track warnings across multiple versions of code being studied, allowing you to do things such as seeing when a bug was first introduced, examining just the warnings that have been introduced since the last release, or graphing the number of infinite recursive loops in your code over time.

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, but they can also store the results from analyzing a sequence of software builds or versions.

Any FindBugs XML bug database contains a version name and timestamp. FindBugs tries to compute a timestamp from the timestamps of the files that are analyzed (e.g., the timestamp is intended to be the time the class files were generated, not analyzed). Each bug database also contains a version name. Both the version name and timestamp can be set manually using the setBugDatabaseInfo (Section 1.7, “setBugDatabaseInfo”) command.

A multiversion bug database assigns a sequence number to each version of the analyzed code. These sequence numbers are simply successive integers, starting at 0 (e.g., a bug database for 4 versions of the code will contain versions 0..3). The bug database will also record the name and timestamp for each version. The filterBugs command allows you to refer to a version by sequence number, name or timestamp.

You can take a sequence (or pair) of single version bug databases and create from them a multiversion bug database, or combine a multiversion bug database with a sequence of later single-version bug databases.

Some of these commands can be invoked as ant tasks. See below for specifics on how to invoke them and what attributes and arguments they take. All of the examples assume that the `findbugs.lib` `refid` is set correctly. Here is one way to set it:

       <!-- 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>

## 1. Commands

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 an ant build file.

Briefly, the command-line tools are:

unionBugs

  combine the results from separate analysis of disjoint classes

computeBugHistory

  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.

setBugDatabaseInfo

  Set information such as the revision name or timestamp in an XML bug database

listBugDatabaseInfo

  List information such as the revision name and timestamp for a list of XML bug databases

filterBugs

  Select a subset of a bug database

mineBugHistory

  Generate a tabular listing of the number of warnings in each version of a multiversion bug database

defectDensity

  List information about defect density (warnings per 1000 NCSS) for the entire project and each class and package

convertXmlToText

  Convert bug warnings in XML format to a textual one-line-per-bug format, or to HTML

### 1.1. unionBugs

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.

Do not use this command to combine results from analyzing different versions of the same file; use computeBugHistory instead.

Specify the xml files on the command line. The result is sent to standard output.

### 1.2. computeBugHistory

Use this command to generate a bug database containing information from different builds or versions of software you are analyzing. History is taken from the first file provided as input; any following files should be single version bug databases (if they contain history, the history in those files will be ignored).

By default, output is written to the standard output.

This functionality may also can be accessed from ant. First create a taskdef for computeBugHistory in your build file:

    <taskdef name="computeBugHistory" classname="edu.umd.cs.findbugs.anttask.ComputeBugHistoryTask">
        <classpath refid="findbugs.lib" />
    </taskdef>

Attributes for this ant task are listed in the following table. To specify input files, nest them inside with a `<datafile>` element. For example:

    <computeBugHistory home="${findbugs.home}" ...>
        <datafile name="analyze1.xml"/>
        <datafile name="analyze2.xml"/>
    </computeBugHistory>

Table 12.1. Options for computeBugHistory command

Command-line option | Ant attribute | Meaning
--- | --- | ---
-output <file> | output="<file>" | save output in the named file (may also be an input file)
-overrideRevisionNames[:truth] | overrideRevisionNames="[true|false]" | override revision names for each version with names computed from the filenames
-noPackageMoves[:truth] | noPackageMoves="[true|false]" | if a class has moved to another package, treat warnings in that class as seperate
-preciseMatch[:truth] | preciseMatch="[true|false]" | require bug patterns to match precisely
-precisePriorityMatch[:truth] | precisePriorityMatch="[true|false]" | consider two warnings as the same only if priorities match exactly
-quiet[:truth] | quiet="[true|false]" | don't generate any output to standard out unless there is an error
-withMessages[:truth] | withMessages="[true|false]" | include human-readable messages describing the warnings in XML output

### 1.3. filterBugs

This command is used to select a subset of warnings from a FindBugs XML warning file and write the selected subset to a new FindBugs warning file.

This command takes a sequence of options, and either zero, one or two filenames of findbugs xml bug files on the command line.

If no file names are provided, the command reads from standard input and 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 output to the second file name.

This functionality may also can be accessed from ant. First create a taskdef for filterBugs in your build file:

    <taskdef name="filterBugs" classname="edu.umd.cs.findbugs.anttask.FilterBugsTask">
        <classpath refid="findbugs.lib" />
    </taskdef>

Attributes for this ant task are listed in the following table. To specify an input file either use the input attribute or nest it inside the ant call with a `<datafile>` element. For example:

    <filterBugs home="${findbugs.home}" ...>
        <datafile name="analyze.xml"/>
    </filterBugs>

Table 12.2. Options for filterBugs command

Command-line option | Ant attribute | Meaning
--- | --- | ---
| input="<file>" | use file as input
| output="<file>" | output results to file
-not | not="[true|false]" | reverse (all) switches for the filter
-withSource[:truth] | withSource="[true|false]" | only warnings for switch source is available
-exclude <filter file> | exclude="<filter file>" | exclude bugs matching given filter
-include <filter file> | include="<filter file>" | include only bugs matching given filter
-annotation <text> | annotation="<text>" | allow only warnings containing this text in a manual annotation
-after <when> | after="<when>" | allow only warnings that first occurred after this version
-before <when> | before="<when>" | allow only warnings that first occurred before this version
-first <when> | first="<when>" | allow only warnings that first occurred in this version
-last <when> | last="<when>" | allow only warnings that last occurred in this version
-fixed <when> | fixed="<when>" | allow only warnings that last occurred in the previous version (clobbers `-last`)
-present <when> | present="<when>" | allow only warnings present in this version
-absent <when> | absent="<when>" | allow only warnings absent in this version
-active[:truth] | active="[true|false]" | allow only warnings alive in the last sequence number
-introducedByChange[:truth] | introducedByChange="[true|false]" | allow only warnings introduced by a change of an existing class
-removedByChange[:truth] | removedByChange="[true|false]" | allow only warnings removed by a change of a persisting class
-newCode[:truth] | newCode="[true|false]" | allow only warnings introduced by the addition of a new class
-removedCode[:truth] | removedCode="[true|false]" | allow only warnings removed by removal of a class
-priority <level> | priority="<level>" | allow only warnings with this priority or higher
-class <pattern> | class="<class>" | allow only bugs whose primary class name matches this pattern
-bugPattern <pattern> | bugPattern="<pattern>" | allow only bugs whose type matches this pattern
-category <category> | category="<category>" | allow only warnings with a category that starts with this string
-designation <designation> | designation="<designation>" | allow only warnings with this designation (e.g., -designation SHOULD_FIX)
-withMessages[:truth] | withMessages="[true|false]" | the generated XML should contain textual messages

### 1.4. mineBugHistory

This command generates a table containing counts of the numbers of warnings in each version of a multiversion bug database.

This functionality may also can be accessed from ant. First create a taskdef for mineBugHistory in your build file:

    <taskdef name="mineBugHistory" classname="edu.umd.cs.findbugs.anttask.MineBugHistoryTask">
        <classpath refid="findbugs.lib" />
    </taskdef>

Attributes for this ant task are listed in the following table. To specify an input file either use the `input` attribute or nest it inside the ant call with a `<datafile>` element. For example:

    <mineBugHistory home="${findbugs.home}" ...>
        <datafile name="analyze.xml"/>
    </mineBugHistory>

Table 12.3. Options for mineBugHistory command

Command-line option | Ant attribute | Meaning
--- | --- | ---
| input="<file>" | use file as input
| output="<file>" | write output to file
-formatDates | formatDates="[true|false]" | render dates in textual form
-noTabs | noTabs="[true|false]" | delimit columns with groups of spaces instead of tabs (see below)
-summary | summary="[true|false]" | output terse summary of changes over the last ten entries

The `-noTabs` 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 `-formatDates` to render dates in terser format without embedded whitespace.

The table is a tab-separated (barring `-noTabs`) table with the following columns:

Table 12.4. Columns in mineBugHistory output

Title | Meaning
--- | ---
seq | Sequence number (successive integers, starting at 0)
version | Version name
time | Release timestamp
classes | Number of classes analyzed
NCSS | Non Commenting Source Statements
added | Count of new warnings for a class that existed in the previous version
newCode | Count of new warnings for a class that did not exist in the previous version
fixed | Count of warnings removed from a class that remains in the current version
removed | Count of warnings in the previous version for a class that is not present in the current version
retained | Count of warnings that were in both the previous and current version
dead | Warnings that were present in earlier versions but in neither the current version or the immediately preceeding version
active | Total warnings present in the current version

### 1.5. defectDensity

This command lists information about defect density (warnings per 1000 NCSS) for the entire project and each class and package. It can either be invoked with no files specified on the command line (in which case it reads from standard input) or with one file specified on the command line.

It generates a table with the following columns, and with one row for the entire project, and one row for each package or class that contains at least 4 warnings.

Table 12.5. Columns in defectDensity output

Title | Meaning
--- | ---
kind | project, package or class
name | The name of the project, package or class
density | Number of warnings generated per 1000 lines of NCSS.
bugs | Number of warnings
NCSS | Calculated number of NCSS

### 1.6. convertXmlToText

This command converts a warning collection in XML format to a text format with one line per warning, or to HTML.

This functionality may also can be accessed from ant. First create a taskdef for convertXmlToText in your build file:

    <taskdef name="convertXmlToText" classname="edu.umd.cs.findbugs.anttask.ConvertXmlToTextTask">
        <classpath refid="findbugs.lib" />
    </taskdef>

Attributes for this ant task are listed in the following table.

Table 12.6. Options for convertXmlToText command

Command-line option | Ant attribute | Meaning
--- | --- | ---
| input="<filename>" | use file as input
| output="<filename>" | output results to file
-longBugCodes | longBugCodes="[true|false]" | use the full bug pattern code instead of two-letter abbreviation
| format="text" | generate plain text output with one bug per line (command-line default)
-html[:stylesheet] | format="html:<stylesheet>" | generate output with specified stylesheet (see below), or default.xsl if unspecified

You may specify plain.xsl, default.xsl, fancy.xsl, fancy-hist.xsl, or your own XSL stylesheet for the -html/format option. Despite the name of this option, you may specify a stylesheet that emits something other than html. When applying a stylesheet other than those included with FindBugs (listed above), the -html/format option should be used with a path or URL to the stylesheet.

### 1.7. setBugDatabaseInfo

This command sets meta-information in a specified warning collection. It takes the following options:

This functionality may also can be accessed from ant. First create a taskdef for setBugDatabaseInfo in your build file:

    <taskdef name="setBugDatabaseInfo" classname="edu.umd.cs.findbugs.anttask.SetBugDatabaseInfoTask">
        <classpath refid="findbugs.lib" />
    </taskdef>

Attributes for this ant task are listed in the following table. To specify an input file either use the `input` attribute or nest it inside the ant call with a `<datafile>` element. For example:

    <setBugDatabaseInfo home="${findbugs.home}" ...>
        <datafile name="analyze.xml"/>
    </setBugDatabaseInfo>

Table 12.7. setBugDatabaseInfo Options

Command-line option | Ant attribute | Meaning
--- | --- | ---
| input="<file>" | use file as input
| output="<file>" | write output to file
-name <name> | name="<name>" | set name for (last) revision
-timestamp <when> | timestamp="<when>" | set timestamp for (last) revision
-source <directory> | source="<directory>" | add specified directory to the source search path
-findSource <directory> | findSource="<directory>" | find and add all relevant source directions contained within specified directory
-suppress <filter file> | suppress="<filter file>" | suppress warnings matched by this file (replaces previous suppressions)
-withMessages | withMessages="[true|false]" | add textual messages to XML
-resetSource | resetSource="[true|false]" | remove all source search paths

### 1.8. listBugDatabaseInfo

This command takes a list of zero or more xml bug database filenames on the command line. If zero file names are provided, it reads from standard input and does not generate a table header.

There is only one option: `-formatDates` renders dates in textual form.

The output is a table one row per bug database and the following columns:

Table 12.8. listBugDatabaseInfo Columns

Column | Meaning
--- | ---
version | version name
time | Release timestamp
classes | Number of classes analyzed
NCSS | Non Commenting Source Statements analyzed
total | Total number of warnings of all kinds
high | Total number of high priority warnings of all kinds
medium | Total number of medium/normal priority warnings of all kinds
low | Total number of low priority warnings of all kinds
filename | filename of database

## 2. Examples

### 2.1. Mining history using proveded shell scrips

In all of the following, the commands are given in a directory that contains directories jdk1.6.0-b12, jdk1.6.0-b13, ..., jdk1.6.0-b60.

You can use the command:

    computeBugHistory jdk1.6.0-b* | filterBugs -bugPattern IL_ | mineBugHistory -formatDates

to generate the following output:

    seq	version	time	classes	NCSS	added	newCode	fixed	removed	retained	dead	active
    0	jdk1.6.0-b12	"Thu Nov 11 09:07:20 EST 2004"	13128	811569	0	4	0	0	0	0	4
    1	jdk1.6.0-b13	"Thu Nov 18 06:02:06 EST 2004"	13128	811570	0	0	0	0	4	0	4
    2	jdk1.6.0-b14	"Thu Dec 02 06:12:26 EST 2004"	13145	811786	0	0	2	0	2	0	2
    3	jdk1.6.0-b15	"Thu Dec 09 06:07:04 EST 2004"	13174	811693	0	0	1	0	1	2	1
    4	jdk1.6.0-b16	"Thu Dec 16 06:21:28 EST 2004"	13175	811715	0	0	0	0	1	3	1
    5	jdk1.6.0-b17	"Thu Dec 23 06:27:22 EST 2004"	13176	811974	0	0	0	0	1	3	1
    6	jdk1.6.0-b19	"Thu Jan 13 06:41:16 EST 2005"	13176	812011	0	0	0	0	1	3	1
    7	jdk1.6.0-b21	"Thu Jan 27 05:57:52 EST 2005"	13177	812173	0	0	0	0	1	3	1
    8	jdk1.6.0-b23	"Thu Feb 10 05:44:36 EST 2005"	13179	812188	0	0	0	0	1	3	1
    9	jdk1.6.0-b26	"Thu Mar 03 06:04:02 EST 2005"	13199	811770	0	0	0	0	1	3	1
    10	jdk1.6.0-b27	"Thu Mar 10 04:48:38 EST 2005"	13189	812440	0	0	0	0	1	3	1
    11	jdk1.6.0-b28	"Thu Mar 17 02:54:22 EST 2005"	13185	812056	0	0	0	0	1	3	1
    12	jdk1.6.0-b29	"Thu Mar 24 03:09:20 EST 2005"	13117	809468	0	0	0	0	1	3	1
    13	jdk1.6.0-b30	"Thu Mar 31 02:53:32 EST 2005"	13118	809501	0	0	0	0	1	3	1
    14	jdk1.6.0-b31	"Thu Apr 07 03:00:14 EDT 2005"	13117	809572	0	0	0	0	1	3	1
    15	jdk1.6.0-b32	"Thu Apr 14 02:56:56 EDT 2005"	13169	811096	0	0	0	0	1	3	1
    16	jdk1.6.0-b33	"Thu Apr 21 02:46:22 EDT 2005"	13187	811942	0	0	0	0	1	3	1
    17	jdk1.6.0-b34	"Thu Apr 28 02:49:00 EDT 2005"	13195	813488	0	1	0	0	1	3	2
    18	jdk1.6.0-b35	"Thu May 05 02:49:04 EDT 2005"	13457	829837	0	0	0	0	2	3	2
    19	jdk1.6.0-b36	"Thu May 12 02:59:46 EDT 2005"	13462	831278	0	0	0	0	2	3	2
    20	jdk1.6.0-b37	"Thu May 19 02:55:08 EDT 2005"	13464	831971	0	0	0	0	2	3	2
    21	jdk1.6.0-b38	"Thu May 26 03:08:16 EDT 2005"	13564	836565	0	0	0	0	2	3	2
    22	jdk1.6.0-b39	"Fri Jun 03 03:10:48 EDT 2005"	13856	849992	0	1	0	0	2	3	3
    23	jdk1.6.0-b40	"Thu Jun 09 03:30:28 EDT 2005"	15972	959619	0	2	0	0	3	3	5
    24	jdk1.6.0-b41	"Thu Jun 16 03:19:22 EDT 2005"	15972	959619	0	0	0	0	5	3	5
    25	jdk1.6.0-b42	"Fri Jun 24 03:38:54 EDT 2005"	15966	958581	0	0	0	0	5	3	5
    26	jdk1.6.0-b43	"Thu Jul 14 03:09:34 EDT 2005"	16041	960544	0	0	0	0	5	3	5
    27	jdk1.6.0-b44	"Thu Jul 21 03:05:54 EDT 2005"	16041	960547	0	0	0	0	5	3	5
    28	jdk1.6.0-b45	"Thu Jul 28 03:26:10 EDT 2005"	16037	960606	0	0	1	0	4	3	4
    29	jdk1.6.0-b46	"Thu Aug 04 03:02:48 EDT 2005"	15936	951355	0	0	0	0	4	4	4
    30	jdk1.6.0-b47	"Thu Aug 11 03:18:56 EDT 2005"	15964	952387	0	0	1	0	3	4	3
    31	jdk1.6.0-b48	"Thu Aug 18 08:10:40 EDT 2005"	15970	953421	0	0	0	0	3	5	3
    32	jdk1.6.0-b49	"Thu Aug 25 03:24:38 EDT 2005"	16048	958940	0	0	0	0	3	5	3
    33	jdk1.6.0-b50	"Thu Sep 01 01:52:40 EDT 2005"	16287	974937	1	0	0	0	3	5	4
    34	jdk1.6.0-b51	"Thu Sep 08 01:55:36 EDT 2005"	16362	979377	0	0	0	0	4	5	4
    35	jdk1.6.0-b52	"Thu Sep 15 02:04:08 EDT 2005"	16477	979399	0	0	0	0	4	5	4
    36	jdk1.6.0-b53	"Thu Sep 22 02:00:28 EDT 2005"	16019	957900	0	0	1	0	3	5	3
    37	jdk1.6.0-b54	"Thu Sep 29 01:54:34 EDT 2005"	16019	957900	0	0	0	0	3	6	3
    38	jdk1.6.0-b55	"Thu Oct 06 01:54:14 EDT 2005"	16051	959014	0	0	0	0	3	6	3
    39	jdk1.6.0-b56	"Thu Oct 13 01:54:12 EDT 2005"	16211	970835	0	0	0	0	3	6	3
    40	jdk1.6.0-b57	"Thu Oct 20 01:55:26 EDT 2005"	16279	971627	0	0	0	0	3	6	3
    41	jdk1.6.0-b58	"Thu Oct 27 01:56:30 EDT 2005"	16283	971945	0	0	0	0	3	6	3
    42	jdk1.6.0-b59	"Thu Nov 03 01:56:58 EST 2005"	16232	972193	0	0	0	0	3	6	3
    43	jdk1.6.0-b60	"Thu Nov 10 01:54:18 EST 2005"	16235	972346	0	0	0	0	3	6	3

We could also generate that information directly, without creating an intermediate db.xml file, using the command

    computeBugHistory  jdk1.6.0-b*/jre/lib/rt.xml | filterBugs -bugPattern IL_ db.xml | mineBugHistory -formatDates

We can then use that information to display a graph showing the number of infinite recursive loops found by FindBugs in each build of Sun's JDK1.6.0. The blue area indicates the number of infinite recursive loops in that build, the red area above it indicates the number of infinite recursive loops that existed in some previous version but not in the current version (thus, the combined height of the red and blue areas is guaranteed to never decrease, and goes up whenever a new infinite recursive loop bug is introduced). The height of the red area is computed as the sum of the fixed, removed and dead values for each version. The reductions in builds 13 and 14 came after Sun was notified about the bugs found by FindBugs in the JDK.

Given the db.xml file that contains the results for all the jdk1.6.0 builds, the following command will show the history of high and medium priority correctness warnings:

    filterBugs -priority M -category C db.xml | mineBugHistory -formatDates

generating the table:

    seq	version	time	classes	NCSS	added	newCode	fixed	removed	retained	dead	active
    0	jdk1.6.0-b12	"Thu Nov 11 09:07:20 EST 2004"	13128	811569	0	1075	0	0	0	0	1075
    1	jdk1.6.0-b13	"Thu Nov 18 06:02:06 EST 2004"	13128	811570	0	0	0	0	1075	0	1075
    2	jdk1.6.0-b14	"Thu Dec 02 06:12:26 EST 2004"	13145	811786	3	0	6	0	1069	0	1072
    3	jdk1.6.0-b15	"Thu Dec 09 06:07:04 EST 2004"	13174	811693	2	1	3	0	1069	6	1072
    4	jdk1.6.0-b16	"Thu Dec 16 06:21:28 EST 2004"	13175	811715	0	0	1	0	1071	9	1071
    5	jdk1.6.0-b17	"Thu Dec 23 06:27:22 EST 2004"	13176	811974	0	0	1	0	1070	10	1070
    6	jdk1.6.0-b19	"Thu Jan 13 06:41:16 EST 2005"	13176	812011	0	0	0	0	1070	11	1070
    7	jdk1.6.0-b21	"Thu Jan 27 05:57:52 EST 2005"	13177	812173	0	0	1	0	1069	11	1069
    8	jdk1.6.0-b23	"Thu Feb 10 05:44:36 EST 2005"	13179	812188	0	0	0	0	1069	12	1069
    9	jdk1.6.0-b26	"Thu Mar 03 06:04:02 EST 2005"	13199	811770	0	0	2	1	1066	12	1066
    10	jdk1.6.0-b27	"Thu Mar 10 04:48:38 EST 2005"	13189	812440	1	0	1	1	1064	15	1065
    11	jdk1.6.0-b28	"Thu Mar 17 02:54:22 EST 2005"	13185	812056	0	0	0	0	1065	17	1065
    12	jdk1.6.0-b29	"Thu Mar 24 03:09:20 EST 2005"	13117	809468	3	0	8	26	1031	17	1034
    13	jdk1.6.0-b30	"Thu Mar 31 02:53:32 EST 2005"	13118	809501	0	0	0	0	1034	51	1034
    14	jdk1.6.0-b31	"Thu Apr 07 03:00:14 EDT 2005"	13117	809572	0	0	0	0	1034	51	1034
    15	jdk1.6.0-b32	"Thu Apr 14 02:56:56 EDT 2005"	13169	811096	1	1	0	1	1033	51	1035
    16	jdk1.6.0-b33	"Thu Apr 21 02:46:22 EDT 2005"	13187	811942	3	0	2	1	1032	52	1035
    17	jdk1.6.0-b34	"Thu Apr 28 02:49:00 EDT 2005"	13195	813488	0	1	0	0	1035	55	1036
    18	jdk1.6.0-b35	"Thu May 05 02:49:04 EDT 2005"	13457	829837	0	36	2	0	1034	55	1070
    19	jdk1.6.0-b36	"Thu May 12 02:59:46 EDT 2005"	13462	831278	0	0	0	0	1070	57	1070
    20	jdk1.6.0-b37	"Thu May 19 02:55:08 EDT 2005"	13464	831971	0	1	1	0	1069	57	1070
    21	jdk1.6.0-b38	"Thu May 26 03:08:16 EDT 2005"	13564	836565	1	7	2	6	1062	58	1070
    22	jdk1.6.0-b39	"Fri Jun 03 03:10:48 EDT 2005"	13856	849992	6	39	5	0	1065	66	1110
    23	jdk1.6.0-b40	"Thu Jun 09 03:30:28 EDT 2005"	15972	959619	7	147	11	0	1099	71	1253
    24	jdk1.6.0-b41	"Thu Jun 16 03:19:22 EDT 2005"	15972	959619	0	0	0	0	1253	82	1253
    25	jdk1.6.0-b42	"Fri Jun 24 03:38:54 EDT 2005"	15966	958581	3	0	1	2	1250	82	1253
    26	jdk1.6.0-b43	"Thu Jul 14 03:09:34 EDT 2005"	16041	960544	5	11	15	8	1230	85	1246
    27	jdk1.6.0-b44	"Thu Jul 21 03:05:54 EDT 2005"	16041	960547	0	0	0	0	1246	108	1246
    28	jdk1.6.0-b45	"Thu Jul 28 03:26:10 EDT 2005"	16037	960606	19	0	2	0	1244	108	1263
    29	jdk1.6.0-b46	"Thu Aug 04 03:02:48 EDT 2005"	15936	951355	13	1	1	32	1230	110	1244
    30	jdk1.6.0-b47	"Thu Aug 11 03:18:56 EDT 2005"	15964	952387	163	8	7	20	1217	143	1388
    31	jdk1.6.0-b48	"Thu Aug 18 08:10:40 EDT 2005"	15970	953421	0	0	0	0	1388	170	1388
    32	jdk1.6.0-b49	"Thu Aug 25 03:24:38 EDT 2005"	16048	958940	1	11	1	0	1387	170	1399
    33	jdk1.6.0-b50	"Thu Sep 01 01:52:40 EDT 2005"	16287	974937	19	27	16	7	1376	171	1422
    34	jdk1.6.0-b51	"Thu Sep 08 01:55:36 EDT 2005"	16362	979377	1	15	3	0	1419	194	1435
    35	jdk1.6.0-b52	"Thu Sep 15 02:04:08 EDT 2005"	16477	979399	0	0	1	1	1433	197	1433
    36	jdk1.6.0-b53	"Thu Sep 22 02:00:28 EDT 2005"	16019	957900	13	12	16	20	1397	199	1422
    37	jdk1.6.0-b54	"Thu Sep 29 01:54:34 EDT 2005"	16019	957900	0	0	0	0	1422	235	1422
    38	jdk1.6.0-b55	"Thu Oct 06 01:54:14 EDT 2005"	16051	959014	1	4	7	0	1415	235	1420
    39	jdk1.6.0-b56	"Thu Oct 13 01:54:12 EDT 2005"	16211	970835	6	8	37	0	1383	242	1397
    40	jdk1.6.0-b57	"Thu Oct 20 01:55:26 EDT 2005"	16279	971627	0	0	0	0	1397	279	1397
    41	jdk1.6.0-b58	"Thu Oct 27 01:56:30 EDT 2005"	16283	971945	0	1	1	0	1396	279	1397
    42	jdk1.6.0-b59	"Thu Nov 03 01:56:58 EST 2005"	16232	972193	6	0	5	0	1392	280	1398
    43	jdk1.6.0-b60	"Thu Nov 10 01:54:18 EST 2005"	16235	972346	0	0	0	0	1398	285	1398
    44	jdk1.6.0-b61	"Thu Nov 17 01:58:42 EST 2005"	16202	971134	2	0	4	0	1394	285	1396

### 2.2. Incremental history maintenance

If db.xml contains the results of running findbugs over builds b12 - b60, we can update db.xml to include the results of analyzing b61 with the commands:

    computeBugHistory -output db.xml db.xml jdk1.6.0-b61/jre/lib/rt.xml

## 3. Ant example

Here is a complete ant script example for both running findbugs and running a chain of data-mining tools afterward:

    <project name="analyze_asm_util" default="findbugs">
       <!-- findbugs task definition -->
       <property name="findbugs.home" value="/Users/ben/Documents/workspace/findbugs/findbugs" />
       <property name="jvmargs" value="-server -Xss1m -Xmx800m -Duser.language=en -Duser.region=EN -Dfindbugs.home=${findbugs.home}" />

        <path id="findbugs.lib">
          <fileset dir="${findbugs.home}/lib">
             <include name="findbugs-ant.jar"/>
          </fileset>
       </path>

       <taskdef name="findbugs" classname="edu.umd.cs.findbugs.anttask.FindBugsTask">
          <classpath refid="findbugs.lib" />
       </taskdef>

       <taskdef name="computeBugHistory" classname="edu.umd.cs.findbugs.anttask.ComputeBugHistoryTask">
          <classpath refid="findbugs.lib" />
       </taskdef>

       <taskdef name="setBugDatabaseInfo" classname="edu.umd.cs.findbugs.anttask.SetBugDatabaseInfoTask">
          <classpath refid="findbugs.lib" />
       </taskdef>

       <taskdef name="mineBugHistory" classname="edu.umd.cs.findbugs.anttask.MineBugHistoryTask">
          <classpath refid="findbugs.lib" />
       </taskdef>

       <!-- findbugs task definition -->
       <target name="findbugs">
          <antcall target="analyze" />
          <antcall target="mine" />
       </target>

       <!-- analyze task -->
       <target name="analyze">
          <!-- run findbugs against asm-util -->
          <findbugs home="${findbugs.home}"
                    output="xml:withMessages"
                    timeout="90000000"
                    reportLevel="experimental"
                    workHard="true"
                    effort="max"
                    adjustExperimental="true"
                    jvmargs="${jvmargs}"
                    failOnError="true"
                    outputFile="out.xml"
                    projectName="Findbugs"
                    debug="false">
             <class location="asm-util-3.0.jar" />
          </findbugs>
       </target>

       <target name="mine">

          <!-- Set info to the latest analysis -->
          <setBugDatabaseInfo home="${findbugs.home}"
                                withMessages="true"
                                name="asm-util-3.0.jar"
                                input="out.xml"
                                output="out-rel.xml"/>

          <!-- Checking if history file already exists (out-hist.xml) -->
          <condition property="mining.historyfile.available">
             <available file="out-hist.xml"/>
          </condition>
          <condition property="mining.historyfile.notavailable">
             <not>
                <available file="out-hist.xml"/>
             </not>
          </condition>

          <!-- this target is executed if the history file do not exist (first run) -->
          <antcall target="history-init">
            <param name="data.file" value="out-rel.xml" />
            <param name="hist.file" value="out-hist.xml" />
          </antcall>
          <!-- else this one is executed -->
          <antcall target="history">
            <param name="data.file"         value="out-rel.xml" />
            <param name="hist.file"         value="out-hist.xml" />
            <param name="hist.summary.file" value="out-hist.txt" />
          </antcall>
       </target>

       <!-- Initializing history file -->
       <target name="history-init" if="mining.historyfile.notavailable">
          <copy file="${data.file}" tofile="${hist.file}" />
       </target>

       <!-- Computing bug history -->
       <target name="history" if="mining.historyfile.available">
          <!-- Merging ${data.file} into ${hist.file} -->
          <computeBugHistory home="${findbugs.home}"
                               withMessages="true"
                               output="${hist.file}">
                <dataFile name="${hist.file}"/>
                <dataFile name="${data.file}"/>
          </computeBugHistory>

          <!-- Compute history into ${hist.summary.file} -->
          <mineBugHistory home="${findbugs.home}"
                            formatDates="true"
                          noTabs="true"
                            input="${hist.file}"
                            output="${hist.summary.file}"/>
       </target>

    </project>

Prev |  | Next
Chapter 11. Using rejarForAnalysis | Home | Chapter 13. License