findbugs的ant脚本实践

时间:2023-12-29 19:01:44
<?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>