From 3be4a20b49932527b3684f1996417360660e99bb Mon Sep 17 00:00:00 2001 From: Duarte Meneses Date: Tue, 21 Feb 2017 18:08:28 +0100 Subject: [PATCH] SQSCANNER-34 Don't use user-defined SONAR_SCANNER_HOME --- src/main/assembly/bin/sonar-runner | 58 +++++++++++------------ src/main/assembly/bin/sonar-runner.bat | 16 ------- src/main/assembly/bin/sonar-scanner | 58 +++++++++++------------ src/main/assembly/bin/sonar-scanner-debug | 2 +- src/main/assembly/bin/sonar-scanner.bat | 17 ------- 5 files changed, 57 insertions(+), 94 deletions(-) diff --git a/src/main/assembly/bin/sonar-runner b/src/main/assembly/bin/sonar-runner index 7c314f1..d80dcf7 100755 --- a/src/main/assembly/bin/sonar-runner +++ b/src/main/assembly/bin/sonar-runner @@ -3,8 +3,8 @@ # SonarQube Runner Startup Script for Unix # # Optional ENV vars: -# SONAR_RUNNER_HOME - location of runner's installed home dir -# SONAR_RUNNER_OPTS - parameters passed to the Java VM when running Sonar +# SONAR_RUNNER_OPTS - Parameters passed to the Java VM when running Sonar +# JAVA_HOME - Location of Java's installation # The following notice only apply to real_path function copied from # https://sites.google.com/site/jdisnard/realpath @@ -67,35 +67,33 @@ real_path () { echo WARN: 'sonar-runner' script is deprecated. Please use 'sonar-scanner' instead. -if [ -z "$SONAR_RUNNER_HOME" ] ; then - PRG="$0" +PRG="$0" - if [ -h "$PRG" ] ; then - # resolve recursively symlinks +if [ -h "$PRG" ] ; then + # resolve recursively symlinks + R_PRG=`real_path "$PRG"` + until [ "$R_PRG" = "$PRG" ]; do + PRG="$R_PRG" R_PRG=`real_path "$PRG"` - until [ "$R_PRG" = "$PRG" ]; do - PRG="$R_PRG" - R_PRG=`real_path "$PRG"` - done - fi + done +fi - SONAR_RUNNER_HOME=`dirname "$PRG"`/.. +sonar_runner_home=`dirname "$PRG"`/.. - # make it fully qualified - SONAR_RUNNER_HOME=`cd "$SONAR_RUNNER_HOME" && pwd` -fi +# make it fully qualified +sonar_runner_home=`cd "$sonar_runner_home" && pwd` -# check that the SONAR_RUNNER_HOME has been correctly set -if [ ! -f "$SONAR_RUNNER_HOME/lib/sonar-scanner-cli-${project.version}.jar" ] ; then - echo '$SONAR_RUNNER_HOME' does not point to a valid installation directory: $SONAR_RUNNER_HOME +# check that the sonar_runner_home has been correctly set +if [ ! -f "$sonar_runner_home/lib/sonar-scanner-cli-${project.version}.jar" ] ; then + echo '$sonar_runner_home' does not point to a valid installation directory: $sonar_runner_home exit 1 fi if [ -n "$JAVA_HOME" ] then - JAVA_CMD="$JAVA_HOME/bin/java" + java_cmd="$JAVA_HOME/bin/java" else - JAVA_CMD="`which java`" + java_cmd="`which java`" fi if [ -n "$SONAR_RUNNER_OPTS" ] ; @@ -106,19 +104,19 @@ then fi fi -JAR_FILE="${SONAR_RUNNER_HOME}"/lib/sonar-scanner-cli-${project.version}.jar -PROJECT_HOME=`pwd` +jar_file="${sonar_runner_home}"/lib/sonar-scanner-cli-${project.version}.jar +project_home=`pwd` -#echo "Info: Using sonar-runner at $SONAR_RUNNER_HOME" -#echo "Info: Using java at $JAVA_CMD" -#echo "Info: Using classpath $JAR_FILE" -#echo "Info: Using project $PROJECT_HOME" +#echo "Info: Using sonar-runner at $sonar_runner_home" +#echo "Info: Using java at $java_cmd" +#echo "Info: Using classpath $jar_file" +#echo "Info: Using project $project_home" -exec "$JAVA_CMD" \ +exec "$java_cmd" \ -Djava.awt.headless=true \ $SONAR_SCANNER_OPTS \ - -classpath $JAR_FILE \ - "-Dscanner.home=\${SONAR_RUNNER_HOME}" \ - "-Dproject.home=\${PROJECT_HOME}" \ + -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-runner.bat b/src/main/assembly/bin/sonar-runner.bat index 7ff47ba..4b2af66 100644 --- a/src/main/assembly/bin/sonar-runner.bat +++ b/src/main/assembly/bin/sonar-runner.bat @@ -4,7 +4,6 @@ @REM JAVA_HOME - location of a JDK home dir @REM @REM Optional ENV vars: -@REM SONAR_RUNNER_HOME - location of runner's installed home dir @REM SONAR_RUNNER_OPTS - parameters passed to the Java VM when running Sonar @echo off @@ -49,25 +48,10 @@ goto error :foundJavaExeFromJavaHome set JAVA_EXEC="%JAVA_HOME%\bin\java.exe" -@REM *** SONAR RUNNER HOME VALIDATION *** :OkJava -if NOT "%SONAR_RUNNER_HOME%"=="" goto cleanSonarRunnerHome set SONAR_RUNNER_HOME=%~dp0.. goto sonarRunnerOpts -:cleanSonarRunnerHome -@REM If the property has a trailing backslash, remove it -if "%SONAR_RUNNER_HOME:~-1%"=="\" set SONAR_RUNNER_HOME=%SONAR_RUNNER_HOME:~0,-1% - -@REM Check if the provided SONAR_RUNNER_HOME is a valid install dir -IF EXIST "%SONAR_RUNNER_HOME%\lib\sonar-scanner-cli-${project.version}.jar" goto sonarRunnerOpts - -echo. -echo ERROR: SONAR_RUNNER_HOME exists but does not point to a valid install -echo directory: %SONAR_RUNNER_HOME% -echo. -goto error - @REM ==== HANDLE DEPRECATED SONAR_RUNNER_OPTS ==== :sonarRunnerOpts if "%SONAR_RUNNER_OPTS%" == "" ( diff --git a/src/main/assembly/bin/sonar-scanner b/src/main/assembly/bin/sonar-scanner index 59586af..b24be61 100755 --- a/src/main/assembly/bin/sonar-scanner +++ b/src/main/assembly/bin/sonar-scanner @@ -3,9 +3,9 @@ # SonarQube Scanner Startup Script for Unix # # Optional ENV vars: -# SONAR_SCANNER_HOME - location of runner's installed home dir -# SONAR_SCANNER_OPTS - parameters passed to the Java VM when running SonarQube Scanner +# SONAR_SCANNER_OPTS - Parameters passed to the Java VM when running SonarQube Scanner # SONAR_SCANNER_DEBUG_OPTS - Extra parameters passed to the Java VM for debugging +# JAVA_HOME - Location of Java's installation # The following notice only apply to real_path function copied from # https://sites.google.com/site/jdisnard/realpath @@ -66,51 +66,49 @@ real_path () { echo "$FOO" } -if [ -z "$SONAR_SCANNER_HOME" ] ; then - PRG="$0" +PRG="$0" - if [ -h "$PRG" ] ; then - # resolve recursively symlinks +if [ -h "$PRG" ] ; then + # resolve recursively symlinks + R_PRG=`real_path "$PRG"` + until [ "$R_PRG" = "$PRG" ]; do + PRG="$R_PRG" R_PRG=`real_path "$PRG"` - until [ "$R_PRG" = "$PRG" ]; do - PRG="$R_PRG" - R_PRG=`real_path "$PRG"` - done - fi + done +fi - SONAR_SCANNER_HOME=`dirname "$PRG"`/.. +sonar_scanner_home=`dirname "$PRG"`/.. - # make it fully qualified - SONAR_SCANNER_HOME=`cd "$SONAR_SCANNER_HOME" && pwd -P` -fi +# make it fully qualified +sonar_scanner_home=`cd "$sonar_scanner_home" && pwd -P` -# check that the SONAR_SCANNER_HOME has been correctly set -if [ ! -f "$SONAR_SCANNER_HOME/lib/sonar-scanner-cli-${project.version}.jar" ] ; then - echo '$SONAR_SCANNER_HOME' does not point to a valid installation directory: $SONAR_SCANNER_HOME +# check that sonar_scanner_home has been correctly set +if [ ! -f "$sonar_scanner_home/lib/sonar-scanner-cli-${project.version}.jar" ] ; then + echo '$sonar_scanner_home' does not point to a valid installation directory: $sonar_scanner_home exit 1 fi if [ -n "$JAVA_HOME" ] then - JAVA_CMD="$JAVA_HOME/bin/java" + java_cmd="$JAVA_HOME/bin/java" else - JAVA_CMD="`which java`" + java_cmd="`which java`" fi -JAR_FILE="${SONAR_SCANNER_HOME}"/lib/sonar-scanner-cli-${project.version}.jar -PROJECT_HOME=`pwd` +jar_file="${sonar_scanner_home}"/lib/sonar-scanner-cli-${project.version}.jar +project_home=`pwd` -#echo "Info: Using sonar-scanner at $SONAR_SCANNER_HOME" -#echo "Info: Using java at $JAVA_CMD" -#echo "Info: Using classpath $JAR_FILE" -#echo "Info: Using project $PROJECT_HOME" +#echo "Info: Using sonar-scanner at $sonar_scanner_home" +#echo "Info: Using java at $java_cmd" +#echo "Info: Using classpath $jar_file" +#echo "Info: Using project $project_home" -exec "$JAVA_CMD" \ +exec "$java_cmd" \ -Djava.awt.headless=true \ $SONAR_SCANNER_OPTS \ $SONAR_SCANNER_DEBUG_OPTS \ - -classpath $JAR_FILE \ - "-Dscanner.home=\${SONAR_SCANNER_HOME}" \ - "-Dproject.home=\${PROJECT_HOME}" \ + -classpath $jar_file \ + "-Dscanner.home=\${sonar_scanner_home}" \ + "-Dproject.home=\${project_home}" \ org.sonarsource.scanner.cli.Main "$@" diff --git a/src/main/assembly/bin/sonar-scanner-debug b/src/main/assembly/bin/sonar-scanner-debug index d07aca2..1fab485 100755 --- a/src/main/assembly/bin/sonar-scanner-debug +++ b/src/main/assembly/bin/sonar-scanner-debug @@ -3,8 +3,8 @@ # SonarQube Scanner Startup Script for Unix # # Optional ENV vars: -# SONAR_SCANNER_HOME - location of runner's installed home dir # SONAR_SCANNER_OPTS - parameters passed to the Java VM when running SonarQube Scanner +# JAVA_HOME - Location of Java's installation # The following notice only apply to real_path function copied from # https://sites.google.com/site/jdisnard/realpath diff --git a/src/main/assembly/bin/sonar-scanner.bat b/src/main/assembly/bin/sonar-scanner.bat index 9f3b98e..bd4c920 100644 --- a/src/main/assembly/bin/sonar-scanner.bat +++ b/src/main/assembly/bin/sonar-scanner.bat @@ -4,7 +4,6 @@ @REM JAVA_HOME - location of a JDK home dir @REM @REM Optional ENV vars: -@REM SONAR_SCANNER_HOME - location of runner's installed home dir @REM SONAR_SCANNER_OPTS - parameters passed to the Java VM when running Sonar @echo off @@ -47,26 +46,10 @@ goto error :foundJavaExeFromJavaHome set JAVA_EXEC="%JAVA_HOME%\bin\java.exe" -@REM *** SONAR SCANNER HOME VALIDATION *** :OkJava -if NOT "%SONAR_SCANNER_HOME%"=="" goto cleanSQScannerHome set SONAR_SCANNER_HOME=%~dp0.. goto run -:cleanSQScannerHome -@REM If the property has a trailing backslash, remove it -if "%SONAR_SCANNER_HOME:~-1%"=="\" set SONAR_SCANNER_HOME=%SONAR_SCANNER_HOME:~0,-1% - -@REM Check if the provided SONAR_SCANNER_HOME is a valid install dir -IF EXIST "%SONAR_SCANNER_HOME%\lib\sonar-scanner-cli-${project.version}.jar" goto run - -echo. -echo ERROR: SONAR_SCANNER_HOME exists but does not point to a valid install -echo directory: %SONAR_SCANNER_HOME% -echo. -goto error - - @REM ==== START RUN ==== :run -- 2.39.5