clean PMD run script

Also port the settings of java's heapsize, using a env var, from the CPD run script

git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@7312 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
Romain Pelisse
2011-09-23 16:05:59 +00:00
parent 8572a62429
commit 4a38a850fa

View File

@ -1,42 +1,72 @@
#!/bin/bash
if [ -z "$3" ]; then
script=`basename $0`
usage() {
echo "Usage:"
echo " $script <java-src-file> html|xml|text|vbhtml rulesetfile1[,rulesetfile2[,..]]"
echo " $(basename $0) <java-src-file> html|xml|text|vbhtml rulesetfile1[,rulesetfile2[,..]]"
}
is_cygwin() {
case "$(uname)" in
CYGWIN*)
readonly cygwin=true
;;
esac
# OS specific support. $var _must_ be set to either true or false.
if [ -z ${cygwin} ] ; then
readonly cygwin=false
fi
}
cygwin_paths() {
# For Cygwin, switch paths to Windows format before running java
if ${cygwin} ; then
JAVA_HOME=$(cygpath --windows "${JAVA_HOME}")
classpath=$(cygpath --path --windows "${classpath}")
DIRECTORY=$(cygpath --windows "${DIRECTORY}")
fi
}
convert_cygwin_vars() {
# If cygwin, convert to Unix form before manipulating
if $cygwin ; then
[ -n "${JAVA_HOME}" ] &&
JAVA_HOME=$(cygpath --unix "${JAVA_HOME}")
[ -n "${CLASSPATH}" ] &&
CLASSPATH=$(cygpath --path --unix "${CLASSPATH}")
fi
}
java_heapsize_settings() {
local heapsize=${HEAPSIZE:-512m}
case "${heapsize}" in
[1-9]*[mgMG])
readonly HEAPSIZE="-Xmx${heapsize}"
;;
'')
;;
*)
echo "HEAPSIZE '${HEAPSIZE}' unknown (try: 512m)"
exit 1
esac
}
if [ -z "$3" ]; then
usage
exit 1
fi
# OS specific support. $var _must_ be set to either true or false.
cygwin=false;
case "`uname`" in
CYGWIN*) cygwin=true ;;
esac
is_cygwin
SCRIPT_DIR=`dirname $0`
CWD="$PWD"
SCRIPT_DIR=$(dirname ${0})
CWD="${PWD}"
cd "$SCRIPT_DIR/../lib"
LIB_DIR=`pwd -P`
cd "${SCRIPT_DIR}/../lib"
LIB_DIR=$(pwd -P)
# If cygwin, convert to Unix form before manipulating
if $cygwin ; then
[ -n "$JAVA_HOME" ] &&
JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
[ -n "$CLASSPATH" ] &&
CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
fi
convert_cygwin_vars
classpath=$CLASSPATH
build_dir="$SCRIPT_DIR/../build"
if [ -d "$build_dir" ]; then
cd "$build_dir"
build_dir=`pwd -P`
classpath=$classpath:$build_dir
fi
cd "$CWD"
for jarfile in `ls $LIB_DIR/*.jar`; do
@ -44,19 +74,14 @@ for jarfile in `ls $LIB_DIR/*.jar`; do
done
FILE=$1
readonly FILE="${1}"
shift
FORMAT=$1
readonly FORMAT="${1}"
shift
RULESETFILES="$@"
readonly RULESETFILES="$@"
# echo "CLASSPATH: $classpath"
cygwin_paths
# For Cygwin, switch paths to Windows format before running java
if $cygwin; then
JAVA_HOME=`cygpath --windows "$JAVA_HOME"`
classpath=`cygpath --path --windows "$classpath"`
FILE=`cygpath --windows "$FILE"`
fi
java_heapsize_settings
java -Xmx512m -cp $classpath net.sourceforge.pmd.PMD $FILE $FORMAT $RULESETFILES
java "${HEAPSIZE}" -cp "${classpath}" net.sourceforge.pmd.PMD $FILE $FORMAT $RULESETFILES