Fork run directly with 'java' to avoid additional class loader from 'scala' command. Fixes #702.

This commit is contained in:
Mark Harrah 2013-04-05 09:02:24 -04:00
parent 382b55402b
commit b560ef280e
5 changed files with 29 additions and 1 deletions

View File

@ -24,7 +24,8 @@ class ForkRun(config: ForkOptions) extends ScalaRun
val scalaOptions = classpathOption(classpath) ::: mainClass :: options.toList
val configLogged = if(config.outputStrategy.isDefined) config else config.copy(outputStrategy = Some(LoggedOutput(log)))
val process = Fork.scala.fork(configLogged, scalaOptions)
// fork with Java because Scala introduces an extra class loader (#702)
val process = Fork.java.fork(configLogged, scalaOptions)
def cancel() = {
log.warn("Run canceled.")
process.destroy()

View File

@ -0,0 +1,8 @@
object CheckLoader {
def main(args: Array[String]) { apply() }
def apply() {
val loader = getClass.getClassLoader
val appLoader = ClassLoader.getSystemClassLoader
assert(loader eq appLoader, "Application classes not loaded in the system class loader")
}
}

View File

@ -0,0 +1,5 @@
name := "forked-test"
organization := "org.example"
libraryDependencies += "org.scalacheck" %% "scalacheck" % "1.10.0" % "test"

View File

@ -0,0 +1,8 @@
import org.scalacheck._
object TestForked extends Properties("Forked loader") {
property("Loaded from application loader") = Prop.secure {
CheckLoader()
true
}
}

View File

@ -0,0 +1,6 @@
# This test verifies that the forked code is loaded in the application class loader.
-> run
-> test
> set fork := true
> run
> test