Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows bat script improvements #1563

Merged
merged 3 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ if defined BUNDLED_JVM (

if "%_JAVACMD%"=="" set _JAVACMD=java

rem if configuration files exist, prepend their contents to the script arguments so it can be processed by this runner
call :parse_config "%SCRIPT_CONF_FILE%" SCRIPT_CONF_ARGS

call :process_args %SCRIPT_CONF_ARGS% %%*

rem Detect if this java is ok to use.
for /F %%j in ('"%_JAVACMD%" -version 2^>^&1') do (
if %%~j==java set JAVAINSTALLED=1
Expand Down Expand Up @@ -86,11 +91,6 @@ if "%JAVAOK%"=="false" (
exit /B 1
)

rem if configuration files exist, prepend their contents to the script arguments so it can be processed by this runner
call :parse_config "%SCRIPT_CONF_FILE%" SCRIPT_CONF_ARGS

call :process_args %SCRIPT_CONF_ARGS% %%*

set _JAVA_OPTS=!_JAVA_OPTS! !_JAVA_PARAMS!

if defined CUSTOM_MAIN_CLASS (
Expand Down Expand Up @@ -135,23 +135,36 @@ exit /B 0
rem Processes incoming arguments and places them in appropriate global variables
:process_args
:param_loop
call set _PARAM1=%%1
set "_TEST_PARAM=%~1"
shift
call set _PARAM1=%%0
set "_TEST_PARAM=%~0"

if ["!_PARAM1!"]==[""] goto param_afterloop

if "!_TEST_PARAM!"=="-main" (
call set CUSTOM_MAIN_CLASS=%%1
shift
goto param_loop
)

rem ignore arguments that do not start with '-'
if "%_TEST_PARAM:~0,1%"=="-" goto param_java_check
set _APP_ARGS=!_APP_ARGS! !_PARAM1!
shift
goto param_loop
if "!_TEST_PARAM!"=="-java-home" (
set "JAVA_HOME=%~1"
set "_JAVACMD=%~1\bin\java.exe"
shift
goto param_loop
)

:param_java_check
if "!_TEST_PARAM:~0,2!"=="-J" (
rem strip -J prefix
set _JAVA_PARAMS=!_JAVA_PARAMS! !_TEST_PARAM:~2!
shift
call set _TEST_PARAM=!_TEST_PARAM:~2!
if not "!_TEST_PARAM:~0,5!" == "-XX:+" if not "!_TEST_PARAM:~0,5!" == "-XX:-" if "!_TEST_PARAM:~0,3!" == "-XX" (
rem special handling for -J-XX since '=' gets parsed away
for /F "delims== tokens=1,*" %%G in ("!_TEST_PARAM!") DO (
call set _TEST_PARAM=!_TEST_PARAM!=%%1
shift
)
)
set _JAVA_PARAMS=!_JAVA_PARAMS! !_TEST_PARAM!
goto param_loop
)

Expand All @@ -160,22 +173,18 @@ rem Processes incoming arguments and places them in appropriate global variables
for /F "delims== tokens=1,*" %%G in ("!_TEST_PARAM!") DO (
if not ["%%H"] == [""] (
set _JAVA_PARAMS=!_JAVA_PARAMS! !_PARAM1!
) else if [%2] neq [] (
) else if [%1] neq [] (
rem it was a normal property: -Dprop=42 or -Drop="42"
call set _PARAM1=%%1=%%2
call set _PARAM1=%%0=%%1
set _JAVA_PARAMS=!_JAVA_PARAMS! !_PARAM1!
shift
)
)
) else (
if "!_TEST_PARAM!"=="-main" (
call set CUSTOM_MAIN_CLASS=%%2
shift
) else (
set _APP_ARGS=!_APP_ARGS! !_PARAM1!
)
goto param_loop
)
shift

set _APP_ARGS=!_APP_ARGS! !_PARAM1!

goto param_loop
:param_afterloop

Expand Down
6 changes: 6 additions & 0 deletions src/sbt-test/windows/test-bat-template/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ TaskKey[Unit]("checkScript") := {
"arg #0 is [first]\narg #1 is [-XX]\narg #2 is [last]\nproperty(test.hoge) is [huga]\nvmarg #0 is [-Dtest.hoge=huga]\nvmarg #1 is [-Xms6m]\nSUCCESS!",
Map("show-vmargs" -> "true")
)
checkOutput(
"with -J-XX java-opts",
Seq("-J-XX:+UseG1GC", "-J-XX:-UnlockExperimentalVMOptions", "-J-XX:MaxGCPauseMillis=500"),
"vmarg #0 is [-XX:+UseG1GC]\nvmarg #1 is [-XX:-UnlockExperimentalVMOptions]\nvmarg #2 is [-XX:MaxGCPauseMillis=500]\nSUCCESS!",
Map("show-vmargs" -> "true")
)
checkOutput(
"include space",
Seq("""-Dtest.hoge=C:\Program Files\Java""", """"C:\Program Files\Java""""),
Expand Down
Loading