我需要为我的 findbugs ant 脚本设置一个过滤器文件,它只扫描 src/* 文件而不是 test/* 文件。
检查所有类同时忽略名称中带有“test”的任何文件名或包名的语法是什么?
FindBugs 实际上是扫描已编译的类文件,而不是sourcePath
. 如果要将 src/* 和 test/* 文件编译到不同的目录,则可以只使用嵌套<class...>
元素。
<findbugs home="${findbugs.dir}" output="xml:withMessages"
outputFile="${findbugs.report.xml}" jvmargs="-Xmx256M"
effort="max" projectName="${ant.project.name}"
auxClasspathRef="findbugs.classpath"
sourcePath="${src.dir}">
<class location="${src.classes.dir}"/>
</findbugs>
如果 src/* 和 test/* 都编译到一个目录中,那将不起作用。在这种情况下,请使用过滤器文件并排除与测试对应的包或类名。
<findbugs home="${findbugs.dir}" output="xml:withMessages"
outputFile="${findbugs.report.xml}" jvmargs="-Xmx256M"
effort="max" projectName="${ant.project.name}"
auxClasspathRef="findbugs.classpath"
sourcePath="${src.dir}"
excludefilter="exclude.xml">
<class location="${classes.dir}"/>
</findbugs>
exclude.xml
看起来像:
<FindBugsFilter>
<Match>
<Class name="~.*Test$"/>
</Match>
<Match>
<Package name="~test\..*"/>
</Match>
</FindBugsFilter>
顺便说一句,用 FindBugs 覆盖单元测试也是一个好主意。没有理由对测试使用较低的质量标准。测试中的错误就是这样,错误。
当然,如果您第一次运行 FindBugs,可能会有很多错误报告,但是如果您注意它们,错误计数会随着时间的推移而下降。