From 0c5295ed0ed729f84acd0df6971593d30056af1e Mon Sep 17 00:00:00 2001 From: Duarte Meneses Date: Wed, 22 Feb 2017 14:05:05 +0100 Subject: [PATCH] SQSCANNER-35 Fix script home detection and path quoting issues --- src/main/assembly/bin/sonar-runner | 46 ++++++++--------------------- src/main/assembly/bin/sonar-scanner | 46 ++++++++--------------------- 2 files changed, 26 insertions(+), 66 deletions(-) diff --git a/src/main/assembly/bin/sonar-runner b/src/main/assembly/bin/sonar-runner index 313a745..a02252d 100755 --- a/src/main/assembly/bin/sonar-runner +++ b/src/main/assembly/bin/sonar-runner @@ -34,35 +34,19 @@ # authors and should not be interpreted as representing official policies, either expressed # or implied, of Jon Disnard. real_path () { - OIFS=$IFS - IFS='/' - for I in $1 - do - # Resolve relative path punctuation. - if [ "$I" = "." ] || [ -z "$I" ] - then continue - elif [ "$I" = ".." ] - then FOO="${FOO%%/${FOO##*/}}" - continue - else FOO="${FOO}/${I}" - fi + target=$1 - # Dereference symbolic links. - if [ -h "$FOO" ] && [ -x "/bin/ls" ] - then IFS=$OIFS - set `/bin/ls -l "$FOO"` - while shift ; - do - if [ "$1" = "->" ] - then FOO=$2 - shift $# - break - fi - done - fi + ( + while true; do + cd "$(dirname "$target")" + target=$(basename "$target") + link=$(readlink "$target") + test "$link" || break + target=$link done - IFS=$OIFS - echo "$FOO" + + echo "$(pwd -P)/$target" + ) } echo WARN: 'sonar-runner' script is deprecated. Please use 'sonar-scanner' instead. @@ -71,11 +55,7 @@ script_path="$0" if [ -h "$script_path" ] ; then # resolve recursively symlinks - r_script_path=$(real_path "$script_path") - until [ "$R_script_path" = "$script_path" ]; do - script_path="$R_script_path" - r_script_path=$(real_path "$script_path") - done + script_path=$(real_path "$script_path") fi sonar_runner_home=$(dirname "$script_path")/.. @@ -115,7 +95,7 @@ project_home=$(pwd) exec "$java_cmd" \ -Djava.awt.headless=true \ $SONAR_SCANNER_OPTS \ - -classpath $jar_file \ + -classpath "$jar_file" \ -Dscanner.home=\$sonar_runner_home \ -Dproject.home=\$project_home \ org.sonarsource.scanner.cli.Main "$@" diff --git a/src/main/assembly/bin/sonar-scanner b/src/main/assembly/bin/sonar-scanner index 6b54cc9..93e99d9 100755 --- a/src/main/assembly/bin/sonar-scanner +++ b/src/main/assembly/bin/sonar-scanner @@ -35,46 +35,26 @@ # authors and should not be interpreted as representing official policies, either expressed # or implied, of Jon Disnard. real_path () { - OIFS=$IFS - IFS='/' - for I in $1 - do - # Resolve relative path punctuation. - if [ "$I" = "." ] || [ -z "$I" ] - then continue - elif [ "$I" = ".." ] - then FOO="${FOO%%/${FOO##*/}}" - continue - else FOO="${FOO}/${I}" - fi + target=$1 - # Dereference symbolic links. - if [ -h "$FOO" ] && [ -x "/bin/ls" ] - then IFS=$OIFS - set `/bin/ls -l "$FOO"` - while shift ; - do - if [ "$1" = "->" ] - then FOO=$2 - shift $# - break - fi - done - fi + ( + while true; do + cd "$(dirname "$target")" + target=$(basename "$target") + link=$(readlink "$target") + test "$link" || break + target=$link done - IFS=$OIFS - echo "$FOO" + + echo "$(pwd -P)/$target" + ) } script_path="$0" if [ -h "$script_path" ] ; then # resolve recursively symlinks - r_script_path=$(real_path "$script_path") - until [ "$r_script_path" = "$script_path" ]; do - script_path="$r_script_path" - r_script_path=`real_path "$script_path"` - done + script_path=$(real_path "$script_path") fi sonar_scanner_home=$(dirname "$script_path")/.. @@ -107,7 +87,7 @@ exec "$java_cmd" \ -Djava.awt.headless=true \ $SONAR_SCANNER_OPTS \ $SONAR_SCANNER_DEBUG_OPTS \ - -classpath $jar_file \ + -classpath "$jar_file" \ -Dscanner.home=\$sonar_scanner_home \ -Dproject.home=\$project_home \ org.sonarsource.scanner.cli.Main "$@" -- 2.39.5