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._
|
2009-10-16 00:10:11 +02:00
|
|
|
import java.io.{File, FileInputStream}
|
2009-09-26 08:18:04 +02:00
|
|
|
import java.util.Properties
|
|
|
|
|
|
2010-08-12 00:50:44 +02:00
|
|
|
object ResolveValues
|
2009-09-26 08:18:04 +02:00
|
|
|
{
|
2010-08-12 00:50:44 +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
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-12 00:50:44 +02:00
|
|
|
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)
|
2009-10-16 00:10:11 +02:00
|
|
|
def apply(): LaunchConfiguration =
|
2009-09-26 08:18:04 +02:00
|
|
|
{
|
|
|
|
|
import conf._
|
2009-10-20 05:18:13 +02:00
|
|
|
val scalaVersion = resolve(conf.scalaVersion)
|
|
|
|
|
val appVersion = resolve(app.version)
|
2010-08-12 00:50:44 +02:00
|
|
|
val classifiers = resolveClassifiers(ivyConfiguration.classifiers)
|
|
|
|
|
withVersions(scalaVersion, appVersion, classifiers)
|
2009-09-26 08:18:04 +02:00
|
|
|
}
|
2010-08-12 00:50:44 +02:00
|
|
|
def resolveClassifiers(classifiers: Classifiers): Classifiers =
|
2009-09-26 08:18:04 +02:00
|
|
|
{
|
2010-08-12 00:50:44 +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 =
|
2009-10-20 05:18:13 +02:00
|
|
|
v match
|
2009-09-26 08:18:04 +02:00
|
|
|
{
|
2010-08-12 00:50:44 +02:00
|
|
|
case e: Explicit[t] => e.value
|
|
|
|
|
case i: Implicit[t] =>
|
|
|
|
|
trim(properties.getProperty(i.name)) map read orElse
|
2009-10-20 05:18:13 +02:00
|
|
|
i.default getOrElse
|
|
|
|
|
error("No " + i.name + " specified in " + propertiesFile)
|
2009-09-26 08:18:04 +02:00
|
|
|
}
|
|
|
|
|
}
|