@@ -10,7 +10,6 @@ package sbt
10
10
import java .io .File
11
11
import java .lang .reflect .Method
12
12
import java .lang .reflect .Modifier .{ isPublic , isStatic }
13
-
14
13
import sbt .internal .inc .ScalaInstance
15
14
import sbt .internal .inc .classpath .{ ClasspathFilter , ClasspathUtil }
16
15
import sbt .internal .util .MessageOnlyException
@@ -34,29 +33,40 @@ class ForkRun(config: ForkOptions) extends ScalaRun {
34
33
s """ Nonzero exit code returned from $label: $exitCode""" .stripMargin
35
34
)
36
35
)
37
- val process = fork(mainClass, classpath, options, log)
38
- def cancel () = {
39
- log.warn(" Run canceled." )
40
- process.destroy()
41
- 1
36
+
37
+ log.info(s " running (fork) $mainClass ${Run .runOptionsStr(options)}" )
38
+ val c = configLogged(log)
39
+ val scalaOpts = scalaOptions(mainClass, classpath, options)
40
+ val exitCode = try Fork .java(c, scalaOpts)
41
+ catch {
42
+ case _ : InterruptedException =>
43
+ log.warn(" Run canceled." )
44
+ 1
42
45
}
43
- val exitCode = try process.exitValue()
44
- catch { case _ : InterruptedException => cancel() }
45
46
processExitCode(exitCode, " runner" )
46
47
}
47
48
48
49
def fork (mainClass : String , classpath : Seq [File ], options : Seq [String ], log : Logger ): Process = {
49
50
log.info(s " running (fork) $mainClass ${Run .runOptionsStr(options)}" )
50
51
51
- val scalaOptions = classpathOption(classpath) ::: mainClass :: options.toList
52
- val configLogged =
53
- if (config.outputStrategy.isDefined) config
54
- else config.withOutputStrategy(OutputStrategy .LoggedOutput (log))
52
+ val c = configLogged(log)
53
+ val scalaOpts = scalaOptions(mainClass, classpath, options)
54
+
55
55
// fork with Java because Scala introduces an extra class loader (#702)
56
- Fork .java.fork(configLogged, scalaOptions)
56
+ Fork .java.fork(c, scalaOpts)
57
+ }
58
+
59
+ private def configLogged (log : Logger ): ForkOptions = {
60
+ if (config.outputStrategy.isDefined) config
61
+ else config.withOutputStrategy(OutputStrategy .LoggedOutput (log))
57
62
}
58
- private def classpathOption (classpath : Seq [File ]) =
59
- " -classpath" :: Path .makeString(classpath) :: Nil
63
+
64
+ private def scalaOptions (
65
+ mainClass : String ,
66
+ classpath : Seq [File ],
67
+ options : Seq [String ]
68
+ ): Seq [String ] =
69
+ " -classpath" :: Path .makeString(classpath) :: mainClass :: options.toList
60
70
}
61
71
62
72
class Run (private [sbt] val newLoader : Seq [File ] => ClassLoader , trapExit : Boolean )
0 commit comments