diff --git a/.travis.yml b/.travis.yml index 7d8675b1a..5d9e56ad5 100755 --- a/.travis.yml +++ b/.travis.yml @@ -23,7 +23,7 @@ matrix: install: - $JABBA_HOME/bin/jabba.exe install $TRAVIS_JDK && export JAVA_HOME="$JABBA_HOME/jdk/$TRAVIS_JDK" && export PATH="$JAVA_HOME/bin:$PATH" - java -Xmx32m -version - - curl https://piccolo.link/sbt-$SBT_VER.zip -L --output /tmp/sbt.zip + - curl --fail https://github.com/sbt/sbt/releases/download/v$SBT_VER/sbt-$SBT_VER.zip -L --output /tmp/sbt.zip - unzip /tmp/sbt.zip -d $HOME/sbt - export PATH="$HOME/sbt/sbt/bin:$PATH" - bin/coursier.bat resolve @@ -43,7 +43,7 @@ matrix: - $JABBA_HOME/bin/jabba install $TRAVIS_JDK && export JAVA_HOME="$JABBA_HOME/jdk/$TRAVIS_JDK/Contents/Home" && export PATH="$JAVA_HOME/bin:$PATH" - java -Xmx32m -version - unset SBT_OPTS - - curl https://piccolo.link/sbt-$SBT_VER.zip -L --output /tmp/sbt.zip + - curl --fail https://github.com/sbt/sbt/releases/download/v$SBT_VER/sbt-$SBT_VER.zip -L --output /tmp/sbt.zip - unzip /tmp/sbt.zip -d $HOME/sbt - export PATH="$HOME/sbt/sbt/bin:$PATH" - bin/coursier resolve @@ -72,7 +72,7 @@ install: - $JABBA_HOME/bin/jabba install $TRAVIS_JDK && export JAVA_HOME="$JABBA_HOME/jdk/$TRAVIS_JDK" && export PATH="$JAVA_HOME/bin:$PATH" - java -Xmx32m -version - unset SBT_OPTS - - curl https://piccolo.link/sbt-$SBT_VER.zip -L --output /tmp/sbt.zip + - curl --fail https://github.com/sbt/sbt/releases/download/v$SBT_VER/sbt-$SBT_VER.zip -L --output /tmp/sbt.zip - unzip /tmp/sbt.zip -d $HOME/sbt - export PATH="$HOME/sbt/sbt/bin:$PATH" - bin/coursier resolve diff --git a/integration-test/bin/java b/integration-test/bin/java new file mode 100755 index 000000000..56920a236 --- /dev/null +++ b/integration-test/bin/java @@ -0,0 +1,9 @@ +#!/usr/bin/env python + +import sys + +if '--version' in sys.argv or '-version' in sys.argv: + print 'openjdk version "1.8.0_212"' +else: + for arg in sys.argv[1:]: + print(repr(arg)[1:-1]) diff --git a/integration-test/bin/java.cmd b/integration-test/bin/java.cmd new file mode 100644 index 000000000..4b214dbf6 --- /dev/null +++ b/integration-test/bin/java.cmd @@ -0,0 +1 @@ +@python "%~dp0%~n0" %* diff --git a/integration-test/src/test/scala/RunnerTest.scala b/integration-test/src/test/scala/RunnerTest.scala index b87f723b5..81386e990 100755 --- a/integration-test/src/test/scala/RunnerTest.scala +++ b/integration-test/src/test/scala/RunnerTest.scala @@ -26,134 +26,6 @@ object SbtRunnerTest extends SimpleTestSuite with PowerAssertions { () } - test("sbt -no-colors") { - val out = sbtProcess("compile", "-no-colors", "-v").!!.linesIterator.toList - assert(out.contains[String]("-Dsbt.log.noformat=true")) - () - } - - test("sbt --no-colors") { - val out = sbtProcess("compile", "--no-colors", "-v").!!.linesIterator.toList - assert(out.contains[String]("-Dsbt.log.noformat=true")) - () - } - - test("sbt --color=false") { - val out = sbtProcess("compile", "--color=false", "-v").!!.linesIterator.toList - assert(out.contains[String]("-Dsbt.color=false")) - () - } - - test("sbt --debug-inc") { - val out = sbtProcess("compile", "--debug-inc", "-v").!!.linesIterator.toList - assert(out.contains[String]("-Dxsbt.inc.debug=true")) - () - } - - test("sbt --supershell=never") { - val out = sbtProcess("compile", "--supershell=never", "-v").!!.linesIterator.toList - assert(out.contains[String]("-Dsbt.supershell=never")) - () - } - - test("sbt --timings") { - val out = sbtProcess("compile", "--timings", "-v").!!.linesIterator.toList - assert(out.contains[String]("-Dsbt.task.timings=true")) - () - } - - test("sbt -D arguments") { - val out = sbtProcess("-Dsbt.supershell=false", "compile", "-v").!!.linesIterator.toList - assert(out.contains[String]("-Dsbt.supershell=false")) - () - } - - test("sbt --sbt-version") { - val out = sbtProcess("--sbt-version", "1.3.13", "compile", "-v").!!.linesIterator.toList - assert(out.contains[String]("-Dsbt.version=1.3.13")) - () - } - - test("sbt -mem 503") { - val out = sbtProcess("compile", "-mem", "503", "-v").!!.linesIterator.toList - assert(out.contains[String]("-Xmx503m")) - () - } - - test("sbt with -mem 503, -Xmx in JAVA_OPTS") { - val out = sbtProcessWithOpts("compile", "-mem", "503", "-v")("-Xmx1024m", "").!!.linesIterator.toList - assert(out.contains[String]("-Xmx503m")) - assert(!out.contains[String]("-Xmx1024m")) - () - } - - test("sbt with -mem 503, -Xmx in SBT_OPTS") { - val out = sbtProcessWithOpts("compile", "-mem", "503", "-v")("", "-Xmx1024m").!!.linesIterator.toList - assert(out.contains[String]("-Xmx503m")) - assert(!out.contains[String]("-Xmx1024m")) - () - } - - test("sbt with -Xms2048M -Xmx2048M -Xss6M in SBT_OPTS") { - 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 - assert(out.contains[String]("-Dsbt.log.noformat=true")) - () - } - - test("sbt with -debug in SBT_OPTS appears in sbt commands") { - if (isWindows) cancel("Test not supported on windows") - - val out: List[String] = sbtProcessWithOpts("compile", "-v")("", "-debug").!!.linesIterator.toList - // Debug argument must appear in the 'commands' section (after the sbt-launch.jar argument) to work - val sbtLaunchMatcher = """^.+sbt-launch.jar["]{0,1}$""".r - val locationOfSbtLaunchJarArg = out.zipWithIndex.collectFirst { - case (arg, index) if sbtLaunchMatcher.findFirstIn(arg).nonEmpty => index - } - - assert(locationOfSbtLaunchJarArg.nonEmpty) - - val argsAfterSbtLaunch = out.drop(locationOfSbtLaunchJarArg.get) - assert(argsAfterSbtLaunch.contains("-debug")) - () - } - test("sbt -V|-version|--version should print sbtVersion") { val out = sbtProcess("-version").!!.trim val expectedVersion = @@ -198,22 +70,6 @@ object SbtRunnerTest extends SimpleTestSuite with PowerAssertions { () } - test("quoted * should not glob expand to local files") { - val out = sbtProcess("testOnly * ", "--no-colors", "-v", "-debug").!!.linesIterator.toList - - // Ensure the "*" doesn't get glob expanded to individual files or directories - // (e.g. Hello.scala gets added to the testOnly arguments) https://github.com/sbt/sbt/issues/5343 - assert(!out.exists(x => x.contains("testOnly") && x.contains("Hello.scala"))) - assert(out.contains[String]("[info] HelloTest")) - () - } - - test("sbt --jvm-debug ") { - val out = sbtProcess("--jvm-debug", "12345", "compile", "-v").!!.linesIterator.toList - assert(out.contains[String]("-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=12345")) - () - } - test("sbt --client") { val out = sbtProcess("--client", "--no-colors", "compile").!!.linesIterator.toList if (isWindows) { diff --git a/integration-test/src/test/scala/ScriptTest.scala b/integration-test/src/test/scala/ScriptTest.scala new file mode 100644 index 000000000..2bbbb86b4 --- /dev/null +++ b/integration-test/src/test/scala/ScriptTest.scala @@ -0,0 +1,175 @@ +package example.test + +import minitest._ +import java.io.File + +object SbtScriptTest extends SimpleTestSuite with PowerAssertions { + lazy val isWindows: Boolean = sys.props("os.name").toLowerCase(java.util.Locale.ENGLISH).contains("windows") + lazy val sbtScript = + if (isWindows) new File("target/universal/stage/bin/sbt.bat") + else new File("target/universal/stage/bin/sbt") + + private val javaBinDir = new File("integration-test", "bin").getAbsolutePath + + def sbtProcess(args: String*) = sbtProcessWithOpts(args: _*)("", "") + def sbtProcessWithOpts(args: String*)(javaOpts: String, sbtOpts: String) = { + val path = sys.env("PATH") + sbt.internal.Process(Seq(sbtScript.getAbsolutePath) ++ args, new File("citest"), + "JAVA_OPTS" -> javaOpts, + "SBT_OPTS" -> sbtOpts, + if (isWindows) + "JAVACMD" -> new File(javaBinDir, "java.cmd").getAbsolutePath() + else + "PATH" -> (javaBinDir + File.pathSeparator + path) + ) + } + + test("sbt -no-colors") { + val out = sbtProcess("compile", "-no-colors").!!.linesIterator.toList + assert(out.contains[String]("-Dsbt.log.noformat=true")) + () + } + + test("sbt --no-colors") { + val out = sbtProcess("compile", "--no-colors").!!.linesIterator.toList + assert(out.contains[String]("-Dsbt.log.noformat=true")) + () + } + + test("sbt --color=false") { + val out = sbtProcess("compile", "--color=false", "-v").!!.linesIterator.toList + assert(out.contains[String]("-Dsbt.color=false")) + () + } + + test("sbt --debug-inc") { + val out = sbtProcess("compile", "--debug-inc", "-v").!!.linesIterator.toList + assert(out.contains[String]("-Dxsbt.inc.debug=true")) + () + } + + test("sbt --supershell=never") { + val out = sbtProcess("compile", "--supershell=never", "-v").!!.linesIterator.toList + assert(out.contains[String]("-Dsbt.supershell=never")) + () + } + + test("sbt --timings") { + val out = sbtProcess("compile", "--timings", "-v").!!.linesIterator.toList + assert(out.contains[String]("-Dsbt.task.timings=true")) + () + } + + test("sbt -D arguments") { + val out = sbtProcess("-Dsbt.supershell=false", "compile", "-v").!!.linesIterator.toList + assert(out.contains[String]("-Dsbt.supershell=false")) + () + } + + test("sbt --sbt-version") { + val out = sbtProcess("--sbt-version", "1.3.13", "compile", "-v").!!.linesIterator.toList + assert(out.contains[String]("-Dsbt.version=1.3.13")) + () + } + + test("sbt -mem 503") { + val out = sbtProcess("compile", "-mem", "503", "-v").!!.linesIterator.toList + assert(out.contains[String]("-Xmx503m")) + () + } + + test("sbt with -mem 503, -Xmx in JAVA_OPTS") { + val out = sbtProcessWithOpts("compile", "-mem", "503", "-v")("-Xmx1024m", "").!!.linesIterator.toList + assert(out.contains[String]("-Xmx503m")) + assert(!out.contains[String]("-Xmx1024m")) + () + } + + test("sbt with -mem 503, -Xmx in SBT_OPTS") { + val out = sbtProcessWithOpts("compile", "-mem", "503", "-v")("", "-Xmx1024m").!!.linesIterator.toList + assert(out.contains[String]("-Xmx503m")) + assert(!out.contains[String]("-Xmx1024m")) + () + } + + test("sbt with -Xms2048M -Xmx2048M -Xss6M in SBT_OPTS") { + 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 + assert(out.contains[String]("-Dsbt.log.noformat=true")) + () + } + + test("sbt with -debug in SBT_OPTS appears in sbt commands") { + if (isWindows) cancel("Test not supported on windows") + + val out: List[String] = sbtProcessWithOpts("compile", "-v")("", "-debug").!!.linesIterator.toList + // Debug argument must appear in the 'commands' section (after the sbt-launch.jar argument) to work + val sbtLaunchMatcher = """^.+sbt-launch.jar["]{0,1}$""".r + val locationOfSbtLaunchJarArg = out.zipWithIndex.collectFirst { + case (arg, index) if sbtLaunchMatcher.findFirstIn(arg).nonEmpty => index + } + + assert(locationOfSbtLaunchJarArg.nonEmpty) + + val argsAfterSbtLaunch = out.drop(locationOfSbtLaunchJarArg.get) + assert(argsAfterSbtLaunch.contains("-debug")) + () + } + + test("sbt --jvm-debug ") { + val out = sbtProcess("--jvm-debug", "12345", "compile", "-v").!!.linesIterator.toList + assert(out.contains[String]("-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=12345")) + () + } + + test("sbt --no-share adds three system properties") { + val out = sbtProcess("--no-share").!!.linesIterator.toList + assert(out.contains[String]("-Dsbt.global.base=project/.sbtboot")) + assert(out.contains[String]("-Dsbt.boot.directory=project/.boot")) + assert(out.contains[String]("-Dsbt.ivy.home=project/.ivy")) + () + } + + test("accept `--ivy` in `SBT_OPTS`") { + if (isWindows) cancel("Test not supported on windows") + val out = sbtProcessWithOpts("")("", sbtOpts = "--ivy /ivy/dir").!!.linesIterator.toList + assert(out.contains[String]("-Dsbt.ivy.home=/ivy/dir")) + () + } +} diff --git a/src/universal/bin/sbt b/src/universal/bin/sbt index cc8d830e8..1a046a9d6 100755 --- a/src/universal/bin/sbt +++ b/src/universal/bin/sbt @@ -403,7 +403,7 @@ run() { exit $exit_code } -declare -r noshare_opts="-Dsbt.global.base=project/.sbtboot -Dsbt.boot.directory=project/.boot -Dsbt.ivy.home=project/.ivy" +declare -ra noshare_opts=(-Dsbt.global.base=project/.sbtboot -Dsbt.boot.directory=project/.boot -Dsbt.ivy.home=project/.ivy) declare -r sbt_opts_file=".sbtopts" declare -r build_props_file="$(pwd)/project/build.properties" declare -r etc_sbt_opts_file="/etc/sbt/sbtopts" @@ -513,8 +513,9 @@ map_args () { -supershell=*) options=( "${options[@]}" "-Dsbt.supershell=${1:12}" ) && shift ;; --color=*) options=( "${options[@]}" "-Dsbt.color=${1:8}" ) && shift ;; -color=*) options=( "${options[@]}" "-Dsbt.color=${1:7}" ) && shift ;; - -no-share|--no-share) options=( "${options[@]}" "$noshare_opts" ) && shift ;; + -no-share|--no-share) options=( "${options[@]}" "${noshare_opts[@]}" ) && shift ;; -no-global|--no-global) options=( "${options[@]}" "-Dsbt.global.base=$(pwd)/project/.sbtboot" ) && shift ;; + -ivy|--ivy) require_arg path "$1" "$2" && options=( "${options[@]}" "-Dsbt.ivy.home=$2" ) && shift 2 ;; -sbt-boot|--sbt-boot) require_arg path "$1" "$2" && options=( "${options[@]}" "-Dsbt.boot.directory=$2" ) && shift 2 ;; -sbt-dir|--sbt-dir) require_arg path "$1" "$2" && options=( "${options[@]}" "-Dsbt.global.base=$2" ) && shift 2 ;; -debug|--debug) commands=( "${commands[@]}" "-debug" ) && shift ;; @@ -538,7 +539,6 @@ process_args () { --client) use_sbtn=1 && shift ;; --server) use_sbtn=0 && shift ;; - -ivy|--ivy) require_arg path "$1" "$2" && addJava "-Dsbt.ivy.home=$2" && shift 2 ;; -mem|--mem) require_arg integer "$1" "$2" && addMemory "$2" && shift 2 ;; -jvm-debug|--jvm-debug) require_arg port "$1" "$2" && addDebugger $2 && shift 2 ;; -batch|--batch) exec