diff --git a/compile/interface/CompilerInterface.scala b/compile/interface/CompilerInterface.scala index b2103864a..f71cfe813 100644 --- a/compile/interface/CompilerInterface.scala +++ b/compile/interface/CompilerInterface.scala @@ -60,7 +60,7 @@ class CompilerInterface if(reporter.hasErrors) { debug("Compilation failed (CompilerInterface)") - throw new InterfaceCompileFailed(args, "Analyzed compilation failed") + throw new InterfaceCompileFailed(args, "Compilation failed") } } } diff --git a/launch/ConfigurationParser.scala b/launch/ConfigurationParser.scala index f2a2be7ed..26c285e21 100644 --- a/launch/ConfigurationParser.scala +++ b/launch/ConfigurationParser.scala @@ -32,16 +32,15 @@ class ConfigurationParser extends NotNull check(m6, "section") new LaunchConfiguration(scalaVersion, app, repositories, boot, logging, properties) } - def getScalaVersion(m: LabelMap) = check("label", getVersion(m)) - def getVersion(m: LabelMap): (Version, LabelMap) = process(m, "version", processVersion) - def processVersion(value: Option[String]): Version = value.map(version).getOrElse(Version.default) - def version(value: String): Version = + def getScalaVersion(m: LabelMap) = check("label", getVersion(m, "Scala version", "scala.version")) + def getVersion(m: LabelMap, label: String, defaultName: String): (Version, LabelMap) = process(m, "version", processVersion(label, defaultName)) + def processVersion(label: String, defaultName: String)(value: Option[String]): Version = + value.map(version(label)).getOrElse(new Version.Implicit(defaultName, None)) + def version(label: String)(value: String): Version = { - if(isEmpty(value)) error("Version cannot be empty (omit version declaration to use the default version)") - val tokens = trim(value.split(",", 2)) - import Version.{Explicit, Implicit} - val defaultVersion = if(tokens.length == 2) Some(tokens(1)) else None - Implicit(tokens(0), defaultVersion)(err => new Explicit(tokens(0))) + if(isEmpty(value)) error(label + " cannot be empty (omit version declaration to use the default version)") + try { parsePropertyValue(label, value)(Version.Implicit.apply) } + catch { case e: BootException => new Version.Explicit(value) } } def processSection[T](sections: SectionMap, name: String, f: LabelMap => T) = process[String,LabelMap,T](sections, name, m => f(m default(x => None))) @@ -90,7 +89,7 @@ class ConfigurationParser extends NotNull { val (org, m1) = id(m, "org", "org.scala-tools.sbt") val (name, m2) = id(m1, "name", "sbt") - val (rev, m3) = getVersion(m2) + val (rev, m3) = getVersion(m2, name + " version", name + ".version") val (main, m4) = id(m3, "class", "xsbt.Main") val (components, m5) = ids(m4, "components", List("default")) val (crossVersioned, m6) = id(m5, "cross-versioned", "true") diff --git a/launch/Create.scala b/launch/Create.scala index ec7ed1827..61ff779c9 100644 --- a/launch/Create.scala +++ b/launch/Create.scala @@ -26,10 +26,14 @@ object Initialize val properties = new Properties if(file.exists) Using(new FileInputStream(file))( properties.load ) - for(property <- appProperties; init <- select(property) if properties.getProperty(property.name) == null) - initialize(properties, property.name, init) - file.getParentFile.mkdirs() - Using(new FileOutputStream(file))( out => properties.save(out, "") ) + val uninitialized = + for(property <- appProperties; init <- select(property) if properties.getProperty(property.name) == null) yield + initialize(properties, property.name, init) + if(!uninitialized.isEmpty) + { + file.getParentFile.mkdirs() + Using(new FileOutputStream(file))( out => properties.save(out, "") ) + } } def initialize(properties: Properties, name: String, init: PropertyInit) { diff --git a/launch/LaunchConfiguration.scala b/launch/LaunchConfiguration.scala index d833d83c3..fbfc77297 100644 --- a/launch/LaunchConfiguration.scala +++ b/launch/LaunchConfiguration.scala @@ -18,18 +18,18 @@ sealed trait Version extends NotNull object Version { final class Explicit(val value: String) extends Version - final class Implicit(val default: Option[String]) extends Version + final class Implicit(val name: String, val default: Option[String]) extends Version { + require(isNonEmpty(name), "Name cannot be empty") require(default.isEmpty || isNonEmpty(default.get), "Default cannot be the empty string") } object Implicit { - def apply(s: String, default: Option[String])(handleError: String => Version): Version = - if(s == "read") new Implicit(default) else handleError("Expected 'read', got '" + s +"'") + def apply(s: String, name: String, default: Option[String]): Version = + if(s == "read") new Implicit(name, default) else error("Expected 'read', got '" + s +"'") } def get(v: Version) = v match { case e: Version.Explicit => e.value; case _ => throw new BootException("Unresolved version: " + v) } - def default = new Implicit(None) } final case class Application(groupID: String, name: String, version: Version, main: String, components: List[String], crossVersioned: Boolean) extends NotNull diff --git a/launch/ResolveVersions.scala b/launch/ResolveVersions.scala index c59828fcc..20fd82535 100644 --- a/launch/ResolveVersions.scala +++ b/launch/ResolveVersions.scala @@ -26,22 +26,19 @@ final class ResolveVersions(conf: LaunchConfiguration) extends NotNull def apply(): LaunchConfiguration = { import conf._ - val appVersionProperty = app.name.toLowerCase.replaceAll("\\s+",".") + ".version" - val scalaVersion = (new Resolve("scala.version", "Scala"))(conf.scalaVersion) - val appVersion = (new Resolve(appVersionProperty, app.name))(app.version) + val scalaVersion = resolve(conf.scalaVersion) + val appVersion = resolve(app.version) withVersions(scalaVersion, appVersion) } - private final class Resolve(versionProperty: String, label: String) extends NotNull + def resolve(v: Version): String = { - def noVersionInFile = throw new BootException("No " + versionProperty + " specified in " + propertiesFile) - def apply(v: Version): String = + v match { - v match - { - case e: Version.Explicit => e.value - case i: Version.Implicit => readVersion() orElse i.default getOrElse noVersionInFile - } + 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) } - def readVersion() = trim(properties.getProperty(versionProperty)) } } \ No newline at end of file diff --git a/launch/src/main/resources/sbt/sbt.boot.properties b/launch/src/main/resources/sbt/sbt.boot.properties index 76da5bfcd..839cad2b7 100644 --- a/launch/src/main/resources/sbt/sbt.boot.properties +++ b/launch/src/main/resources/sbt/sbt.boot.properties @@ -1,10 +1,10 @@ [scala] - version: read + version: read(def.scala.version) [app] org: org.scala-tools.sbt name: sbt - version: read + version: read(sbt.version) class: sbt.xMain components: xsbti cross-versioned: true @@ -30,7 +30,8 @@ project.name: quick=set(test), new=prompt(Name), fill=prompt(Name) project.organization: new=prompt(Organization) project.version: quick=set(1.0), new=prompt(Version)[1.0], fill=prompt(Version)[1.0] - scala.version: quick=set(2.7.5), new=prompt(Scala version)[2.7.5], fill=prompt(Scala version)[2.7.5] + def.scala.version: quick=set(2.7.5), new=set(2.7.5), fill=set(2.7.5) + build.scala.versions: quick=set(2.7.5), new=prompt(Scala version)[2.7.5], fill=prompt(Scala version)[2.7.5] sbt.version: quick=set(0.6.0), new=prompt(sbt version)[0.6.0], fill=prompt(sbt version)[0.6.0] project.scratch: quick=set(true) project.initialize: quick=set(true), new=set(true) \ No newline at end of file