Permalink
Browse files

a more universal launcher

when a properties file is not otherwise explicitly specified,
the sbt.version from project/build.properties is used to select
the default properties file to use.  This launcher should be able
to launch:

 0.7.x
 0.10.{0,1}
 0.11.{0,1,2,3}
 0.12.x

Note that it can only launch the release versions of 0.10 and 0.11
listed above and in particular cannot launch snapshot versions.  All
0.12.x versions and 0.7.x versions should be supported, although only
0.7.7 was tested.
  • Loading branch information...
1 parent cf2402c commit f39af0bab3e3d4ab3e756864c6adecfd21a5f9c9 @harrah committed May 25, 2012
@@ -6,6 +6,7 @@ package xsbt.boot
import Pre._
import java.io.{File, FileInputStream, InputStreamReader}
import java.net.{MalformedURLException, URI, URL}
+import java.util.regex.Pattern
import scala.collection.immutable.List
import annotation.tailrec
@@ -35,8 +36,9 @@ object Configuration
}
def configurationOnClasspath: URL =
{
- resourcePaths.iterator.map(getClass.getResource).find(_ ne null) getOrElse
- ( multiPartError("Could not finder sbt launch configuration. Searched classpath for:", resourcePaths))
+ val paths = resourcePaths(guessSbtVersion)
+ paths.iterator.map(getClass.getResource).find(neNull) getOrElse
+ ( multiPartError("Could not finder sbt launch configuration. Searched classpath for:", paths))
}
def directConfiguration(path: String, baseDirectory: File): URL =
{
@@ -59,11 +61,49 @@ object Configuration
}
def multiPartError[T](firstLine: String, lines: List[T]) = error( (firstLine :: lines).mkString("\n\t") )
+ def DefaultBuildProperties = "project/build.properties"
+ def SbtVersionProperty = "sbt.version"
val ConfigurationName = "sbt.boot.properties"
val JarBasePath = "/sbt/"
def userConfigurationPath = "/" + ConfigurationName
def defaultConfigurationPath = JarBasePath + ConfigurationName
- def resourcePaths: List[String] = userConfigurationPath :: defaultConfigurationPath :: Nil
+ val baseResourcePaths: List[String] = userConfigurationPath :: defaultConfigurationPath :: Nil
+ def resourcePaths(sbtVersion: Option[String]): List[String] =
+ versionParts(sbtVersion) flatMap { part =>
+ baseResourcePaths map { base =>
+ base + part
+ }
+ }
+ def fallbackParts: List[String] = "" :: Nil
+ def versionParts(version: Option[String]): List[String] =
+ version match {
+ case None => fallbackParts
+ case Some(v) => versionParts(v)
+ }
+ def versionParts(version: String): List[String] =
+ {
+ val pattern = Pattern.compile("""(\d+)\.(\d+)\.(\d+)(-.*)?""")
+ val m = pattern.matcher(version)
+ if(m.matches())
+ subPartsIndices map {_.map(m.group).filter(neNull).mkString(".") }
+ else
+ fallbackParts
+ }
+ private[this] def subPartsIndices =
+ (1 :: 2 :: Nil) ::
+ (1 :: 2 :: 3 :: Nil) ::
+ (1 :: 2 :: 3 :: 4 :: Nil) ::
+ (Nil) ::
+ Nil
+ // the location of project/build.properties and the name of the property within that file
+ // that configures the sbt version is configured in sbt.boot.properties.
+ // We have to hard code them here in order to use them to determine the location of sbt.boot.properties itself
+ def guessSbtVersion: Option[String] =
+ {
+ val props = ResolveValues.readProperties(new File(DefaultBuildProperties))
+ Option(props.getProperty(SbtVersionProperty))
+ }
+
def resolveAgainst(baseDirectory: File): List[URI] = (baseDirectory toURI) :: (new File(System.getProperty("user.home")) toURI) ::
toDirectory(classLocation(getClass).toURI) :: Nil
@@ -81,4 +121,5 @@ object Configuration
newFile.toURI
}
catch { case _: Exception => uri }
+ private[this] def neNull: AnyRef => Boolean = _ ne null
}
@@ -0,0 +1,23 @@
+[scala]
+ version: 2.8.1
+
+[app]
+ org: ${sbt.organization-org.scala-tools.sbt}
+ name: sbt
+ version: ${sbt.version-0.10.0}
+ class: ${sbt.main.class-sbt.xMain}
+ components: xsbti,extra
+ cross-versioned: ${sbt.cross.versioned-true}
+
+[repositories]
+ local
+ typesafe-ivy-releases: http://repo.typesafe.com/typesafe/ivy-releases/, [organization]/[module]/[revision]/[type]s/[artifact](-[classifier]).[ext]
+ maven-central
+ sonatype-snapshots: https://oss.sonatype.org/content/repositories/snapshots
+
+[boot]
+ directory: ${sbt.boot.directory-${sbt.global.base-${user.home}/.sbt}/boot/}
+
+[ivy]
+ ivy-home: ${sbt.ivy.home-${user.home}/.ivy2/}
+ checksums: ${sbt.checksums-sha1,md5}
@@ -0,0 +1,23 @@
+[scala]
+ version: 2.8.1
+
+[app]
+ org: ${sbt.organization-org.scala-tools.sbt}
+ name: sbt
+ version: ${sbt.version-0.10.1}
+ class: ${sbt.main.class-sbt.xMain}
+ components: xsbti,extra
+ cross-versioned: ${sbt.cross.versioned-true}
+
+[repositories]
+ local
+ typesafe-ivy-releases: http://repo.typesafe.com/typesafe/ivy-releases/, [organization]/[module]/[revision]/[type]s/[artifact](-[classifier]).[ext]
+ maven-central
+ sonatype-snapshots: https://oss.sonatype.org/content/repositories/snapshots
+
+[boot]
+ directory: ${sbt.boot.directory-${sbt.global.base-${user.home}/.sbt}/boot/}
+
+[ivy]
+ ivy-home: ${sbt.ivy.home-${user.home}/.ivy2/}
+ checksums: ${sbt.checksums-sha1,md5}
@@ -0,0 +1,23 @@
+[scala]
+ version: 2.9.1
+
+[app]
+ org: ${sbt.organization-org.scala-tools.sbt}
+ name: sbt
+ version: ${sbt.version-0.11.0}
+ class: ${sbt.main.class-sbt.xMain}
+ components: xsbti,extra
+ cross-versioned: ${sbt.cross.versioned-true}
+
+[repositories]
+ local
+ typesafe-ivy-releases: http://repo.typesafe.com/typesafe/ivy-releases/, [organization]/[module]/[revision]/[type]s/[artifact](-[classifier]).[ext]
+ maven-central
+ sonatype-snapshots: https://oss.sonatype.org/content/repositories/snapshots
+
+[boot]
+ directory: ${sbt.boot.directory-${sbt.global.base-${user.home}/.sbt}/boot/}
+
+[ivy]
+ ivy-home: ${sbt.ivy.home-${user.home}/.ivy2/}
+ checksums: ${sbt.checksums-sha1,md5}
@@ -0,0 +1,23 @@
+[scala]
+ version: 2.9.1
+
+[app]
+ org: ${sbt.organization-org.scala-tools.sbt}
+ name: sbt
+ version: ${sbt.version-0.11.1}
+ class: ${sbt.main.class-sbt.xMain}
+ components: xsbti,extra
+ cross-versioned: ${sbt.cross.versioned-true}
+
+[repositories]
+ local
+ typesafe-ivy-releases: http://repo.typesafe.com/typesafe/ivy-releases/, [organization]/[module]/[revision]/[type]s/[artifact](-[classifier]).[ext]
+ maven-central
+ sonatype-snapshots: https://oss.sonatype.org/content/repositories/snapshots
+
+[boot]
+ directory: ${sbt.boot.directory-${sbt.global.base-${user.home}/.sbt}/boot/}
+
+[ivy]
+ ivy-home: ${sbt.ivy.home-${user.home}/.ivy2/}
+ checksums: ${sbt.checksums-sha1,md5}
@@ -0,0 +1,23 @@
+[scala]
+ version: 2.9.1
+
+[app]
+ org: ${sbt.organization-org.scala-tools.sbt}
+ name: sbt
+ version: ${sbt.version-0.11.2}
+ class: ${sbt.main.class-sbt.xMain}
+ components: xsbti,extra
+ cross-versioned: ${sbt.cross.versioned-true}
+
+[repositories]
+ local
+ typesafe-ivy-releases: http://repo.typesafe.com/typesafe/ivy-releases/, [organization]/[module]/[revision]/[type]s/[artifact](-[classifier]).[ext]
+ maven-central
+ sonatype-snapshots: https://oss.sonatype.org/content/repositories/snapshots
+
+[boot]
+ directory: ${sbt.boot.directory-${sbt.global.base-${user.home}/.sbt}/boot/}
+
+[ivy]
+ ivy-home: ${sbt.ivy.home-${user.home}/.ivy2/}
+ checksums: ${sbt.checksums-sha1,md5}
@@ -0,0 +1,23 @@
+[scala]
+ version: 2.9.1
+
+[app]
+ org: ${sbt.organization-org.scala-sbt}
+ name: sbt
+ version: ${sbt.version-0.11.3}
+ class: ${sbt.main.class-sbt.xMain}
+ components: xsbti,extra
+ cross-versioned: ${sbt.cross.versioned-true}
+
+[repositories]
+ local
+ typesafe-ivy-releases: http://repo.typesafe.com/typesafe/ivy-releases/, [organization]/[module]/[revision]/[type]s/[artifact](-[classifier]).[ext]
+ maven-central
+ sonatype-snapshots: https://oss.sonatype.org/content/repositories/snapshots
+
+[boot]
+ directory: ${sbt.boot.directory-${sbt.global.base-${user.home}/.sbt}/boot/}
+
+[ivy]
+ ivy-home: ${sbt.ivy.home-${user.home}/.ivy2/}
+ checksums: ${sbt.checksums-sha1,md5}
@@ -0,0 +1,24 @@
+[scala]
+ version: 2.7.7
+
+[app]
+ org: ${sbt.organization-org.scala-tools.sbt}
+ name: sbt
+ version: ${sbt.version-read(sbt.version)}
+ class: ${sbt.main.class-sbt.xMain}
+ components: xsbti
+ cross-versioned: ${sbt.cross.versioned-true}
+
+[repositories]
+ local
+ sbt-db: http://databinder.net/repo/, [organization]/[module]/[revision]/[type]s/[artifact](-[classifier]).[ext]
+ maven-central
+ sonatype-snapshots: https://oss.sonatype.org/content/repositories/snapshots
+
+[boot]
+ directory: ${sbt.boot.directory-${sbt.global.base-${user.home}/.sbt}/boot/}
+ properties: project/build.properties
+
+[ivy]
+ ivy-home: ${sbt.ivy.home-${user.home}/.ivy2/}
+ checksums: ${sbt.checksums-sha1,md5}

0 comments on commit f39af0b

Please sign in to comment.