Findbugs 是一个静态分析工具,它检查类或者 JAR 文件,将字节码与一组缺陷模式进行对比以发现可能的问题。利用这个工具,就可以在不实际运行程序的情况对软件进行分析。它可以帮助改进代码的质量。
Findbugs提供了方便操作的可视化界面,同时也可以作为Eclipse的一个插件来使用,而我们使用得最多的还是作为Eclipse的插件来使用。
doCheck.bat
------------
@ant -f fingbugs.xml
---------
fingbugs.xml
---------------------------------
<project name="sharedTargetsMacros" default="findbugs">
<!-- DEFINE SHARED PROPERTIES -->
<property name="project.path" value="D:/projectAddr"/>
<property name="auditCode.path" value="${project.path}/classes/com/此次省略" />
<!--<property name="findbugs.home" value="C:/Programing/Java/findbugs-1.3.9" />-->
<property name="findbugs.home" value="E:/Apps/findbugs-1.3.9" />
<property name="lib.path" value="${project.path}/WEB-INF/lib"/>
<!-- DEFINE PATH REFERENCES -->
<path id="findbugs.classpath">
<fileset dir="${findbugs.home}/lib" includes="*.jar" />
</path>
<target name="metrics" depends="findbugs"/>
<target name="findbugs">
<taskdef name="findbugs" classname="edu.umd.cs.findbugs.anttask.FindBugsTask" classpathref="findbugs.classpath"/>
<findbugs projectName="projectName" home="${findbugs.home}" output="html" outputFile="projectName.html" jvmargs="-Xmx256m -Xmx256m" reportLevel="Low" excludeFilter="findbugs_exclude.xml"><!--过滤文件-->
<auxClasspath path="classes" />
<!--
<auxClasspath path="${lib.path}/*.jar" />
<auxClasspath path="${lib.path}/test/*.jar" />
<auxClasspath path="${lib.path}/wseeclient/*.jar" />
-->
<auxClasspath path="${lib.path}/struts.jar" />
<auxClasspath path="${lib.path}/jcs-1.3.jar" />
<auxClasspath path="${lib.path}/poi-2.5.1-final-20040804.jar" />
<auxClasspath path="${lib.path}/javax.ejb_3.0.1.jar" />
<auxClasspath path="${lib.path}/javax.jsp_1.1.0.0_2-1.jar" />
<auxClasspath path="${lib.path}/json-lib-2.2.2-jdk15.jar" />
<auxClasspath path="${lib.path}/commons-lang.jar" />
<auxClasspath path="${lib.path}/commons-httpclient-2.0.jar" />
<auxClasspath path="${lib.path}/weblogic.jar" />
<auxClasspath path="${lib.path}/quartz-all-1.6.0.jar" />
<auxClasspath path="${lib.path}/jaxb1-impl-2.2.jar" />
<auxClasspath path="${lib.path}/junit-4.8.1.jar" />
<class location="${auditCode.path}/action/*.class" />
<class location="${auditCode.path}/bean/*.class" />
<class location="${auditCode.path}/delegate/*.class" />
<class location="${auditCode.path}/form/*.class" />
<class location="${auditCode.path}/helper/*.class" />
<class location="${auditCode.path}/helper/ap/*.class" />
<sourcePath path="${lib.path}/trunk/src/com/此处省略/**/*.java" />
</findbugs>
</target>
</project>
-------------------
过滤文件
<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等类