From 1d4d566d6bb005930f350235e57b6efb2946819e Mon Sep 17 00:00:00 2001 From: Mark Harrah Date: Fri, 5 Aug 2011 21:56:32 -0400 Subject: [PATCH] support use of native libraries in 'run' and 'test' --- main/Defaults.scala | 7 ++++--- run/Run.scala | 4 ++-- testing/TestFramework.scala | 4 ++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/main/Defaults.scala b/main/Defaults.scala index 0e7d52a7a..1fab6814b 100644 --- a/main/Defaults.scala +++ b/main/Defaults.scala @@ -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]] = diff --git a/run/Run.scala b/run/Run.scala index afb04eadb..c9f16b6b1 100644 --- a/run/Run.scala +++ b/run/Run.scala @@ -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) } diff --git a/testing/TestFramework.scala b/testing/TestFramework.scala index 368a9f856..1e411295c 100644 --- a/testing/TestFramework.scala +++ b/testing/TestFramework.scala @@ -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) } }