benji
benji

Reputation: 2451

FindBugs Exclude filter with Ant

I can't get FindBugs to take into account my exclude filter:

In tools/findbugs-exclude.xml:

<FindBugsFilter>
  <Match>
    <Bug pattern="WMI_WRONG_MAP_ITERATOR,SE_COMPARATOR_SHOULD_BE_SERIALIZABLE,RV_RETURN_VALUE_IGNORED,EI_EXPOSE_REP,EI_EXPOSE_REP2,MS_CANNOT_BE_FINAL,SBSC_USE_STRINGBUFFER_CONCATENATION,SE_BAD_FIELD"/>
  </Match>
</FindBugsFilter>

In build.xml:

<findbugs home="${findbugs.home}" 
    output="html" 
    outputFile="${findbugs.output.current}" 
    timeout="1200000" 
    jvmargs="-Xmx1024m" 
    effort="max" 
    excludeFilter="${basedir}/tools/findbugs-exclude.xml">
  <auxClasspath>
    <fileset dir="${basedir}/lib">
      <include name="**/*.jar" />
    </fileset>
  </auxClasspath>
  <sourcePath path="${basedir}/sources" />
  <class location="${classes}" />
  <fileset dir="${basedir}/build/dist">
    <include name="*.jar" />
  </fileset>
</findbugs>

FindBugs generates the report properly but it includes everything.

Upvotes: 3

Views: 1780

Answers (1)

Kristof Neirynck
Kristof Neirynck

Reputation: 4162

I've had the exact same problem and it was due to a typo in the findbugs-exclude.xml file path.

Try running ant in verbose mode like this:

C:\Workspace\example> ant -verbose

You'll notice something like this in the output:

findbugs:
 [findbugs] Executing findbugs FindBugsTask from ant task
 [findbugs] Running FindBugs...
 [findbugs] Executing 'C:\Workspace\opt\Java\jdk1.8.0_72\jre\bin\java.exe' with arguments:
 [findbugs] '-Xmx1024m'
 [findbugs] '-Dfindbugs.hostApp=FBAntTask'
 [findbugs] '-Dfindbugs.home=C:\Workspace\opt\findbugs-3.0.1'
 [findbugs] '-classpath'
 [findbugs] 'C:\Workspace\opt\findbugs-3.0.1\lib\findbugs.jar'
 [findbugs] 'edu.umd.cs.findbugs.FindBugs2'
 [findbugs] '-sortByClass'
 [findbugs] '-timestampNow'
 [findbugs] '-xml:withMessages'
 [findbugs] '-exclude'
 [findbugs] 'C:\Workspace\example\tools\findbugs-exclude.xml'
 [findbugs] '-auxclasspathFromInput'
 [findbugs] '-sourcepath'
 [findbugs] 'C:\Workspace\example\src'
 [findbugs] '-outputFile'
 [findbugs] 'C:\Workspace\example\output\findbugs.xml'
 [findbugs] '-exitcode'
 [findbugs] 'C:\Workspace\example\cls'

If the -exclude argument is missing add the following to your build.xml to see if the path is correct:

<available property="file.exists" file="${basedir}/tools/findbugs-exclude.xml"/>
<echo>${basedir}/tools/findbugs-exclude.xml exists = ${file.exists}</echo>

Because FindBugsTask.java contains a check to see if the excludeFilter file exists.

public void setExcludeFilter(File filterFile) {
    if (filterFile != null && filterFile.length() > 0) {
        this.excludeFile = filterFile;
    } else {
        this.excludeFile = null;
    }
}

Upvotes: 1

Related Questions