mirror of https://github.com/sbt/sbt.git
support use of native libraries in 'run' and 'test'
This commit is contained in:
parent
29db8dbe8d
commit
1d4d566d6b
|
|
@ -235,7 +235,7 @@ object Defaults extends BuildCommon
|
|||
dirs.descendentsExcept("*",excl).get
|
||||
|
||||
lazy val testTasks: Seq[Setting[_]] = testTaskOptions(test) ++ testTaskOptions(testOnly) ++ Seq(
|
||||
testLoader <<= (fullClasspath, scalaInstance) map { (cp, si) => TestFramework.createTestLoader(data(cp), si) },
|
||||
testLoader <<= (fullClasspath, scalaInstance, taskTemporaryDirectory) map { (cp, si, temp) => TestFramework.createTestLoader(data(cp), si, IO.createUniqueDirectory(temp)) },
|
||||
testFrameworks in GlobalScope :== {
|
||||
import sbt.TestFrameworks._
|
||||
Seq(ScalaCheck, Specs2, Specs, ScalaTest, ScalaCheckCompat, ScalaTestCompat, SpecsCompat, JUnit)
|
||||
|
|
@ -403,12 +403,13 @@ object Defaults extends BuildCommon
|
|||
}
|
||||
|
||||
def runnerTask = runner <<= runnerInit
|
||||
def runnerInit: Initialize[Task[ScalaRun]] = (scalaInstance, baseDirectory, javaOptions, outputStrategy, fork, javaHome, trapExit) map { (si, base, options, strategy, forkRun, javaHomeDir, trap) =>
|
||||
def runnerInit: Initialize[Task[ScalaRun]] =
|
||||
(taskTemporaryDirectory, scalaInstance, baseDirectory, javaOptions, outputStrategy, fork, javaHome, trapExit) map { (tmp, si, base, options, strategy, forkRun, javaHomeDir, trap) =>
|
||||
if(forkRun) {
|
||||
new ForkRun( ForkOptions(scalaJars = si.jars, javaHome = javaHomeDir, outputStrategy = strategy,
|
||||
runJVMOptions = options, workingDirectory = Some(base)) )
|
||||
} else
|
||||
new Run(si, trap)
|
||||
new Run(si, trap, tmp)
|
||||
}
|
||||
|
||||
def docTask: Initialize[Task[File]] =
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ class ForkRun(config: ForkScalaRun) extends ScalaRun
|
|||
Some("Nonzero exit code returned from " + label + ": " + exitCode)
|
||||
}
|
||||
}
|
||||
class Run(instance: ScalaInstance, trapExit: Boolean) extends ScalaRun
|
||||
class Run(instance: ScalaInstance, trapExit: Boolean, nativeTmp: File) extends ScalaRun
|
||||
{
|
||||
/** Runs the class 'mainClass' using the given classpath and options using the scala runner.*/
|
||||
def run(mainClass: String, classpath: Seq[File], options: Seq[String], log: Logger) =
|
||||
|
|
@ -48,7 +48,7 @@ class Run(instance: ScalaInstance, trapExit: Boolean) extends ScalaRun
|
|||
private def run0(mainClassName: String, classpath: Seq[File], options: Seq[String], log: Logger)
|
||||
{
|
||||
log.debug(" Classpath:\n\t" + classpath.mkString("\n\t"))
|
||||
val loader = ClasspathUtilities.makeLoader(classpath, instance)
|
||||
val loader = ClasspathUtilities.makeLoader(classpath, instance.loader, instance, nativeTmp)
|
||||
val main = getMainMethod(mainClassName, loader)
|
||||
invokeMain(loader, main, options)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -194,13 +194,13 @@ object TestFramework
|
|||
Thread.currentThread.setContextClassLoader(loader)
|
||||
try { eval } finally { Thread.currentThread.setContextClassLoader(oldLoader) }
|
||||
}
|
||||
def createTestLoader(classpath: Seq[File], scalaInstance: ScalaInstance): ClassLoader =
|
||||
def createTestLoader(classpath: Seq[File], scalaInstance: ScalaInstance, tempDir: File): ClassLoader =
|
||||
{
|
||||
val declaresCompiler = classpath.exists(_.getName contains "scala-compiler")
|
||||
val filterCompilerLoader = if(declaresCompiler) scalaInstance.loader else new FilteredLoader(scalaInstance.loader, ScalaCompilerJarPackages)
|
||||
val interfaceFilter = (name: String) => name.startsWith("org.scalatools.testing.")
|
||||
val notInterfaceFilter = (name: String) => !interfaceFilter(name)
|
||||
val dual = new DualLoader(filterCompilerLoader, notInterfaceFilter, x => true, getClass.getClassLoader, interfaceFilter, x => false)
|
||||
ClasspathUtilities.makeLoader(classpath, dual, scalaInstance)
|
||||
ClasspathUtilities.makeLoader(classpath, dual, scalaInstance, tempDir)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue