adding PMD and CPD support

git-svn-id: http://google-refine.googlecode.com/svn/trunk@407 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
Stefano Mazzocchi 2010-04-07 17:31:25 +00:00
parent 6dbe794658
commit 6674b69773
2 changed files with 96 additions and 8 deletions

View File

@ -29,6 +29,7 @@
<property name="tests.dir" value="${basedir}/tests/java" /> <property name="tests.dir" value="${basedir}/tests/java" />
<property name="tools.dir" value="${basedir}/tools" /> <property name="tools.dir" value="${basedir}/tools" />
<property name="reports.dir" value="${build.dir}/reports" />
<property name="server_classes.dir" value="${build.dir}/classes" /> <property name="server_classes.dir" value="${build.dir}/classes" />
<property name="webapp_classes.dir" value="${basedir}/src/main/webapp/WEB-INF/classes" /> <property name="webapp_classes.dir" value="${basedir}/src/main/webapp/WEB-INF/classes" />
<property name="tests_classes.dir" value="${tests.dir}/classes" /> <property name="tests_classes.dir" value="${tests.dir}/classes" />
@ -235,19 +236,63 @@
</tar> </tar>
</target> </target>
<target name="findbugs" depends="build"> <target name="prepare_reports">
<mkdir dir="${reports.dir}" />
</target>
<target name="findbugs" depends="build,prepare_reports">
<taskdef <taskdef
name="findbugs" name="findbugs"
classname="edu.umd.cs.findbugs.anttask.FindBugsTask" classname="edu.umd.cs.findbugs.anttask.FindBugsTask"
classpath="${findbugs.dir}/lib/findbugs-ant.jar" classpath="${findbugs.dir}/lib/findbugs-ant.jar"
/> />
<findbugs jvmargs="-Xmx1024m" home="${findbugs.dir}" output="html" outputFile="${build.dir}/gridworks-findbugs.html" > <findbugs jvmargs="-Xmx1024m" home="${findbugs.dir}" output="html" outputFile="${reports.dir}/findbugs.html" >
<auxClasspath refid="class.path" /> <auxClasspath refid="class.path" />
<sourcePath path="${src.dir}" /> <sourcePath path="${src.dir}" />
<class location="${webapp_classes.dir}" /> <class location="${webapp_classes.dir}" />
</findbugs> </findbugs>
</target> </target>
<target name="pmd" depends="prepare_reports">
<path id="pmd.path">
<fileset dir="${pmd.dir}/lib" includes="*.jar"/>
</path>
<taskdef
name="pmd"
classname="net.sourceforge.pmd.ant.PMDTask"
classpathref="pmd.path"
/>
<pmd targetjdk="1.6" encoding="UTF-8">
<ruleset>basic</ruleset>
<formatter type="html" toFile="${reports.dir}/pmd.html" toConsole="true"/>
<fileset dir="${server.src.dir}">
<include name="**/*.java"/>
</fileset>
<fileset dir="${src.dir}">
<include name="**/*.java"/>
</fileset>
</pmd>
</target>
<target name="cpd" depends="prepare_reports">
<path id="pmd.path">
<fileset dir="${pmd.dir}/lib" includes="*.jar"/>
</path>
<taskdef
name="cpd"
classname="net.sourceforge.pmd.cpd.CPDTask"
classpathref="pmd.path"
/>
<cpd minimumTokenCount="100" outputFile="${reports.dir}/cpd.txt" encoding="UTF-8">
<fileset dir="${server.src.dir}">
<include name="**/*.java"/>
</fileset>
<fileset dir="${src.dir}">
<include name="**/*.java"/>
</fileset>
</cpd>
</target>
<target name="clean"> <target name="clean">
<delete file="${build.dir}/gridworks.jar" /> <delete file="${build.dir}/gridworks.jar" />
<delete dir="${server_classes.dir}" /> <delete dir="${server_classes.dir}" />

View File

