]> source.dussan.org Git - sonar-scanner-cli.git/commitdiff
SQSCANNER-35 Fix script home detection and path quoting issues
authorDuarte Meneses <duarte.meneses@sonarsource.com>
Wed, 22 Feb 2017 13:05:05 +0000 (14:05 +0100)
committerDuarte Meneses <duarte.meneses@sonarsource.com>
Wed, 22 Feb 2017 14:48:05 +0000 (15:48 +0100)
src/main/assembly/bin/sonar-runner
src/main/assembly/bin/sonar-scanner

index 313a745710e071b4ea3eade94f0676e55dcfc47f..a02252d67eb3f95802622346a5fe9c0b80a29248 100755 (executable)
 # 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 "$@"
index 6b54cc9a6266f123581a6ce7c75e0b2cf15beb14..93e99d9c8d9690fb9e6ec0c5d23fb0db4033ba2b 100755 (executable)
 # 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 "$@"