findbugs的ant脚本实践

<?xml version="1.0" encoding="UTF-8"?>

<project name="codeCheck" default="findbugs">
  
  <property file="confi.properties" />

  <path id="findbugs.lib">
      <fileset dir="${findbugs.home}/lib">
         <include name="findbugs-ant.jar"/>
      </fileset>
   </path>

  <taskdef name="findbugs" classname="edu.umd.cs.findbugs.anttask.FindBugsTask">
	<classpath refid="findbugs.lib" />
  </taskdef>

  <taskdef name="computeBugHistory" classname="edu.umd.cs.findbugs.anttask.ComputeBugHistoryTask">
      <classpath refid="findbugs.lib" />
   </taskdef>

   <taskdef name="setBugDatabaseInfo" classname="edu.umd.cs.findbugs.anttask.SetBugDatabaseInfoTask">
      <classpath refid="findbugs.lib" />
   </taskdef>

   <taskdef name="mineBugHistory" classname="edu.umd.cs.findbugs.anttask.MineBugHistoryTask">
      <classpath refid="findbugs.lib" />
   </taskdef>
  
  <!-- hi,look, this is procedure --> 
   <target name="findbugs">
	  <antcall target="analyze" />
	  <antcall target="mine" />
      <antcall target="report" />
   </target>

  <!-- findbugs task definition -->
  <target name="analyze">
    <findbugs home="${findbugs.home}"
			  projectName="${project.name}"
              output="xml:withMessages"
              outputFile="out.xml"
			  reportLevel="low"
			  effort="max"
              includeFilter="includerFilter.xml"			  
			 >
	  <auxClasspath path="${project.home}/${depend.lib.dir1}/xxx.jar" />
	  <auxClasspath path="${project.home}/${depend.lib.dir2}/xxxjar" /> 
      <class location="${project.home}/${class1.dir}" />
	  <class location="${project.home}/${class2.dir}" />
    </findbugs>
  </target>

  <!-- mine task -->
  <target name="mine">

	<!-- Set info to the latest analysis -->
	<setBugDatabaseInfo home="${findbugs.home}"
						withMessages="true"
						name="${project.version}"
						input="out.xml"
						output="out-rel.xml"/>

	<!-- Checking if history file already exists (out-hist.xml) -->
	<condition property="mining.historyfile.available">
	  <available file="out-hist.xml"/>
	</condition>
	<condition property="mining.historyfile.notavailable">
	  <not>
		<available file="out-hist.xml"/>
	  </not>
	</condition>

	<!-- this target is executed if the history file do not exist (first run) -->
	<antcall target="history-init">
	  <param name="data.file" value="out-rel.xml" />
	  <param name="hist.file" value="out-hist.xml" />
	</antcall>
	<!-- else this one is executed -->
	<antcall target="history">
	  <param name="data.file"         value="out-rel.xml" />
	  <param name="hist.file"         value="out-hist.xml" />
	  <param name="hist.summary.file" value="out-hist.txt" />
	</antcall>
  </target>

  <!-- Initializing history file -->
  <target name="history-init" if="mining.historyfile.notavailable">
	<copy file="${data.file}" tofile="${hist.file}" />
  </target>

  <!-- Computing bug history -->
  <target name="history" if="mining.historyfile.available">
	<!-- Merging ${data.file} into ${hist.file} -->
	<computeBugHistory home="${findbugs.home}"
					   withMessages="true"
					   output="${hist.file}">
	  <dataFile name="${hist.file}"/>
	  <dataFile name="${data.file}"/>
	</computeBugHistory>

	<!-- Compute history into ${hist.summary.file} -->
	<mineBugHistory home="${findbugs.home}"
					formatDates="true"
					noTabs="true"
					input="${hist.file}"
					output="${hist.summary.file}"/>
  </target>

  <!-- report task -->
  <target name="report">	
	<xslt in="out-rel.xml"
            out="rep/default.html"
            style="${findbugs.home}/src/xsl/default.xsl" /> 
	
	<xslt in="out-rel.xml"
		  out="rep/fancy.html"
		  style="${findbugs.home}/src/xsl/fancy.xsl" />

	<xslt in="out-hist.xml"
		  out="rep/fancy-hist.html"
		  style="${findbugs.home}/src/xsl/fancy-hist.xsl" />

	<xslt in="out-rel.xml"
		  out="rep/plain.html"
		  style="${findbugs.home}/src/xsl/plain.xsl" />

	<xslt in="out-rel.xml"
		  out="rep/sum.html"
		  style="${findbugs.home}/src/xsl/summary.xsl" />

	<xslt in="out-rel.xml"
		  out="rep/all.csv"
		  style="xsl/s4csv.xsl" />

	<xslt in="out-rel.xml"
		 out="rep/all.html"
		 style="xsl/s4html.xsl" />

	<!-- Checking if history file already exists (out-hist.xml) -->
	<condition property="generate.available">
	  <available file="out-hist.xml"/>
	</condition>
	<!-- this target is executed if the history file do not exist (first run) -->
	<antcall target="generate_email_report">
	</antcall>
  </target>

  <!-- generate report, current revision's New warnings -->
  <target name="generate_email_report" if="generate.available">
	<delete file="rep/new.csv" />
	<copy file="out-hist.xml" tofile="out-hist-copy.xml" />
	<xslt in="out-hist-copy.xml"
		  out="rep/news.csv"
		  style="xsl/s4csv_news.xsl" />
	<xslt in="out-hist-copy.xml"
		  out="rep/news.html"
		  style="xsl/s4html_news.xsl" />
	<delete file="out-hist-copy.xml" />
	<!-- sned_email -->
	<condition property="send.available">
	  <available file="rep/news.html" />
	</condition>
	<antcall target="send_email">
	</antcall>
  </target>

  <!-- send email -->
  <target name="send_email" if="send.available">
	<!-- TODO -->
  </target>
  

</project>

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值