mirror of https://github.com/sbt/sbt.git
Fork java, not scala.
This commit is contained in:
parent
7afc9e77c6
commit
68c5cbe438
|
|
@ -125,12 +125,7 @@ object Defaults extends BuildCommon
|
|||
name <<= thisProject(_.id),
|
||||
logManager <<= extraLoggers(LogManager.defaults),
|
||||
onLoadMessage <<= onLoadMessage or (name, thisProjectRef)("Set current project to " + _ + " (in build " + _.build +")"),
|
||||
runnerTask,
|
||||
forkOptions <<= (scalaInstance, baseDirectory, javaOptions, outputStrategy, javaHome, connectInput) map {
|
||||
(si, base, options, strategy, javaHomeDir, connectIn) =>
|
||||
ForkOptions(scalaJars = si.jars, javaHome = javaHomeDir, connectInput = connectIn, outputStrategy = strategy,
|
||||
runJVMOptions = options, workingDirectory = Some(base))
|
||||
}
|
||||
runnerTask
|
||||
)
|
||||
def paths = Seq(
|
||||
baseDirectory <<= thisProject(_.base),
|
||||
|
|
@ -291,15 +286,14 @@ object Defaults extends BuildCommon
|
|||
testOptions in GlobalScope :== Nil,
|
||||
testFilter in testOnly :== (selectedFilter _),
|
||||
testFilter in testQuick <<= testQuickFilter,
|
||||
executeTests <<= (streams in test, loadedTestFrameworks, testLoader, testGrouping in test, fullClasspath in test, forkOptions in test, resolvedScoped, state) flatMap {
|
||||
(s, frameworkMap, loader, groups, cp, forkOpts, scoped, st) =>
|
||||
executeTests <<= (streams in test, loadedTestFrameworks, testLoader, testGrouping in test, fullClasspath in test, javaOptions in test, javaHome, resolvedScoped, state) flatMap {
|
||||
(s, frameworkMap, loader, groups, cp, javaOpts, javaHome, scoped, st) =>
|
||||
implicit val display = Project.showContextKey(st)
|
||||
val results = groups map {
|
||||
case Tests.TestGroup(name, tests, config) =>
|
||||
config.subproc match {
|
||||
case Tests.Fork(extraJvm) =>
|
||||
val runner = new ForkRun(forkOpts.copy(runJVMOptions = forkOpts.runJVMOptions ++ extraJvm))
|
||||
ForkTests(frameworkMap.keys.toSeq, tests.toList, config, cp.map(_.data), runner, s.log)
|
||||
ForkTests(frameworkMap.keys.toSeq, tests.toList, config, cp.map(_.data), javaHome, javaOpts, s.log)
|
||||
case Tests.InProcess =>
|
||||
Tests(frameworkMap, loader, tests, config, noTestsMessage(scoped, name), s.log)
|
||||
}
|
||||
|
|
@ -374,8 +368,8 @@ object Defaults extends BuildCommon
|
|||
|
||||
def inputTests(key: InputKey[_]): Initialize[InputTask[Unit]] =
|
||||
InputTask( loadForParser(definedTestNames)( (s, i) => testOnlyParser(s, i getOrElse Nil) ) ) { result =>
|
||||
(streams, loadedTestFrameworks, testFilter in key, testGrouping in key, testLoader, resolvedScoped, result, fullClasspath in key, forkOptions in key, state) flatMap {
|
||||
case (s, frameworks, filter, groups, loader, scoped, (selected, frameworkOptions), cp, forkOpts, st) =>
|
||||
(streams, loadedTestFrameworks, testFilter in key, testGrouping in key, testLoader, resolvedScoped, result, fullClasspath in key, javaOptions in key, javaHome, state) flatMap {
|
||||
case (s, frameworks, filter, groups, loader, scoped, (selected, frameworkOptions), cp, javaOpts, javaHome, st) =>
|
||||
implicit val display = Project.showContextKey(st)
|
||||
val results = groups map {
|
||||
case Tests.TestGroup(name, tests, config) =>
|
||||
|
|
@ -383,8 +377,7 @@ object Defaults extends BuildCommon
|
|||
val newConfig = config.copy(options = modifiedOpts)
|
||||
newConfig.subproc match {
|
||||
case Tests.Fork(extraJvm) =>
|
||||
val runner = new ForkRun(forkOpts.copy(runJVMOptions = forkOpts.runJVMOptions ++ extraJvm))
|
||||
ForkTests(frameworks.keys.toSeq, tests.toList, newConfig, cp.map(_.data), runner, s.log)
|
||||
ForkTests(frameworks.keys.toSeq, tests.toList, newConfig, cp.map(_.data), javaHome, javaOpts, s.log)
|
||||
case Tests.InProcess =>
|
||||
Tests(frameworks, loader, tests, newConfig, noTestsMessage(scoped, name), s.log)
|
||||
}
|
||||
|
|
@ -529,8 +522,13 @@ object Defaults extends BuildCommon
|
|||
|
||||
def runnerTask = runner <<= runnerInit
|
||||
def runnerInit: Initialize[Task[ScalaRun]] =
|
||||
(taskTemporaryDirectory, scalaInstance, fork, trapExit, forkOptions) map { (tmp, si, forkRun, trap, forkOptions) =>
|
||||
if(forkRun) new ForkRun(forkOptions) else new Run(si, trap, tmp)
|
||||
(taskTemporaryDirectory, scalaInstance, baseDirectory, javaOptions, outputStrategy, fork, javaHome, trapExit, connectInput) map {
|
||||
(tmp, si, base, options, strategy, forkRun, javaHomeDir, trap, connectIn) =>
|
||||
if(forkRun) {
|
||||
new ForkRun( ForkOptions(scalaJars = si.jars, javaHome = javaHomeDir, connectInput = connectIn, outputStrategy = strategy,
|
||||
runJVMOptions = options, workingDirectory = Some(base)) )
|
||||
} else
|
||||
new Run(si, trap, tmp)
|
||||
}
|
||||
|
||||
@deprecated("Use `docTaskSettings` instead", "0.12.0")
|
||||
|
|
|
|||
|
|
@ -179,7 +179,6 @@ object Keys
|
|||
val trapExit = SettingKey[Boolean]("trap-exit", "If true, enables exit trapping and thread management for 'run'-like tasks. This is currently only suitable for serially-executed 'run'-like tasks.")
|
||||
|
||||
val fork = SettingKey[Boolean]("fork", "If true, forks a new JVM when running. If false, runs in the same JVM as the build.")
|
||||
val forkOptions = TaskKey[ForkOptions]("fork-options", "Options for starting new JVM when forking.")
|
||||
val outputStrategy = SettingKey[Option[sbt.OutputStrategy]]("output-strategy", "Selects how to log output when running a main class.")
|
||||
val connectInput = SettingKey[Boolean]("connect-input", "If true, connects standard input when running a main class forked.")
|
||||
val javaHome = SettingKey[Option[File]]("java-home", "Selects the Java installation used for compiling and forking. If None, uses the Java installation running the build.")
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import Tests._
|
|||
import ForkMain._
|
||||
|
||||
private[sbt] object ForkTests {
|
||||
def apply(frameworks: Seq[TestFramework], tests: List[TestDefinition], config: Execution, classpath: Seq[File], runner: ScalaRun, log: Logger): Task[Output] = {
|
||||
def apply(frameworks: Seq[TestFramework], tests: List[TestDefinition], config: Execution, classpath: Seq[File], javaHome: Option[File], javaOpts: Seq[String], log: Logger): Task[Output] = {
|
||||
val opts = config.options.toList
|
||||
val listeners = opts flatMap {
|
||||
case Listeners(ls) => ls
|
||||
|
|
@ -88,8 +88,10 @@ private[sbt] object ForkTests {
|
|||
t.start()
|
||||
|
||||
val fullCp = classpath ++: Seq(IO.classLocationFile[ForkMain], IO.classLocationFile[Framework])
|
||||
for (msg <- runner.run(classOf[ForkMain].getCanonicalName, fullCp, Seq(server.getLocalPort.toString), log)) {
|
||||
log.error(msg)
|
||||
val options = javaOpts ++: Seq("-classpath", fullCp mkString File.pathSeparator, classOf[ForkMain].getCanonicalName, server.getLocalPort.toString)
|
||||
val ec = Fork.java(javaHome, options, StdoutOutput)
|
||||
if (ec != 0) {
|
||||
log.error("Running java with options " + options.mkString(" ") + " failed with exit code " + ec)
|
||||
server.close()
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue