【问题标题】:FindBugs Exclude filter with AntFindBugs 使用 Ant 排除过滤器
【发布时间】:2014-06-18 00:21:53
【问题描述】:

我无法让 FindBugs 考虑我的排除过滤器:

在工具/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>

在 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 可以正确生成报告,但它包含所有内容。

【问题讨论】:

    标签: ant findbugs


    【解决方案1】:

    我遇到了完全相同的问题,这是由于 findbugs-exclude.xml 文件路径中的拼写错误。

    尝试像这样以详细模式运行 ant:

    C:\Workspace\example> ant -verbose
    

    您会在输出中注意到类似的内容:

    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'
    

    如果缺少-exclude 参数,请将以下内容添加到您的 build.xml 以查看路径是否正确:

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

    因为FindBugsTask.java 包含一个检查excludeFilter 文件是否存在。

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

    【讨论】:

      猜你喜欢
      • 2010-11-07
      • 2011-11-25
      • 2018-11-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-21
      • 2011-01-26
      • 1970-01-01
      相关资源
      最近更新 更多