diff --git a/integration-test/src/test/scala/RunnerTest.scala b/integration-test/src/test/scala/RunnerTest.scala index d810f9475..d3dc0c580 100755 --- a/integration-test/src/test/scala/RunnerTest.scala +++ b/integration-test/src/test/scala/RunnerTest.scala @@ -95,12 +95,41 @@ object SbtRunnerTest extends SimpleTestSuite with PowerAssertions { } test("sbt with -Xms2048M -Xmx2048M -Xss6M in SBT_OPTS") { - if (isWindows) cancel("Test not supported on windows") val out = sbtProcessWithOpts("compile -v", "", "-Xms2048M -Xmx2048M -Xss6M").!!.linesIterator.toList assert(out.contains[String]("-Xss6M")) () } + test("sbt with -Dhttp.proxyHost=proxy -Dhttp.proxyPort=8080 in SBT_OPTS") { + val out = sbtProcessWithOpts("compile -v", "", "-Dhttp.proxyHost=proxy -Dhttp.proxyPort=8080").!!.linesIterator.toList + assert(out.contains[String]("-Dhttp.proxyHost=proxy")) + assert(out.contains[String]("-Dhttp.proxyPort=8080")) + () + } + + test("sbt with -XX:ParallelGCThreads=16 -XX:PermSize=128M in SBT_OPTS") { + val out = sbtProcessWithOpts("compile -v", "", "-XX:ParallelGCThreads=16 -XX:PermSize=128M").!!.linesIterator.toList + assert(out.contains[String]("-XX:ParallelGCThreads=16")) + assert(out.contains[String]("-XX:PermSize=128M")) + () + } + + test("sbt with -XX:+UseG1GC -XX:+PrintGC in SBT_OPTS") { + val out = sbtProcessWithOpts("compile -v", "", "-XX:+UseG1GC -XX:+PrintGC").!!.linesIterator.toList + assert(out.contains[String]("-XX:+UseG1GC")) + assert(out.contains[String]("-XX:+PrintGC")) + assert(!out.contains[String]("-XX:+UseG1GC=-XX:+PrintGC")) + () + } + + test("sbt with -XX:-UseG1GC -XX:-PrintGC in SBT_OPTS") { + val out = sbtProcessWithOpts("compile -v", "", "-XX:-UseG1GC -XX:-PrintGC").!!.linesIterator.toList + assert(out.contains[String]("-XX:-UseG1GC")) + assert(out.contains[String]("-XX:-PrintGC")) + assert(!out.contains[String]("-XX:-UseG1GC=-XX:-PrintGC")) + () + } + test("sbt with --no-colors in SBT_OPTS") { if (isWindows) cancel("Test not supported on windows") val out = sbtProcessWithOpts("compile -v", "", "--no-colors").!!.linesIterator.toList diff --git a/src/universal/bin/sbt.bat b/src/universal/bin/sbt.bat index 577a2adac..417b79ad3 100755 --- a/src/universal/bin/sbt.bat +++ b/src/universal/bin/sbt.bat @@ -49,7 +49,11 @@ rem users can set SBT_OPTS via .sbtopts if exist .sbtopts for /F %%A in (.sbtopts) do ( set _sbtopts_line=%%A if not "!_sbtopts_line:~0,1!" == "#" ( - set _SBT_OPTS=%%A %SBT_OPTS% + if defined _SBT_OPTS ( + set _SBT_OPTS=!_SBT_OPTS! %%A + ) else ( + set _SBT_OPTS=%%A + ) ) ) @@ -404,21 +408,45 @@ if "%~0" == "new" ( if "%g:~0,2%" == "-D" ( rem special handling for -D since '=' gets parsed away - echo "%g%" | find "=" > null - if ERRORLEVEL 1 ( - if not "%~1" == "" ( - call :dlog [args_loop] -D argument %~0=%~1 - set "SBT_ARGS=!SBT_ARGS! %~0=%~1" - shift - goto args_loop + for /F "tokens=1 delims==" %%a in ("%g%") do ( + rem make sure it doesn't have the '=' already + if "%g%" == "%%a" ( + if not "%~1" == "" ( + call :dlog [args_loop] -D argument %~0=%~1 + set "SBT_ARGS=!SBT_ARGS! %~0=%~1" + shift + goto args_loop + ) else ( + echo %g% is missing a value + goto error + ) ) else ( - echo %g% is missing a value - goto error + call :dlog [args_loop] -D argument %~0 + set "SBT_ARGS=!SBT_ARGS! %~0" + goto args_loop + ) + ) +) + +if not "%g:~0,5%" == "-XX:+" if not "%g:~0,5%" == "-XX:-" if "%g:~0,3%" == "-XX" ( + rem special handling for -XX since '=' gets parsed away + for /F "tokens=1 delims==" %%a in ("%g%") do ( + rem make sure it doesn't have the '=' already + if "%g%" == "%%a" ( + if not "%~1" == "" ( + call :dlog [args_loop] -XX argument %~0=%~1 + set "SBT_ARGS=!SBT_ARGS! %~0=%~1" + shift + goto args_loop + ) else ( + echo %g% is missing a value + goto error + ) + ) else ( + call :dlog [args_loop] -XX argument %~0 + set "SBT_ARGS=!SBT_ARGS! %~0" + goto args_loop ) - ) else ( - call :dlog [args_loop] -D argument %~0 - set "SBT_ARGS=!SBT_ARGS! %~0" - goto args_loop ) ) @@ -584,16 +612,28 @@ shift if [%0] EQU [] goto echolist_end set "p=%0" -rem special handling for -D since '=' gets parsed away if "%p:~0,2%" == "-D" ( - rem if "-Dscala.ext.dirs" (replace all = with nothing) == "-Dscala.ext.dirs" - rem (e.g. verify it doesn't have the = already) + rem special handling for -D since '=' gets parsed away + for /F "tokens=1 delims==" %%a in ("%p%") do ( + rem make sure it doesn't have the '=' already + if "%p%" == "%%a" if not "%~1" == "" ( + echo %0=%1 + shift + goto echolist + ) + ) +) - if "x%p:^==%" == "x%p%" if not "%~1" == "" ( - echo %0=%1 - shift - goto echolist - ) +if not "%p:~0,5%" == "-XX:+" if not "%p:~0,5%" == "-XX:-" if "%p:~0,3%" == "-XX" ( + rem special handling for -XX since '=' gets parsed away + for /F "tokens=1 delims==" %%a in ("%p%") do ( + rem make sure it doesn't have the '=' already + if "%p%" == "%%a" if not "%~1" == "" ( + echo %0=%1 + shift + goto echolist + ) + ) ) echo %0 @@ -613,24 +653,33 @@ exit /B 0 rem evict memory related options set _new_java_opts= - - for /F %%g in ("!_JAVA_OPTS!") do ( + set _old_java_opts=!_JAVA_OPTS! +:next_java_opt + if "!_old_java_opts!" == "" goto :done_java_opt + for /F "tokens=1,*" %%g in ("!_old_java_opts!") do ( set "p=%%g" if not "!p:~0,4!" == "-Xmx" if not "!p:~0,4!" == "-Xms" if not "!p:~0,15!" == "-XX:MaxPermSize" if not "!p:~0,20!" == "-XX:MaxMetaspaceSize" if not "!p:~0,25!" == "-XX:ReservedCodeCacheSize" ( set _new_java_opts=!_new_java_opts! %%g ) + set "_old_java_opts=%%h" ) + goto :next_java_opt +:done_java_opt set _JAVA_OPTS=!_new_java_opts! set _new_sbt_opts= - - for /F %%g in ("!_SBT_OPTS!") do ( + set _old_sbt_opts=!_SBT_OPTS! +:next_sbt_opt + if "!_old_sbt_opts!" == "" goto :done_sbt_opt + for /F "tokens=1,*" %%g in ("!_old_sbt_opts!") do ( set "p=%%g" if not "!p:~0,4!" == "-Xmx" if not "!p:~0,4!" == "-Xms" if not "!p:~0,15!" == "-XX:MaxPermSize" if not "!p:~0,20!" == "-XX:MaxMetaspaceSize" if not "!p:~0,25!" == "-XX:ReservedCodeCacheSize" ( set _new_sbt_opts=!_new_sbt_opts! %%g ) + set "_old_sbt_opts=%%h" ) - + goto :next_sbt_opt +:done_sbt_opt set _SBT_OPTS=!_new_sbt_opts! rem a ham-fisted attempt to move some memory settings in concert