mirror of https://github.com/sbt/sbt.git
Test and fixes for getting ClassLoader for Scala jars.
This commit is contained in:
parent
b716d33ba3
commit
efb1604f0e
|
|
@ -11,11 +11,12 @@
|
|||
import java.io.{File, FileFilter}
|
||||
import java.net.URLClassLoader
|
||||
|
||||
import xsbti.boot.{Exit => IExit, Launcher, MainResult, Reboot, SbtConfiguration, SbtMain}
|
||||
|
||||
// contains constants and paths
|
||||
import BootConfiguration._
|
||||
import UpdateTarget.{UpdateScala, UpdateSbt}
|
||||
|
||||
import xsbti.boot.{Exit => IExit, Launcher, MainResult, Reboot, SbtConfiguration, SbtMain}
|
||||
|
||||
class Launch(projectRootDirectory: File, mainClassName: String) extends Launcher with NotNull
|
||||
{
|
||||
|
|
@ -99,7 +100,7 @@ class Launch(projectRootDirectory: File, mainClassName: String) extends Launcher
|
|||
val scalaLoader = newScalaLoader(scalaDirectory)
|
||||
if(needsUpdate(scalaLoader, TestLoadScalaClasses))
|
||||
{
|
||||
(new Update(baseDirectory, scalaVersion, ""))(UpdateScala)
|
||||
(new Update(baseDirectory, "", scalaVersion))(UpdateScala)
|
||||
val scalaLoader = newScalaLoader(scalaDirectory)
|
||||
failIfMissing(scalaLoader, TestLoadScalaClasses, "Scala " + scalaVersion)
|
||||
scalaLoader
|
||||
|
|
@ -115,7 +116,7 @@ class Launch(projectRootDirectory: File, mainClassName: String) extends Launcher
|
|||
val sbtLoader = newSbtLoader(sbtDirectory, scalaLoader)
|
||||
if(needsUpdate(sbtLoader, TestLoadSbtClasses))
|
||||
{
|
||||
(new Update(baseDirectory, scalaVersion, sbtVersion))(UpdateSbt)
|
||||
(new Update(baseDirectory, sbtVersion, scalaVersion))(UpdateSbt)
|
||||
val sbtLoader = newSbtLoader(sbtDirectory, scalaLoader)
|
||||
failIfMissing(sbtLoader, TestLoadSbtClasses, "sbt " + sbtVersion)
|
||||
sbtLoader
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ import UpdateTarget.{UpdateSbt, UpdateScala}
|
|||
/** Ensures that the Scala and sbt jars exist for the given versions or else downloads them.*/
|
||||
final class Update(bootDirectory: File, sbtVersion: String, scalaVersion: String)
|
||||
{
|
||||
require(!scalaVersion.trim.isEmpty, "No Scala version specified")
|
||||
private def logFile = new File(bootDirectory, UpdateLogName)
|
||||
/** A Writer to use to write the full logging information to a file for debugging. **/
|
||||
private lazy val logWriter =
|
||||
|
|
@ -41,6 +42,8 @@ final class Update(bootDirectory: File, sbtVersion: String, scalaVersion: String
|
|||
/** The main entry point of this class for use by the Update module. It runs Ivy */
|
||||
def apply(target: UpdateTarget.Value)
|
||||
{
|
||||
if(target == UpdateTarget.UpdateSbt)
|
||||
require(!sbtVersion.isEmpty, "No sbt version specified")
|
||||
Message.setDefaultLogger(new SbtIvyLogger(logWriter))
|
||||
try { update(target) }
|
||||
catch
|
||||
|
|
|
|||
|
|
@ -0,0 +1,28 @@
|
|||
package xsbt
|
||||
|
||||
import java.util.Properties
|
||||
import xsbti.boot._
|
||||
import org.specs._
|
||||
|
||||
object ScalaProviderTest extends Specification
|
||||
{
|
||||
"Launch" should {
|
||||
"Provide ClassLoader for Scala 2.7.2" in { checkScalaLoader("2.7.2", "2.7.2") }
|
||||
"Provide ClassLoader for Scala 2.7.3" in { checkScalaLoader("2.7.3", "2.7.3.final") }
|
||||
"Provide ClassLoader for Scala 2.7.4" in { checkScalaLoader("2.7.4", "2.7.4.final") }
|
||||
"Provide ClassLoader for Scala 2.7.5" in { checkScalaLoader("2.7.5", "2.7.5.final") }
|
||||
}
|
||||
private def checkScalaLoader(version: String, versionValue: String): Unit = withLaunch(checkLauncher(version, versionValue))
|
||||
private def checkLauncher(version: String, versionValue: String)(launcher: Launcher): Unit =
|
||||
{
|
||||
val loader = launcher.getScalaLoader(version)
|
||||
Class.forName("scala.ScalaObject", false, loader)
|
||||
val propertiesStream = loader.getResourceAsStream("library.properties")
|
||||
val properties = new Properties
|
||||
properties.load(propertiesStream)
|
||||
properties.getProperty("version.number") must beEqualTo(versionValue)
|
||||
}
|
||||
private def withLaunch[T](f: Launcher => T): T = withLaunch("")(f)
|
||||
private def withLaunch[T](mainClass: String)(f: Launcher => T): T =
|
||||
FileUtilities.withTemporaryDirectory { temp => f(new xsbt.boot.Launch(temp, mainClass)) }
|
||||
}
|
||||
|
|
@ -2,15 +2,16 @@ import sbt._
|
|||
|
||||
class XSbt(info: ProjectInfo) extends ParentProject(info)
|
||||
{
|
||||
val launchInterfaceSub = project(launchPath / "interface", "Launcher Interface", new InterfaceProject(_))
|
||||
val testDeps = project("test-dependencies", "Dependencies", new TestDependencies(_))
|
||||
|
||||
val launchInterfaceSub = project(launchPath / "interface", "Launcher Interface", new InterfaceProject(_), testDeps)
|
||||
val launchSub = project(launchPath, "Launcher", new LaunchProject(_), launchInterfaceSub)
|
||||
|
||||
val commonDeps = project("common", "Dependencies", new CommonDependencies(_))
|
||||
val interfaceSub = project("interface", "Interface", new InterfaceProject(_))
|
||||
|
||||
val controlSub = project(utilPath / "control", "Control", new Base(_))
|
||||
val collectionSub = project(utilPath / "collection", "Collections", new Base(_))
|
||||
val ioSub = project(utilPath / "io", "IO", new Base(_), controlSub, commonDeps)
|
||||
val ioSub = project(utilPath / "io", "IO", new Base(_), controlSub, testDeps)
|
||||
val classpathSub = project(utilPath / "classpath", "Classpath", new Base(_))
|
||||
|
||||
val compilerInterfaceSub = project(compilePath / "interface", "Compiler Interface", new CompilerInterfaceProject(_), interfaceSub)
|
||||
|
|
@ -18,7 +19,7 @@ class XSbt(info: ProjectInfo) extends ParentProject(info)
|
|||
val ivySub = project("ivy", "Ivy", new IvyProject(_), interfaceSub)
|
||||
val logSub = project(utilPath / "log", "Logging", new Base(_))
|
||||
|
||||
val taskSub = project("tasks", "Tasks", new TaskProject(_), controlSub, collectionSub, commonDeps)
|
||||
val taskSub = project("tasks", "Tasks", new TaskProject(_), controlSub, collectionSub, testDeps)
|
||||
val cacheSub = project("cache", "Cache", new CacheProject(_), taskSub, ioSub)
|
||||
val compilerSub = project(compilePath, "Compile", new Base(_), interfaceSub, ivySub, ioSub, compilerInterfaceSub)
|
||||
|
||||
|
|
@ -26,11 +27,11 @@ class XSbt(info: ProjectInfo) extends ParentProject(info)
|
|||
def utilPath = path("util")
|
||||
def compilePath = path("compile")
|
||||
|
||||
class LaunchProject(info: ProjectInfo) extends Base(info)
|
||||
class LaunchProject(info: ProjectInfo) extends Base(info) with TestWithIO
|
||||
{
|
||||
val ivy = "org.apache.ivy" % "ivy" % "2.0.0"
|
||||
}
|
||||
class CommonDependencies(info: ProjectInfo) extends DefaultProject(info)
|
||||
class TestDependencies(info: ProjectInfo) extends DefaultProject(info)
|
||||
{
|
||||
val sc = "org.scala-tools.testing" % "scalacheck" % "1.5" % "test->default"
|
||||
val sp = "org.scala-tools.testing" % "specs" % "1.5.0" % "test->default"
|
||||
|
|
@ -47,12 +48,9 @@ class XSbt(info: ProjectInfo) extends ParentProject(info)
|
|||
{
|
||||
override def scratch = true
|
||||
}
|
||||
class IvyProject(info: ProjectInfo) extends Base(info)
|
||||
class IvyProject(info: ProjectInfo) extends Base(info) with TestWithIO
|
||||
{
|
||||
val ivy = "org.apache.ivy" % "ivy" % "2.0.0"
|
||||
// use IO from tests
|
||||
override def testCompileAction = super.testCompileAction dependsOn(ioSub.testCompile)
|
||||
override def testClasspath = super.testClasspath +++ ioSub.testClasspath
|
||||
}
|
||||
class InterfaceProject(info: ProjectInfo) extends DefaultProject(info)
|
||||
{
|
||||
|
|
@ -70,6 +68,12 @@ class XSbt(info: ProjectInfo) extends ParentProject(info)
|
|||
def testPackagePath = outputPath / "test.jar"
|
||||
lazy val packageForTest = packageTask(mainClasses +++ mainResources, testPackagePath, packageOptions).dependsOn(compile)
|
||||
}
|
||||
trait TestWithIO extends BasicScalaProject
|
||||
{
|
||||
// use IO from tests
|
||||
override def testCompileAction = super.testCompileAction dependsOn(ioSub.testCompile)
|
||||
override def testClasspath = super.testClasspath +++ ioSub.testClasspath
|
||||
}
|
||||
}
|
||||
trait SourceProject extends BasicScalaProject
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue