Jenkinsを導入したので、FindBugsを使ってソースコードを静的解析し、潜在的なバグの可能性のある箇所を指摘してもらうまでの手順です。
インストール環境
今回のサーバ環境は、以下のとおりです。
$ less /etc/redhat-release CentOS release 5.8 (Final)
Antをインストール
Apache Ant - Binary Distributions から最新版をダウンロードして転送するか、Jenkinsサーバからwgetでダウンロードします。解凍して /usr/local/ に置きました。
# tar zxfv apache-ant-1.8.4-bin.tar.gz # mv apache-ant-1.8.4 /usr/local/ant
環境変数の設定
Antの環境変数と、Antにパスを通します。
# vi /etc/profile
以下を追記。
export ANT_HOME=/usr/local/ant export PATH=$PATH:$ANT_HOME/bin
設定を反映しましょう。
# source /etc/profile
FindBugsをインストール
FindBugs Downloads から最新版をダウンロードしてjenkinsサーバに転送します。解凍して /usr/local/ に置きました。
# tar zxfv findbugs-2.0.1.tar.gz # mv findbugs-2.0.1 /usr/local/findbugs
環境変数の設定
FindBugsの環境変数と、FindBugsにパスを通します。
# vi /etc/profile
以下を追記。
export FINDBUGS_HOME=/usr/local/findbugs export PATH=$PATH:$FINDBUGS_HOME/bin
設定を反映しましょう。
# source /etc/profile
Antタスクのインストール
$FINDBUGS_HOME/lib/findbugs-ant.jar を $ANT_HOME/lib/にコピーします。
# cp $FINDBUGS_HOME/lib/findbugs-ant.jar $ANT_HOME/lib/
build.xmlを修正
FindBugsのタスクを追加します。この辺はプロジェクトで違ってくるので参考までに例として載せます。
ここでポイントは、auxClasspathに解析が必要ないライブラリを追加しておくことです。pathタグで除外するファイル群を指定して、auxClasspathのrefidに設定しましょう。
<!-- ビルドに必要なファイル群 --> <path id="build.classpath"> <fileset dir="lib"> <include name="*.jar"/> </fileset> <fileset dir="${build.webinf}/lib"> <include name="*.jar"/> </fileset> <fileset dir="/usr/local/tomcat/lib"> <include name="*.jar"/> </fileset> </path> <property name="build.OutputDir" value="src/main/webapp/WEB-INF/classes"/> <property name="build.SourceDir" value="src/main/java"/> <!-- - - - - - - - - - - - - - - - - - findbugsを実行 - - - - - - - - - - - - - - - - - --> <property environment="env" /> <condition property="have.findbugs"> <and> <available classname="edu.umd.cs.findbugs.anttask.FindBugsTask" /> <available file="${env.FINDBUGS_HOME}" /> </and> </condition> <target name="Findbugs" if="have.findbugs"> <taskdef name="findbugs" classname="edu.umd.cs.findbugs.anttask.FindBugsTask" /> <findbugs home="${env.FINDBUGS_HOME}" effort="max" output="xml" outputFile="findbugs.xml" > <auxClasspath refid="build.classpath" /> <sourcePath path="${build.SourceDir}" /> <class location="${build.OutputDir}" /> </findbugs> </target>