Skip to content

Commit

Permalink
jline support for 2.9
Browse files Browse the repository at this point in the history
  • Loading branch information
harrah committed Mar 5, 2011
1 parent e7b47d6 commit ec8c543
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 11 deletions.
2 changes: 1 addition & 1 deletion launch/BootConfiguration.scala
Expand Up @@ -68,7 +68,7 @@ private object BootConfiguration
/** The name of the directory to retrieve the application and its dependencies to.*/
def appDirectoryName(appID: xsbti.ApplicationID, sep: String) = appID.groupID + sep + appID.name + sep + appID.version
/** The name of the directory in the boot directory to put all jars for the given version of scala in.*/
def baseDirectoryName(scalaVersion: String) = "scala-" + scalaVersion
def baseDirectoryName(scalaVersion: String) = if(scalaVersion.isEmpty) "other" else "scala-" + scalaVersion
}
private object ProxyProperties
{
Expand Down
20 changes: 17 additions & 3 deletions launch/Launch.scala
Expand Up @@ -83,12 +83,26 @@ class Launch private[xsbt](val bootDirectory: File, val ivyOptions: IvyOptions)
private val scalaProviders = new Cache[String, ScalaProvider](new ScalaProvider(_))
def getScala(version: String): xsbti.ScalaProvider = scalaProviders(version)

lazy val topLoader = new BootFilteredLoader(getClass.getClassLoader)
lazy val topLoader = (new JNAProvider).loader
val updateLockFile = new File(bootDirectory, "sbt.boot.lock")

def globalLock: xsbti.GlobalLock = Locks
def cacheDirectory = ivyOptions.cacheDirectory.orNull

class JNAProvider extends Provider
{
lazy val id = new Application("net.java.dev.jna", "jna", new Explicit("3.2.3"), "", Nil, false, array())
lazy val configuration = new UpdateConfiguration(bootDirectory, ivyOptions.cacheDirectory, "", repositories)
lazy val libDirectory = new File(bootDirectory, baseDirectoryName(""))
def baseDirectories: List[File] = new File(libDirectory, appDirectoryName(id.toID, File.separator)) :: Nil
def testLoadClasses: List[String] = "com.sun.jna.Function" :: Nil
def extraClasspath = array()
def target = new UpdateApp(id, Nil)
lazy val parentLoader = new BootFilteredLoader(getClass.getClassLoader)
def failLabel = "JNA"
def lockFile = updateLockFile
}

class ScalaProvider(val version: String) extends xsbti.ScalaProvider with Provider
{
def launcher: xsbti.Launcher = Launch.this
Expand All @@ -97,9 +111,9 @@ class Launch private[xsbt](val bootDirectory: File, val ivyOptions: IvyOptions)
lazy val configuration = new UpdateConfiguration(bootDirectory, ivyOptions.cacheDirectory, version, repositories)
lazy val libDirectory = new File(configuration.bootDirectory, baseDirectoryName(version))
lazy val scalaHome = new File(libDirectory, ScalaDirectoryName)
def compilerJar = new File(scalaHome,CompilerModuleName + ".jar")
def compilerJar = new File(scalaHome, CompilerModuleName + ".jar")
def libraryJar = new File(scalaHome, LibraryModuleName + ".jar")
override def classpath = array(compilerJar, libraryJar)
override def classpath = Provider.getJars(scalaHome :: Nil)
def baseDirectories = List(scalaHome)
def testLoadClasses = TestLoadScalaClasses
def target = new UpdateScala(Value.get(classifiers.forScala))
Expand Down
9 changes: 5 additions & 4 deletions launch/Update.scala
Expand Up @@ -26,11 +26,11 @@ import util.{DefaultMessageLogger, Message, MessageLoggerEngine}

import BootConfiguration._

sealed trait UpdateTarget extends NotNull { def tpe: String; def classifiers: List[String] }
sealed trait UpdateTarget { def tpe: String; def classifiers: List[String] }
final class UpdateScala(val classifiers: List[String]) extends UpdateTarget { def tpe = "scala" }
final class UpdateApp(val id: Application, val classifiers: List[String]) extends UpdateTarget { def tpe = "app" }

final class UpdateConfiguration(val bootDirectory: File, val ivyCacheDirectory: Option[File], val scalaVersion: String, val repositories: List[Repository]) extends NotNull
final class UpdateConfiguration(val bootDirectory: File, val ivyCacheDirectory: Option[File], val scalaVersion: String, val repositories: List[Repository])

/** Ensures that the Scala and application jars exist for the given versions or else downloads them.*/
final class Update(config: UpdateConfiguration)
Expand Down Expand Up @@ -97,7 +97,7 @@ final class Update(config: UpdateConfiguration)
target match
{
case u: UpdateScala =>
addDependency(moduleID, ScalaOrg, CompilerModuleName, scalaVersion, "default", u.classifiers)
addDependency(moduleID, ScalaOrg, CompilerModuleName, scalaVersion, "default;optional", u.classifiers)
addDependency(moduleID, ScalaOrg, LibraryModuleName, scalaVersion, "default", u.classifiers)
System.out.println("Getting Scala " + scalaVersion + " ...")
case u: UpdateApp =>
Expand All @@ -122,7 +122,8 @@ final class Update(config: UpdateConfiguration)
private def addDependency(moduleID: DefaultModuleDescriptor, organization: String, name: String, revision: String, conf: String, classifiers: List[String])
{
val dep = new DefaultDependencyDescriptor(moduleID, createID(organization, name, revision), false, false, true)
dep.addDependencyConfiguration(DefaultIvyConfiguration, conf)
for(c <- conf.split(";"))
dep.addDependencyConfiguration(DefaultIvyConfiguration, c)
for(classifier <- classifiers)
addClassifier(dep, name, classifier)
moduleID.addDependency(dep)
Expand Down
7 changes: 4 additions & 3 deletions util/classpath/ScalaInstance.scala
Expand Up @@ -26,12 +26,12 @@ object ScalaInstance
def apply(version: String, launcher: xsbti.Launcher): ScalaInstance =
apply(version, launcher.getScala(version))
def apply(version: String, provider: xsbti.ScalaProvider): ScalaInstance =
new ScalaInstance(version, provider.loader, provider.libraryJar, provider.compilerJar, Nil)
new ScalaInstance(version, provider.loader, provider.libraryJar, provider.compilerJar, provider.jars - provider.libraryJar - provider.compilerJar)

def apply(scalaHome: File, launcher: xsbti.Launcher): ScalaInstance =
apply(libraryJar(scalaHome), compilerJar(scalaHome), launcher)
apply(libraryJar(scalaHome), compilerJar(scalaHome), launcher, jlineJar(scalaHome))
def apply(version: String, scalaHome: File, launcher: xsbti.Launcher): ScalaInstance =
apply(version, libraryJar(scalaHome), compilerJar(scalaHome), launcher)
apply(version, libraryJar(scalaHome), compilerJar(scalaHome), launcher, jlineJar(scalaHome))
def apply(libraryJar: File, compilerJar: File, launcher: xsbti.Launcher, extraJars: File*): ScalaInstance =
{
val loader = scalaLoader(launcher, libraryJar :: compilerJar :: extraJars.toList)
Expand All @@ -43,6 +43,7 @@ object ScalaInstance

private def compilerJar(scalaHome: File) = scalaJar(scalaHome, "scala-compiler.jar")
private def libraryJar(scalaHome: File) = scalaJar(scalaHome, "scala-library.jar")
private def jlineJar(scalaHome: File) = scalaJar(scalaHome, "jline.jar")
def scalaJar(scalaHome: File, name: String) = new File(scalaHome, "lib" + File.separator + name)

/** Gets the version of Scala in the compiler.properties file from the loader.*/
Expand Down

0 comments on commit ec8c543

Please sign in to comment.