diff options
author | Dimitris Kavvathas <dimitris.kavvathas@sonarsource.com> | 2022-08-09 17:34:22 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2022-08-10 20:03:08 +0000 |
commit | e12852cc16f5d328c25e6569759d0eb1ee467835 (patch) | |
tree | f7376b257f5c40f083b180c2b99fde06e5ee347e /sonar-application | |
parent | a5d505ac9b71b401691f452c69a994495c09cedb (diff) | |
download | sonarqube-e12852cc16f5d328c25e6569759d0eb1ee467835.tar.gz sonarqube-e12852cc16f5d328c25e6569759d0eb1ee467835.zip |
SONAR-17137 add SONAR_JAVA_PATH environmental variable for user-defined Java executable path
Diffstat (limited to 'sonar-application')
-rw-r--r-- | sonar-application/build.gradle | 10 | ||||
-rw-r--r-- | sonar-application/src/main/assembly/bin/windows-x86-64/SonarService.bat | 32 | ||||
-rw-r--r-- | sonar-application/src/main/assembly/bin/windows-x86-64/SonarService.xml | 25 | ||||
-rwxr-xr-x | sonar-application/src/main/assembly/bin/windows-x86-64/StartSonar.bat | 49 | ||||
-rw-r--r-- | sonar-application/src/main/assembly/bin/windows-x86-64/lib/SonarServiceWrapper.exe (renamed from sonar-application/src/main/assembly/bin/windows-x86-64/SonarService.exe) | bin | 655872 -> 655872 bytes | |||
-rw-r--r-- | sonar-application/src/main/assembly/bin/windows-x86-64/lib/SonarServiceWrapper.xml | 45 | ||||
-rw-r--r-- | sonar-application/src/main/assembly/bin/windows-x86-64/lib/find_java.bat | 32 |
7 files changed, 142 insertions, 51 deletions
diff --git a/sonar-application/build.gradle b/sonar-application/build.gradle index 1784e591257..d8f39a1363b 100644 --- a/sonar-application/build.gradle +++ b/sonar-application/build.gradle @@ -141,7 +141,7 @@ task zip(type: Zip, dependsOn: [configurations.compileClasspath, tasks.downloadL from(file('src/main/assembly')) { exclude 'conf/sonar.properties' exclude 'conf/wrapper.conf' - exclude 'bin/windows-x86-64/SonarService.xml' + exclude 'bin/windows-x86-64/lib/SonarServiceWrapper.xml' exclude 'bin/windows-x86-64/StartSonar.bat' exclude 'elasticsearch-patch' exclude 'bin/linux-x86-64/sonar.sh' @@ -240,13 +240,19 @@ task zip(type: Zip, dependsOn: [configurations.compileClasspath, tasks.downloadL } into("${archiveDir}/bin/windows-x86-64/") { - from file('src/main/assembly/bin/windows-x86-64/SonarService.xml') from file('src/main/assembly/bin/windows-x86-64/StartSonar.bat') filter(ReplaceTokens, tokens: [ 'sqversion': version ]) } + into("${archiveDir}/bin/windows-x86-64/lib/") { + from file('src/main/assembly/bin/windows-x86-64/lib/SonarServiceWrapper.xml') + filter(ReplaceTokens, tokens: [ + 'sqversion': version + ]) + } + into("${archiveDir}/elasticsearch/") { from file('src/main/assembly/elasticsearch-patch') include 'bin/elasticsearch' diff --git a/sonar-application/src/main/assembly/bin/windows-x86-64/SonarService.bat b/sonar-application/src/main/assembly/bin/windows-x86-64/SonarService.bat new file mode 100644 index 00000000000..1df5e2cf027 --- /dev/null +++ b/sonar-application/src/main/assembly/bin/windows-x86-64/SonarService.bat @@ -0,0 +1,32 @@ +@rem SonarQube +@rem Copyright (C) 2009-2022 SonarSource SA +@rem mailto:info AT sonarsource DOT com +@rem +@rem This program is free software; you can redistribute it and/or +@rem modify it under the terms of the GNU Lesser General Public +@rem License as published by the Free Software Foundation; either +@rem version 3 of the License, or (at your option) any later version. +@rem +@rem This program is distributed in the hope that it will be useful, +@rem but WITHOUT ANY WARRANTY; without even the implied warranty of +@rem MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +@rem Lesser General Public License for more details. +@rem +@rem You should have received a copy of the GNU Lesser General Public License +@rem along with this program; if not, write to the Free Software Foundation, +@rem Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +@echo off +setlocal + +rem DO NOT EDIT THE FOLLOWING SECTIONS + +set REALPATH=%~dp0 +rem check if Java is found +set JAVA_EXE= +call "%REALPATH%lib\find_java.bat" set_java_exe FAIL || goto:eof + +rem call the SonarServiceWrapper.exe passing all the parameters +"%REALPATH%lib\SonarServiceWrapper.exe" %* + +endlocal diff --git a/sonar-application/src/main/assembly/bin/windows-x86-64/SonarService.xml b/sonar-application/src/main/assembly/bin/windows-x86-64/SonarService.xml deleted file mode 100644 index 0aaa9bc0609..00000000000 --- a/sonar-application/src/main/assembly/bin/windows-x86-64/SonarService.xml +++ /dev/null @@ -1,25 +0,0 @@ -<service> - <!-- Path to the Java executable --> - <executable>java</executable> - - <!-- DO NOT EDIT THE FOLLOWING SECTIONS --> - <arguments> - -Xms8m -Xmx32m - -Djava.awt.headless=true - --add-exports=java.base/jdk.internal.ref=ALL-UNNAMED - --add-opens=java.base/java.lang=ALL-UNNAMED - --add-opens=java.base/java.nio=ALL-UNNAMED - --add-opens=java.base/sun.nio.ch=ALL-UNNAMED - --add-opens=java.management/sun.management=ALL-UNNAMED - --add-opens=jdk.management/com.sun.management.internal=ALL-UNNAMED - -cp "..\..\lib\sonar-application-@sqversion@.jar" "org.sonar.application.App" - </arguments> - - <id>SonarQube</id> - <name>SonarQube</name> - <description>SonarQube</description> - - <logpath>../../logs</logpath> - <log mode="none"/> - -</service>
\ No newline at end of file diff --git a/sonar-application/src/main/assembly/bin/windows-x86-64/StartSonar.bat b/sonar-application/src/main/assembly/bin/windows-x86-64/StartSonar.bat index 500b5cbe8f3..e154489c0bc 100755 --- a/sonar-application/src/main/assembly/bin/windows-x86-64/StartSonar.bat +++ b/sonar-application/src/main/assembly/bin/windows-x86-64/StartSonar.bat @@ -19,12 +19,13 @@ @echo off
setlocal
-rem Path to the Java executable
-set JAVA_EXE="java"
-
-
rem DO NOT EDIT THE FOLLOWING SECTIONS
+
set REALPATH=%~dp0
+
+set JAVA_EXE=
+call "%REALPATH%lib\find_java.bat" set_java_exe FAIL || goto:eof
+
call :check_if_sonar_is_running FAIL || goto:eof
echo Starting SonarQube...
@@ -41,28 +42,28 @@ echo Starting SonarQube... goto:eof
:check_if_sonar_is_running
-set "SQ_SERVICE="
-for /f %%i in ('%REALPATH%/SonarService.exe status') do set "SQ_SERVICE=%%i"
-if [%SQ_SERVICE%]==[Started] (
- echo ERROR: SonarQube is already running as a service.
- exit /b 1
-)
+ set "SQ_SERVICE="
+ for /f %%i in ('%REALPATH%SonarService.bat status ^>nul 2^>nul') do set "SQ_SERVICE=%%i"
+ if [%SQ_SERVICE%]==[Started] (
+ echo ERROR: SonarQube is already running as a service.
+ exit /b 1
+ )
-set "SQ_PROCESS="
-where jps >nul 2>nul
-if %errorlevel% equ 0 (
- rem give priority to jps command if present
- for /f "tokens=1" %%i in ('jps -l ^| findstr "org.sonar.application.App"') do set "SQ_PROCESS=%%i"
-) else (
- rem fallback to wmic command
- for /f "tokens=2" %%i in ('wmic process where "name='java.exe' and commandline like '%%org.sonar.application.App%%'" get name^, processid 2^>nul ^| findstr "java"') do set "SQ_PROCESS=%%i"
-)
+ set "SQ_PROCESS="
+ where jps >nul 2>nul
+ if %errorlevel% equ 0 (
+ rem give priority to jps command if present
+ for /f "tokens=1" %%i in ('jps -l ^| findstr "org.sonar.application.App"') do set "SQ_PROCESS=%%i"
+ ) else (
+ rem fallback to wmic command
+ for /f "tokens=2" %%i in ('wmic process where "name='java.exe' and commandline like '%%org.sonar.application.App%%'" get name^, processid 2^>nul ^| findstr "java"') do set "SQ_PROCESS=%%i"
+ )
-if not [%SQ_PROCESS%]==[] (
- echo ERROR: Another instance of the SonarQube application is already running with PID %SQ_PROCESS%
- exit /b 1
-)
-goto:eof
+ if not [%SQ_PROCESS%]==[] (
+ echo ERROR: Another instance of the SonarQube application is already running with PID %SQ_PROCESS%
+ exit /b 1
+ )
+ goto:eof
endlocal
diff --git a/sonar-application/src/main/assembly/bin/windows-x86-64/SonarService.exe b/sonar-application/src/main/assembly/bin/windows-x86-64/lib/SonarServiceWrapper.exe Binary files differindex 21926362c2d..21926362c2d 100644 --- a/sonar-application/src/main/assembly/bin/windows-x86-64/SonarService.exe +++ b/sonar-application/src/main/assembly/bin/windows-x86-64/lib/SonarServiceWrapper.exe diff --git a/sonar-application/src/main/assembly/bin/windows-x86-64/lib/SonarServiceWrapper.xml b/sonar-application/src/main/assembly/bin/windows-x86-64/lib/SonarServiceWrapper.xml new file mode 100644 index 00000000000..ec836f3c874 --- /dev/null +++ b/sonar-application/src/main/assembly/bin/windows-x86-64/lib/SonarServiceWrapper.xml @@ -0,0 +1,45 @@ +<!-- + ~ SonarQube + ~ Copyright (C) 2009-2022 SonarSource SA + ~ mailto:info AT sonarsource DOT com + ~ + ~ This program is free software; you can redistribute it and/or + ~ modify it under the terms of the GNU Lesser General Public + ~ License as published by the Free Software Foundation; either + ~ version 3 of the License, or (at your option) any later version. + ~ + ~ This program is distributed in the hope that it will be useful, + ~ but WITHOUT ANY WARRANTY; without even the implied warranty of + ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + ~ Lesser General Public License for more details. + ~ + ~ You should have received a copy of the GNU Lesser General Public License + ~ along with this program; if not, write to the Free Software Foundation, + ~ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + --> + +<service> + <!-- Path to the Java executable --> + <executable>%JAVA_EXE%</executable> + + <!-- DO NOT EDIT THE FOLLOWING SECTIONS --> + <arguments> + -Xms8m -Xmx32m + -Djava.awt.headless=true + --add-exports=java.base/jdk.internal.ref=ALL-UNNAMED + --add-opens=java.base/java.lang=ALL-UNNAMED + --add-opens=java.base/java.nio=ALL-UNNAMED + --add-opens=java.base/sun.nio.ch=ALL-UNNAMED + --add-opens=java.management/sun.management=ALL-UNNAMED + --add-opens=jdk.management/com.sun.management.internal=ALL-UNNAMED + -cp "..\..\..\lib\sonar-application-@sqversion@.jar" "org.sonar.application.App" + </arguments> + + <id>SonarQube</id> + <name>SonarQube</name> + <description>SonarQube</description> + + <logpath>../../../logs</logpath> + <log mode="none"/> + +</service>
\ No newline at end of file diff --git a/sonar-application/src/main/assembly/bin/windows-x86-64/lib/find_java.bat b/sonar-application/src/main/assembly/bin/windows-x86-64/lib/find_java.bat new file mode 100644 index 00000000000..12ac5fcb7c6 --- /dev/null +++ b/sonar-application/src/main/assembly/bin/windows-x86-64/lib/find_java.bat @@ -0,0 +1,32 @@ +@echo off +call:%~1 +goto exit + +rem Sets the JAVA_EXE var to be used by the calling script. +rem By default, the java.exe in the PATH is selected. This can be overwritten by the environmental variable SONAR_JAVA_PATH. +rem Returns an error code if Java executable is not found in the PATH and the environmental variable SONAR_JAVA_PATH is not properly set. +:set_java_exe + rem use java.exe from PATH, by default + where "java.exe" >nul 2>nul + if %errorlevel% equ 0 ( + set JAVA_EXE="java.exe" + ) + + rem if the environmental variable SONAR_JAVA_PATH is set, override the default java.exe + if not "%SONAR_JAVA_PATH%"=="" ( + if exist "%SONAR_JAVA_PATH%" ( + set JAVA_EXE="%SONAR_JAVA_PATH%" + ) else ( + echo ERROR: "%SONAR_JAVA_PATH%" not found. Please make sure that the environmental variable SONAR_JAVA_PATH points to the Java executable. + exit /b 1 + ) + ) + + if [%JAVA_EXE%]==[] ( + echo ERROR: java.exe not found. Please make sure that the environmental variable SONAR_JAVA_PATH points to the Java executable. + exit /b 1 + ) + goto:eof + +:exit +exit /b
\ No newline at end of file |