diff --git a/spring-boot-project/spring-boot-cli/src/main/executablecontent/bin/spring b/spring-boot-project/spring-boot-cli/src/main/executablecontent/bin/spring index 21ba6a064b..3411a395a4 100755 --- a/spring-boot-project/spring-boot-cli/src/main/executablecontent/bin/spring +++ b/spring-boot-project/spring-boot-cli/src/main/executablecontent/bin/spring @@ -1,9 +1,9 @@ #!/usr/bin/env bash # OS specific support (must be 'true' or 'false'). -cygwin=false; -darwin=false; -case "`uname`" in +cygwin=false +darwin=false +case "$(uname)" in CYGWIN*) cygwin=true ;; @@ -18,63 +18,79 @@ case "`uname`" in esac # For Cygwin, ensure paths are in UNIX format before anything is touched. -if $cygwin ; then - [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` +if ${cygwin} ; then + [ -n "${JAVA_HOME}" ] && JAVA_HOME=$(cygpath --unix "${JAVA_HOME}") fi # Attempt to find JAVA_HOME if not already set if [ -z "${JAVA_HOME}" ]; then - if $darwin ; then - [ -z "$JAVA_HOME" -a -f "/usr/libexec/java_home" ] && export JAVA_HOME=`/usr/libexec/java_home` - [ -z "$JAVA_HOME" -a -d "/Library/Java/Home" ] && export JAVA_HOME="/Library/Java/Home" - [ -z "$JAVA_HOME" -a -d "/System/Library/Frameworks/JavaVM.framework/Home" ] && export JAVA_HOME="/System/Library/Frameworks/JavaVM.framework/Home" + if ${darwin} ; then + if [[ -z "${JAVA_HOME}" && -f "/usr/libexec/java_home" ]]; then + JAVA_HOME=$(/usr/libexec/java_home) + export JAVA_HOME + fi + if [[ -z "${JAVA_HOME}" && -d "/Library/Java/Home" ]]; then + export JAVA_HOME="/Library/Java/Home" + fi + if [[ -z "${JAVA_HOME}" && -d "/System/Library/Frameworks/JavaVM.framework/Home" ]]; then + export JAVA_HOME="/System/Library/Frameworks/JavaVM.framework/Home" + fi else - javaExecutable="`which javac`" - [ -z "$javaExecutable" -o "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ] && echo "JAVA_HOME not set and cannot find javac to deduce location, please set JAVA_HOME." && exit 1 + javaExecutable="$(command -v javac)" + if [[ -z "$javaExecutable" || "$(expr "${javaExecutable}" : '\([^ ]*\)')" = "no" ]]; then + echo "JAVA_HOME not set and cannot find javac to deduce location, please set JAVA_HOME." + exit 1 + fi # readlink(1) is not available as standard on Solaris 10. - readLink=`which readlink` - [ `expr "$readLink" : '\([^ ]*\)'` = "no" ] && echo "JAVA_HOME not set and readlink not available, please set JAVA_HOME." && exit 1 - javaExecutable="`readlink -f \"$javaExecutable\"`" - javaHome="`dirname \"$javaExecutable\"`" - javaHome=`expr "$javaHome" : '\(.*\)/bin'` - JAVA_HOME="$javaHome" + readLink="$(command -v readlink)" + [ "$(expr "${readLink}" : '\([^ ]*\)')" = "no" ] && { + echo "JAVA_HOME not set and readlink not available, please set JAVA_HOME." + exit 1 + } + javaExecutable="$(readlink -f "${javaExecutable}")" + javaHome="$(dirname "${javaExecutable}")" + javaHome=$(expr "$javaHome" : '\(.*\)/bin') + JAVA_HOME="${javaHome}" export JAVA_HOME fi fi # Sanity check that we have java if [ ! -f "${JAVA_HOME}/bin/java" ]; then - echo "" - echo "======================================================================================================" - echo " Please ensure that your JAVA_HOME points to a valid Java SDK." - echo " You are currently pointing to:" - echo "" - echo " ${JAVA_HOME}" - echo "" - echo " This does not seem to be valid. Please rectify and restart." - echo "======================================================================================================" - echo "" + cat <<-JAVA_HOME_NOT_SET_TXT + + ====================================================================================================== + Please ensure that your JAVA_HOME points to a valid Java SDK. + You are currently pointing to: + + ${JAVA_HOME} + + This does not seem to be valid. Please rectify and restart. + ====================================================================================================== + + JAVA_HOME_NOT_SET_TXT exit 1 fi # Attempt to find SPRING_HOME if not already set if [ -z "${SPRING_HOME}" ]; then - # Resolve links: $0 may be a link - PRG="$0" - # Need this for relative symlinks. - while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi - done - SAVED="`pwd`" - cd "`dirname \"$PRG\"`/../" >&- - export SPRING_HOME="`pwd -P`" - cd "$SAVED" >&- + # Resolve links: $0 may be a link + PRG="$0" + # Need this for relative symlinks. + while [ -h "$PRG" ] ; do + ls=$(ls -ld "$PRG") + link=$(expr "$ls" : '.*-> \(.*\)$') + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=$(dirname "$PRG")"/$link" + fi + done + SAVED="$(pwd)" + cd "$(dirname "${PRG}")/../" >&- || exit 1 + SPRING_HOME="$(pwd -P)" + export SPRING_HOME + cd "$SAVED" >&- || exit 1 fi if [ ! -d "${SPRING_HOME}" ]; then @@ -84,16 +100,17 @@ if [ ! -d "${SPRING_HOME}" ]; then fi CLASSPATH=.:${SPRING_HOME}/bin -if [ -d ${SPRING_HOME}/ext ]; then +if [ -d "${SPRING_HOME}/ext" ]; then CLASSPATH=$CLASSPATH:${SPRING_HOME}/ext fi -for f in ${SPRING_HOME}/lib/*; do +for f in "${SPRING_HOME}"/lib/*; do CLASSPATH=$CLASSPATH:$f done if $cygwin; then - SPRING_HOME=`cygpath --path --mixed "$SPRING_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + SPRING_HOME=$(cygpath --path --mixed "$SPRING_HOME") + CLASSPATH=$(cygpath --path --mixed "$CLASSPATH") fi -"${JAVA_HOME}/bin/java" ${JAVA_OPTS} -cp "$CLASSPATH" org.springframework.boot.loader.JarLauncher "$@" +IFS=" " read -r -a javaOpts <<< "$JAVA_OPTS" +"${JAVA_HOME}/bin/java" "${javaOpts[@]}" -cp "$CLASSPATH" org.springframework.boot.loader.JarLauncher "$@" \ No newline at end of file