findbugs ant 代码审核工具

 

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>

-------------------

过滤文件

findbugs_exclude.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等类











<project name='annogen.findbugs' default='all.clean' basedir='.'>

  <!-- Properties -->

  <property environment='env'/>
  <property name='output_dir'        location='build/findbugs'/>
  <property name='output_file'       location='${output_dir}/index.html'/>

  <property name='findbugs_home'     location='external/findbugs'/>
  <property name='findbugs_jar'      location='${findbugs_home}/lib/findbugs-ant.jar'/>
  <property name='stax_api_jar'      location='external/lib/stax-api.jar'/>
  <property name='junit_jar'         location='external/lib/junit.jar' />

  <path id='sourcepath'>
    <dirset dir='.'>
      <include name='**/src/'/>
      <include name='**/src_150'/>
    </dirset>
  </path>



  <!-- Targets -->

  <target name='all.clean' depends='clean,all'/>

  <target name='clean'>
    <delete dir='${output_dir}'/>
  </target>

  <target name='all'>
    <mkdir dir='${output_dir}'/>
    <taskdef name='findbugs'
             classname='edu.umd.cs.findbugs.anttask.FindBugsTask'
             classpath='${findbugs_jar}'/>
    <findbugs home='${findbugs_home}'
              output='html'
              outputFile='${output_file}' >
      <auxClasspath path='${stax_api_jar};${env.ANT_HOME}/lib/ant.jar;${junit_jar}' />
      <sourcePath refid='sourcepath' />
      <class location='build/classes'/>
    </findbugs>

    <echo message=''/>
    <echo message='Findbugs complete, output in ${output_file}'/>
  </target>

  <target name='view' depends='all.clean'>
    <exec dir='.' executable='explorer.exe' os='Windows 2000, Windows XP'>
      <!--<arg line="X:\metajam\jam\annogen_new\build\findbugs\index.html"/>-->
      <arg line='${output_file}'/>
    </exec>
  </target>

</project>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值