From 4a38a850fa7e10c9ec5e86a603cc18e528abc326 Mon Sep 17 00:00:00 2001 From: Romain Pelisse Date: Fri, 23 Sep 2011 16:05:59 +0000 Subject: [PATCH] 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 --- pmd/bin/pmd.sh | 101 ++++++++++++++++++++++++++++++------------------- 1 file changed, 63 insertions(+), 38 deletions(-) diff --git a/pmd/bin/pmd.sh b/pmd/bin/pmd.sh index 67006ade61..89de53ba7a 100755 --- a/pmd/bin/pmd.sh +++ b/pmd/bin/pmd.sh @@ -1,42 +1,72 @@ #!/bin/bash -if [ -z "$3" ]; then - script=`basename $0` +usage() { echo "Usage:" - echo " $script html|xml|text|vbhtml rulesetfile1[,rulesetfile2[,..]]" + echo " $(basename $0) 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