sbt/launch/ResolveValues.scala

54 lines
1.7 KiB
Scala
Raw Normal View History

2010-02-08 05:45:19 +01:00
/* sbt -- Simple Build Tool
* Copyright 2009 Mark Harrah
*/
2009-09-26 08:18:04 +02:00
package xsbt.boot
2009-10-18 04:40:02 +02:00
import Pre._
import java.io.{File, FileInputStream}
2009-09-26 08:18:04 +02:00
import java.util.Properties
object ResolveValues
2009-09-26 08:18:04 +02:00
{
def apply(conf: LaunchConfiguration): LaunchConfiguration = (new ResolveValues(conf))()
2009-09-26 08:18:04 +02:00
private def trim(s: String) = if(s eq null) None else notEmpty(s.trim)
2009-10-18 04:40:02 +02:00
private def notEmpty(s: String) = if(isEmpty(s)) None else Some(s)
2009-09-26 08:18:04 +02:00
private def readProperties(propertiesFile: File) =
{
val properties = new Properties
if(propertiesFile.exists)
Using( new FileInputStream(propertiesFile) )( properties.load )
properties
}
}
import ResolveValues.{readProperties, trim}
final class ResolveValues(conf: LaunchConfiguration) extends NotNull
2009-09-26 08:18:04 +02:00
{
private def propertiesFile = conf.boot.properties
private lazy val properties = readProperties(propertiesFile)
def apply(): LaunchConfiguration =
2009-09-26 08:18:04 +02:00
{
import conf._
val scalaVersion = resolve(conf.scalaVersion)
val appVersion = resolve(app.version)
val classifiers = resolveClassifiers(ivyConfiguration.classifiers)
withVersions(scalaVersion, appVersion, classifiers)
2009-09-26 08:18:04 +02:00
}
def resolveClassifiers(classifiers: Classifiers): Classifiers =
2009-09-26 08:18:04 +02:00
{
import ConfigurationParser.readIDs
// the added "" ensures that the main jars are retrieved
val scalaClassifiers = "" :: resolve(classifiers.forScala)
val appClassifiers = "" :: resolve(classifiers.app)
Classifiers(new Explicit(scalaClassifiers), new Explicit(appClassifiers))
}
def resolve[T](v: Value[T])(implicit read: String => T): T =
v match
2009-09-26 08:18:04 +02:00
{
case e: Explicit[t] => e.value
case i: Implicit[t] =>
trim(properties.getProperty(i.name)) map read orElse
i.default getOrElse
error("No " + i.name + " specified in " + propertiesFile)
2009-09-26 08:18:04 +02:00
}
}