@ -53,15 +53,19 @@ where [options] include:
and <action> is one of and <action> is one of
build ..................... Build Gridworks build ..................... Build Gridworks
run ....................... Run Gridworks run ....................... Run Gridworks [default]
test ...................... Run all Gridworks tests
server_test ............... Run only the server tests
ui_test ................... Run only the UI tests
test ...................... Test Gridworks
findbugs .................. Run Findbugs against Gridworks findbugs .................. Run Findbugs against Gridworks
pmd ....................... Run PMD against Gridworks
cpd ....................... Run Copy/Paste Detection against Gridworks
mac_dist <version> ........ Make MacOSX binary distribution mac_dist <version> ........ Make MacOSX binary distribution
windows_dist <version> .... Make Windows binary distribution windows_dist <version> .... Make Windows binary distribution
linux_dist <version> ...... Make Linux binary distribution linux_dist <version> ...... Make Linux binary distribution
dist <version> ............ Make all distributions dist <version> ............ Make all distributions
clean ..................... Clean compiled classes clean ..................... Clean compiled classes
@ -96,6 +100,14 @@ check_downloaders() {
fi fi
} }
check_unzip() {
UNZIP="`which unzip`"
if [ "$UNZIP" == "" ] ; then
error "We need 'unzip' present in PATH to expand external dependencies."
fi
}
check_python() { check_python() {
PYTHON="`which python`" PYTHON="`which python`"
if [ "$PYTHON" == "" ] ; then if [ "$PYTHON" == "" ] ; then
@ -163,7 +175,12 @@ tool_download() {
download $URL $FILE download $URL $FILE
fi fi
if [ ! -d "$DIR" ] ; then if [ ! -d "$DIR" ] ; then
if [ `echo $FILE | sed 's|.*.(tar.gz|tgz)$||'` == "" ] ; then
tar xzf $FILE || error "Error while expanding $FILE" tar xzf $FILE || error "Error while expanding $FILE"
elif [ `echo $FILE | sed 's|.*.zip$||'` == "" ] ; then
check_unzip
$UNZIP $FILE || error "Error while expanding $FILE"
fi
fi fi
cd .. cd ..
} }
@ -280,6 +297,16 @@ findbugs_prepare() {
tool_download $FINDBUGS_URL $FINDBUGS_FILE $FINDBUGS_DIR tool_download $FINDBUGS_URL $FINDBUGS_FILE $FINDBUGS_DIR
} }
pmd_prepare() {
tools_prepare
PMD_URL="http://downloads.sourceforge.net/project/pmd/pmd/4.2.5/pmd-bin-4.2.5.zip"
PMD_FILE="pmd-bin-4.2.5.zip"
PMD_DIR="pmd-4.2.5"
tool_download $PMD_URL $PMD_FILE $PMD_DIR
}
# ---------------------------------------------------------------------------------------------- # ----------------------------------------------------------------------------------------------
ant() { ant() {
@ -492,7 +519,7 @@ run() {
echo "" echo ""
if [ "$FORK" == "" ] ; then if [ "$FORK" == "" ] ; then
exec "$RUN_CMD" exec $RUN_CMD
else else
sh -c "$RUN_CMD" & sh -c "$RUN_CMD" &
GRIDWORKS_PID="$!" GRIDWORKS_PID="$!"
@ -522,6 +549,20 @@ findbugs() {
ant findbugs ant findbugs
} }
pmd() {
pmd_prepare
ANT_PARAMS="-Dpmd.dir=${GRIDWORKS_TOOLS_DIR}/${PMD_DIR}"
ant pmd
}
cpd() {
pmd_prepare
ANT_PARAMS="-Dpmd.dir=${GRIDWORKS_TOOLS_DIR}/${PMD_DIR}"
ant cpd
}
# -------------------------- script ----------------------------- # -------------------------- script -----------------------------
# ----- Normalize the current directory ------------------------- # ----- Normalize the current directory -------------------------
@ -642,6 +683,8 @@ case "$ACTION" in
ui_test) ui_test $1;; ui_test) ui_test $1;;
server_test) server_test $1;; server_test) server_test $1;;
findbugs) findbugs;; findbugs) findbugs;;
pmd) pmd;;
cpd) cpd;;
run) run;; run) run;;
execute) execute $*;; execute) execute $*;;
mac_dist) mac_dist $1;; mac_dist) mac_dist $1;;