clean CPD run script

git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@7311 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
Romain Pelisse
2011-09-23 15:41:24 +00:00
parent 799f7d6002
commit 8572a62429

View File

@ -11,76 +11,107 @@
## If you run into java.lang.OutOfMemoryError, try setting the environment
## variable HEAPSIZE to e.g. 512m
DIRECTORY=$1
usage() {
echo "Usage:"
echo "$(basename ${0}) <source-directory> [--ignore-literals] [--ignore-identifiers]"
echo ""
echo "Set language with environment variable LANGUAGE ($(supported_languages))"
}
if [ -z "$1" ]; then
script=`basename $0`
echo "Usage:"
echo " $script <directory>"
exit 1
supported_languages() {
echo "c, cpp, fortran, java, jsp, php, ruby"
}
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
}
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
}
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
}
language_settings() {
readonly LANGUAGE=${LANGUAGE:-cpp}
case "${LANGUAGE}" in
c|cpp|fortran|java|jsp|php|ruby)
echo "Language is set to ${LANGUAGE}"
;;
*)
echo "Language '${LANGUAGE}' unknown (try: $(supported_languages))"
exit 1
esac
}
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
}
DIRECTORY=${1}
if [ -z "${DIRECTORY}" ]; then
usage
exit 1
fi
shift
# 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"
readonly SCRIPT_DIR=$(dirname ${0})
CWD="${PWD}"
cd "$SCRIPT_DIR/../lib"
LIB_DIR=`pwd -P`
cd "${SCRIPT_DIR}/../lib"
readonly 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
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
classpath=$classpath:$jarfile
cd "${CWD}"
for jarfile in ${LIB_DIR}/*.jar; do
classpath=${classpath}:${jarfile}
done
HEAPSIZE=${HEAPSIZE:-512m}
LANGUAGE=${LANGUAGE:-cpp}
MINIMUM_TOKENS=${MINIMUM_TOKENS:-100}
java_heapsize_settings
case "$HEAPSIZE" in
[1-9]*[mgMG]) HEAPSIZE=-Xmx$HEAPSIZE ;;
'') ;;
*) echo "HEAPSIZE '$HEAPSIZE' unknown (try: 512m)"
exit 1
esac
language_settings
case "$LANGUAGE" in
c|cpp|fortran|java|jsp|php|ruby) ;;
*) echo "Language '$LANGUAGE' unknown (try: c, cpp, fortran, java, jsp, php, ruby)"
exit 1
esac
cygwin_paths
# echo "CLASSPATH: $classpath"
# 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
java $HEAPSIZE -cp $classpath net.sourceforge.pmd.cpd.CPD --minimum-tokens $MINIMUM_TOKENS --files $DIRECTORY --language $LANGUAGE ${@}
java "${HEAPSIZE}" -cp "${classpath}" net.sourceforge.pmd.cpd.CPD \
--minimum-tokens "${MINIMUM_TOKENS:-100}"\
--files "${DIRECTORY}" \
--language "${LANGUAGE}" \
${@}