Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

file 164 lines (148 sloc) 7.14 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
/* sbt -- Simple Build Tool
* Copyright 2008, 2009, 2010 Mark Harrah
*/
package xsbt.boot

import Pre._
import BootConfiguration.{CompilerModuleName, LibraryModuleName}
import java.io.File
import java.net.URL

object Launch
{
def apply(arguments: List[String]): Unit = apply( (new File("")).getAbsoluteFile , arguments )

def apply(currentDirectory: File, arguments: List[String]): Unit =
Configuration.find(arguments, currentDirectory) match { case (configLocation, newArguments) => configured(currentDirectory, configLocation, newArguments) }

def configured(currentDirectory: File, configLocation: URL, arguments: List[String]): Unit =
{
val config = Configuration.parse(configLocation, currentDirectory)
Find(config, currentDirectory) match { case (resolved, baseDirectory) => parsed(baseDirectory, resolved, arguments) }
}
def parsed(currentDirectory: File, parsed: LaunchConfiguration, arguments: List[String]): Unit =
{
val propertiesFile = parsed.boot.properties
import parsed.boot.{enableQuick, promptCreate, promptFill}
if(isNonEmpty(promptCreate) && !propertiesFile.exists)
Initialize.create(propertiesFile, promptCreate, enableQuick, parsed.appProperties)
else if(promptFill)
Initialize.fill(propertiesFile, parsed.appProperties)
initialized(currentDirectory, parsed, arguments)
}
def initialized(currentDirectory: File, parsed: LaunchConfiguration, arguments: List[String]): Unit =
{
val resolved = ResolveVersions(parsed)
explicit(currentDirectory, resolved, arguments)
}

def explicit(currentDirectory: File, explicit: LaunchConfiguration, arguments: List[String]): Unit =
launch( run(Launcher(explicit)) ) (
new RunConfiguration(explicit.getScalaVersion, explicit.app.toID, currentDirectory, arguments) )

def run(launcher: xsbti.Launcher)(config: RunConfiguration): xsbti.MainResult =
{
import config._
val scalaProvider: xsbti.ScalaProvider = launcher.getScala(scalaVersion)
val appProvider: xsbti.AppProvider = scalaProvider.app(app)
val appConfig: xsbti.AppConfiguration = new AppConfiguration(toArray(arguments), workingDirectory, appProvider)

val main = appProvider.newMain()
main.run(appConfig)
}
final def launch(run: RunConfiguration => xsbti.MainResult)(config: RunConfiguration)
{
run(config) match
{
case e: xsbti.Exit => System.exit(e.code)
case r: xsbti.Reboot => launch(run)(new RunConfiguration(r.scalaVersion, r.app, r.baseDirectory, r.arguments.toList))
case x => throw new BootException("Invalid main result: " + x + (if(x eq null) "" else " (class: " + x.getClass + ")"))
}
}
}
final class RunConfiguration(val scalaVersion: String, val app: xsbti.ApplicationID, val workingDirectory: File, val arguments: List[String]) extends NotNull

import BootConfiguration.{appDirectoryName, baseDirectoryName, ScalaDirectoryName, TestLoadScalaClasses}
class Launch(val bootDirectory: File, repositories: List[Repository], scalaClassifiers: List[String]) extends xsbti.Launcher
{
bootDirectory.mkdirs
private val scalaProviders = new Cache[String, ScalaProvider](new ScalaProvider(_))
def getScala(version: String): xsbti.ScalaProvider = scalaProviders(version)

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

def globalLock: xsbti.GlobalLock = Locks

class ScalaProvider(val version: String) extends xsbti.ScalaProvider with Provider
{
def launcher: xsbti.Launcher = Launch.this
def parentLoader = topLoader

lazy val configuration = new UpdateConfiguration(bootDirectory, 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 libraryJar = new File(scalaHome, LibraryModuleName + ".jar")
override def classpath = array(compilerJar, libraryJar)
def baseDirectories = List(scalaHome)
def testLoadClasses = TestLoadScalaClasses
def target = new UpdateScala(scalaClassifiers)
def failLabel = "Scala " + version
def lockFile = updateLockFile
def extraClasspath = array()

def app(id: xsbti.ApplicationID): xsbti.AppProvider = new AppProvider(id)

class AppProvider(val id: xsbti.ApplicationID) extends xsbti.AppProvider with Provider
{
def scalaProvider: xsbti.ScalaProvider = ScalaProvider.this
def configuration = ScalaProvider.this.configuration
lazy val appHome = new File(libDirectory, appDirectoryName(id, File.separator))
def parentLoader = ScalaProvider.this.loader
def baseDirectories = appHome :: id.mainComponents.map(components.componentLocation).toList
def testLoadClasses = List(id.mainClass)
def target = new UpdateApp(Application(id))
def failLabel = id.name + " " + id.version
def lockFile = updateLockFile
def mainClasspath = fullClasspath
def extraClasspath = id.classpathExtra

lazy val mainClass: Class[T] forSome { type T <: xsbti.AppMain } =
{
val c = Class.forName(id.mainClass, true, loader)
c.asSubclass(classOf[xsbti.AppMain])
}
def newMain(): xsbti.AppMain = mainClass.newInstance

lazy val components = new ComponentProvider(appHome)
}
}
}
object Launcher
{
def apply(bootDirectory: File, repositories: List[Repository], scalaClassifiers: List[String]): xsbti.Launcher =
apply(bootDirectory, repositories, scalaClassifiers, GetLocks.find)
def apply(bootDirectory: File, repositories: List[Repository], scalaClassifiers: List[String], locks: xsbti.GlobalLock): xsbti.Launcher =
new Launch(bootDirectory, repositories, scalaClassifiers) {
override def globalLock = locks
}
def apply(explicit: LaunchConfiguration): xsbti.Launcher =
new Launch(explicit.boot.directory, explicit.repositories, explicit.scalaClassifiers)
def defaultAppProvider(baseDirectory: File): xsbti.AppProvider = getAppProvider(baseDirectory, Configuration.configurationOnClasspath)
def getAppProvider(baseDirectory: File, configLocation: URL): xsbti.AppProvider =
{
val parsed = ResolvePaths(Configuration.parse(configLocation, baseDirectory), baseDirectory)
Initialize.process(parsed.boot.properties, parsed.appProperties, Initialize.selectQuick)
val config = ResolveVersions(parsed)
val launcher = apply(config)
val scalaProvider = launcher.getScala(config.getScalaVersion)
scalaProvider.app(config.app.toID)
}
}
class ComponentProvider(baseDirectory: File) extends xsbti.ComponentProvider
{
def componentLocation(id: String): File = new File(baseDirectory, id)
def component(id: String) = Provider.wrapNull(componentLocation(id).listFiles).filter(_.isFile)
def defineComponent(id: String, files: Array[File]) =
{
val location = componentLocation(id)
if(location.exists)
throw new BootException("Cannot redefine component. ID: " + id + ", files: " + files.mkString(","))
else
Copy(files.toList, location)
}
def lockFile = ComponentProvider.lockFile(baseDirectory)
}
object ComponentProvider
{
def lockFile(baseDirectory: File) =
{
baseDirectory.mkdirs()
new File(baseDirectory, "sbt.components.lock")
}
}
Something went wrong with that request. Please try again.