Add Package (or Class) Filtering To Your Findbugs Ant Task
Following on from my last post about using hbm2java to generate a @Entity bean DAO layer for our application, Findbugs, the great automatic bug finding tool, will find a lot of issues with Hibernate’s auto-generated code (primarily around exposing internal Date objects to callers). So long as this is something we are aware of and don’t have a problem with, we don’t want find bugs to tell us about this stuff. It’s possible to filter out an entire package or class tree with the use of Findbugs’ filters.
For example, say we wanted to filter out the classes in the package com.mycom.dbautodao, we could create a findbugs_filter.xml which contains:
view plaincopy to clipboardprint?
<FindBugsFilter>
<Match>
<Package name="~com\.mycom\.dbautodao\..*"/>
</Match>
</FindBugsFilter>
<FindBugsFilter>
<Match>
<Package name="~com\.mycom\.dbautodao\..*"/>
</Match>
</FindBugsFilter>
This uses a regular expression to filter out checks against all contents and sub-packages of the com.mycom.dbautodao package.
Similarly it’s possible to do the same with a <class name=”myregex”/> element rather than a <package/> element for finer control.
To enable the filtering we just need modify the tag in our Ant build file to include the filter, e.g.
view plaincopy to clipboardprint?
<findbugs home="${findbugs.home}" output="xml" outputFile="${basedir}/dist/findbugs/findbugs.xml" excludefilter="findbugs_filter.xml">
<findbugs home="${findbugs.home}" output="xml" outputFile="${basedir}/dist/findbugs/findbugs.xml" excludefilter="findbugs_filter.xml">
While on the topic of regular expressions, I often find myself using this online regex checker tool which uses Java’s regex syntax – http://www.fileformat.info/tool/regex.htm. It’s a really quick and handy way of writing and testing a regular expression, since you can enter
在主脚本文件中增加:
<target name="findbugs">
<findbugs home="${findbugs.dir}/findbugs-1.2.1" output="xml" jvmargs="-Xmx256M" projectName="${ant.project.name}"
outputFile="${testreport.dir}/findbugs.xml" excludeFilter="${testreport.dir}/FindBugsFilter.xml">
<class location="${outclasses.dir}" />
</findbugs>
<echo>Findbugs检查代码错误完成!</echo>
</target>
然后指定一个单独的配置文件: FindBugsFilter.xml
内容如下例子:
<FindBugsFilter>
<Match>
<Method name="main" />
</Match>
<Match>
<Class name="~.*\.*Test" />
</Match>
<Match>
<Class name="~.*\.*Value" />
</Match>
<Match>
<Class name="~.*\.*Value\$.*" />
</Match>
<Match>
<Class name="~.*\.*Table" />
</Match>
</FindBugsFilter>
这样会过滤Value和Table,Cache等类
分享到:
相关推荐
中文版-FindBugs规则整理_ 支持规则大约有300个左右;
FindBugs的规则整理(中文版)
FindBugs规则整理_中文版 支持规则大约有300个左右
SonarQube的FindBugs插件sonar-findbugs-plugin.jar(版本:4.0.1-SNAPSHOT),包含FindBugs Security Audit等规则,可以离线集成到sonarqube。
在eclipse中修改checkstyle和pmd、FindBugs规则集的方法
findbugs 1.3.9 findbugs 1.3.9 findbugs 1.3.9 findbugs 1.3.9 findbugs 1.3.9 findbugs 1.3.9
myeclipse 和 eclipse 集成插件
findbugs-maven-plugin, 为了生成基于FindBugs分析器的报告,Maven Mojo插件 Maven 插件 最新快照请从这里下载最新的快照。构建findbugs-maven-plugin需求Java 7是必需的。这将允许分析字节码到 Java 8 findbugs-...
FindBugs规则整理_中文版.pdf
FindBugs 是由马里兰大学提供的一款开源 Java静态代码分析工具。FindBugs通过检查类文件或 JAR文件,将字节码与一组缺陷模式进行对比从而发现代码缺陷,完成静态代码分析。FindBugs既提供可视化 UI 界面,同时...
如何进行findbugs规则设置,进行问题的缺陷分析。 如何进行findbugs规则设置,进行问题的缺陷分析。
NULL 博文链接:https://plkong.iteye.com/blog/1482178
sonarqube5.6.7的findbugs规则插件插件,已经在Windows系统和Centos6.5下验证,亲测可用sonar-findbugs-plugin-3.4.3.jar
赠送jar包:findbugs-annotations-1.3.9-1.jar; 赠送原API文档:findbugs-annotations-1.3.9-1-javadoc.jar; 赠送源代码:findbugs-annotations-1.3.9-1-sources.jar; 赠送Maven依赖信息文件:findbugs-...
插件安装时,我们只需在eclipse根目录下新建一个【links】目录,然后在里面创建【.link】扩展名的文件,在里面写上类似于【path=F:\\IDE\\eclipsePlugin\\findbugs\\findbugs1.3.4】这样的配置信息,不就可以统一...
在这个由两部分组成的系列文章的第一部分中,高级软件工程师 Chris Grindstaff 分析了 FindBugs 如何帮助提高代码质量以及排除隐含的缺陷。代码质量工具的一个问题是它们容易为开发人员提供大量但并非真正问题的问题...
sonar自定义规则findbugs插件: 版本:3.11.1 对应soanrqube版本:7.6-8.1都可以使用该版本(即从7.6开始的sonar版本到8.1都可以使用该插件)
findbugs.jar开发findbugs自定义插件
FindBugs规则整理_中文版.rar