From e12852cc16f5d328c25e6569759d0eb1ee467835 Mon Sep 17 00:00:00 2001 From: Dimitris Kavvathas Date: Tue, 9 Aug 2022 17:34:22 +0200 Subject: SONAR-17137 add SONAR_JAVA_PATH environmental variable for user-defined Java executable path --- .../assembly/bin/windows-x86-64/SonarService.bat | 32 ++++++++++++++ .../assembly/bin/windows-x86-64/SonarService.exe | Bin 655872 -> 0 bytes .../assembly/bin/windows-x86-64/SonarService.xml | 25 ----------- .../assembly/bin/windows-x86-64/StartSonar.bat | 49 +++++++++++---------- .../bin/windows-x86-64/lib/SonarServiceWrapper.exe | Bin 0 -> 655872 bytes .../bin/windows-x86-64/lib/SonarServiceWrapper.xml | 45 +++++++++++++++++++ .../assembly/bin/windows-x86-64/lib/find_java.bat | 32 ++++++++++++++ 7 files changed, 134 insertions(+), 49 deletions(-) create mode 100644 sonar-application/src/main/assembly/bin/windows-x86-64/SonarService.bat delete mode 100644 sonar-application/src/main/assembly/bin/windows-x86-64/SonarService.exe delete mode 100644 sonar-application/src/main/assembly/bin/windows-x86-64/SonarService.xml create mode 100644 sonar-application/src/main/assembly/bin/windows-x86-64/lib/SonarServiceWrapper.exe create mode 100644 sonar-application/src/main/assembly/bin/windows-x86-64/lib/SonarServiceWrapper.xml create mode 100644 sonar-application/src/main/assembly/bin/windows-x86-64/lib/find_java.bat (limited to 'sonar-application/src') 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.exe b/sonar-application/src/main/assembly/bin/windows-x86-64/SonarService.exe deleted file mode 100644 index 21926362c2d..00000000000 Binary files a/sonar-application/src/main/assembly/bin/windows-x86-64/SonarService.exe and /dev/null differ 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 @@ - - - java - - - - -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" - - - SonarQube - SonarQube - SonarQube - - ../../logs - - - \ 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/lib/SonarServiceWrapper.exe b/sonar-application/src/main/assembly/bin/windows-x86-64/lib/SonarServiceWrapper.exe new file mode 100644 index 00000000000..21926362c2d Binary files /dev/null and b/sonar-application/src/main/assembly/bin/windows-x86-64/lib/SonarServiceWrapper.exe differ 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 @@ + + + + + %JAVA_EXE% + + + + -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" + + + SonarQube + SonarQube + SonarQube + + ../../../logs + + + \ 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 -- cgit v1.2.3