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
|
|
|
|
|
|
|
|
|
|
object ResolveVersions
|
|
|
|
|
{
|
2009-10-16 00:10:11 +02:00
|
|
|
def apply(conf: LaunchConfiguration): LaunchConfiguration = (new ResolveVersions(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
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-16 00:10:11 +02:00
|
|
|
import ResolveVersions.{readProperties, trim}
|
2009-09-26 08:18:04 +02:00
|
|
|
final class ResolveVersions(conf: LaunchConfiguration) extends NotNull
|
|
|
|
|
{
|
|
|
|
|
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)
|
2009-10-16 00:10:11 +02:00
|
|
|
withVersions(scalaVersion, appVersion)
|
2009-09-26 08:18:04 +02:00
|
|
|
}
|
2009-10-20 05:18:13 +02:00
|
|
|
def resolve(v: Version): String =
|
2009-09-26 08:18:04 +02:00
|
|
|
{
|
2009-10-20 05:18:13 +02:00
|
|
|
v match
|
2009-09-26 08:18:04 +02:00
|
|
|
{
|
2009-10-20 05:18:13 +02:00
|
|
|
case e: Version.Explicit => e.value
|
|
|
|
|
case i: Version.Implicit =>
|
|
|
|
|
trim(properties.getProperty(i.name)) orElse
|
|
|
|
|
i.default getOrElse
|
|
|
|
|
error("No " + i.name + " specified in " + propertiesFile)
|
2009-09-26 08:18:04 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|