Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 31 additions & 10 deletions apache-maven/src/assembly/maven/bin/mvn.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ if not exist "%MAVEN_HOME%\bin\mvn.cmd" goto error
@REM When only version info is requested, render the banner from a single
@REM lightweight JVM (-XshowSettings) without starting Maven itself.
set "FAST_VERSION=0"
set "VERSION_SETTINGS_DIR="
set "VERSION_SETTINGS_TEMP="
if defined IS_VERSION_AND_EXIT goto tryFastVersion
if defined IS_SHOW_VERSION goto tryFastVersion
Expand All @@ -165,10 +166,12 @@ goto javaGate
:tryFastVersion
if defined IS_VERBOSE goto javaGate
if defined IS_MAIN_OVERRIDE goto javaGate
set "VERSION_SETTINGS_TEMP=%TEMP%\mvn-version-%RANDOM%-%RANDOM%.txt"
call :mkTempDir version VERSION_SETTINGS_DIR
if ERRORLEVEL 1 goto javaGate
set "VERSION_SETTINGS_TEMP=%VERSION_SETTINGS_DIR%\settings.txt"
"%JAVACMD%" --enable-native-access=ALL-UNNAMED -XshowSettings:properties -version 2> "%VERSION_SETTINGS_TEMP%"
if ERRORLEVEL 1 (
del "%VERSION_SETTINGS_TEMP%" 2>nul
rd /s /q "%VERSION_SETTINGS_DIR%" 2>nul
set "VERSION_SETTINGS_TEMP="
Comment on lines +174 to 175

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Nit — stale variable on java failure path

After rd /s /q removes the directory, VERSION_SETTINGS_DIR stays defined (it still holds the now-deleted path). Only VERSION_SETTINGS_TEMP is cleared. For symmetry with the initial set "VERSION_SETTINGS_DIR=" at the top of the script, clear it here too.

Suggested change
rd /s /q "%VERSION_SETTINGS_DIR%" 2>nul
set "VERSION_SETTINGS_TEMP="
rd /s /q "%VERSION_SETTINGS_DIR%" 2>nul
set "VERSION_SETTINGS_DIR="
set "VERSION_SETTINGS_TEMP="

goto javaGate
)
Expand All @@ -188,7 +191,7 @@ goto fastVersionDone

:versionPrint
call :printFastVersion "%VERSION_SETTINGS_TEMP%"
if defined VERSION_SETTINGS_TEMP del "%VERSION_SETTINGS_TEMP%" 2>nul
if defined VERSION_SETTINGS_DIR rd /s /q "%VERSION_SETTINGS_DIR%" 2>nul
if defined IS_VERSION_AND_EXIT goto end
set "MAVEN_VERSION_PRINTED=-Dmaven.version.printed=true"
:fastVersionDone
Expand Down Expand Up @@ -279,8 +282,10 @@ cd /d "%EXEC_DIR%"

:endDetectBaseDir

rem Initialize JVM_CONFIG_ARGFILE_ARG to empty
rem Initialize to empty so values inherited from the environment are never used or deleted
set "JVM_CONFIG_ARGFILE_ARG="
set "JVM_CONFIG_DIR="
set "JVM_CONFIG_TEMP="

if not exist "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadJvmConfig

Expand All @@ -293,7 +298,12 @@ rem Why write to a temp file instead of capturing stdout via 'for /f ... in (`cm
rem cmd.exe's child shell interprets special characters (pipes |, ampersands &, etc.)
rem in the captured output — breaking values like -Dhttp.nonProxyHosts=de|*.de.

set "JVM_CONFIG_TEMP=%TEMP%\mvn-jvm-config-%RANDOM%-%RANDOM%.txt"
call :mkTempDir jvm-config JVM_CONFIG_DIR
if ERRORLEVEL 1 (
echo ERROR: Could not create a temporary directory in %TEMP% for .mvn/jvm.config 1>&2
exit /b 1
)
set "JVM_CONFIG_TEMP=%JVM_CONFIG_DIR%\jvm.config.args"

rem Debug logging (set MAVEN_DEBUG_SCRIPT=1 to enable)
if defined MAVEN_DEBUG_SCRIPT (
Expand All @@ -316,9 +326,7 @@ if %JVM_CONFIG_EXIT% neq 0 (
echo ERROR: Failed to parse .mvn/jvm.config file 1>&2
echo jvm.config path: %MAVEN_PROJECTBASEDIR%\.mvn\jvm.config 1>&2
echo Java command: %JAVACMD% 1>&2
if exist "%JVM_CONFIG_TEMP%" (
del "%JVM_CONFIG_TEMP%" 2>nul
)
rd /s /q "%JVM_CONFIG_DIR%" 2>nul
exit /b 1
)

Expand Down Expand Up @@ -412,8 +420,8 @@ if defined MAVEN_DEBUG_SCRIPT (
%MAVEN_ARGS% ^
%*
set JVM_CONFIG_EXIT_CODE=%ERRORLEVEL%
rem Cleanup the jvm.config temp file now that the JVM has exited (must be before @endlocal)
if defined JVM_CONFIG_TEMP del "%JVM_CONFIG_TEMP%" 2>nul
rem Cleanup the jvm.config temp directory now that the JVM has exited (must be before @endlocal)
if defined JVM_CONFIG_DIR rd /s /q "%JVM_CONFIG_DIR%" 2>nul
if %JVM_CONFIG_EXIT_CODE% neq 0 goto error
goto end

Expand Down Expand Up @@ -527,3 +535,16 @@ echo Java version: %_JAVA_VERSION%, vendor: %_JAVA_VENDOR%, runtime: %_JAVA_HOME
echo Default locale: %_LOCALE%, platform encoding: %_ENCODING%, time zone: %_TIMEZONE%
echo OS name: "%_OS_NAME%", version: "%_OS_VERSION%", arch: "%_OS_ARCH%", family: "%_OS_FAMILY%"
exit /b 0

:mkTempDir
@REM Creates a new, empty directory under %TEMP% and stores its path in the variable named by %2.
@REM %RANDOM% is seeded from the clock once per cmd.exe, so mvn.cmd processes started in the same
@REM second draw the same numbers. mkdir fails when the name is taken and the retry moves on to the
@REM next number, so concurrent builds never share a temp file.
set "_MKTEMP_TRIES=0"
:mkTempDirRetry
set /a _MKTEMP_TRIES+=1
set "_MKTEMP_DIR=%TEMP%\mvn-%~1-%RANDOM%-%RANDOM%"
mkdir "%_MKTEMP_DIR%" 2>nul && (set "%~2=%_MKTEMP_DIR%" & exit /b 0)
if %_MKTEMP_TRIES% lss 100 goto mkTempDirRetry
exit /b 1
Loading