From f39af0bab3e3d4ab3e756864c6adecfd21a5f9c9 Mon Sep 17 00:00:00 2001 From: Mark Harrah Date: Thu, 24 May 2012 21:50:23 -0400 Subject: [PATCH] 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. --- launch/Configuration.scala | 47 +++++++++++++++++-- .../main/resources/sbt.boot.properties0.10.0 | 23 +++++++++ .../main/resources/sbt.boot.properties0.10.1 | 23 +++++++++ .../main/resources/sbt.boot.properties0.11.0 | 23 +++++++++ .../main/resources/sbt.boot.properties0.11.1 | 23 +++++++++ .../main/resources/sbt.boot.properties0.11.2 | 23 +++++++++ .../main/resources/sbt.boot.properties0.11.3 | 23 +++++++++ .../src/main/resources/sbt.boot.properties0.7 | 24 ++++++++++ 8 files changed, 206 insertions(+), 3 deletions(-) create mode 100644 launch/src/main/resources/sbt.boot.properties0.10.0 create mode 100644 launch/src/main/resources/sbt.boot.properties0.10.1 create mode 100644 launch/src/main/resources/sbt.boot.properties0.11.0 create mode 100644 launch/src/main/resources/sbt.boot.properties0.11.1 create mode 100644 launch/src/main/resources/sbt.boot.properties0.11.2 create mode 100644 launch/src/main/resources/sbt.boot.properties0.11.3 create mode 100644 launch/src/main/resources/sbt.boot.properties0.7 diff --git a/launch/Configuration.scala b/launch/Configuration.scala index 7ad2c7e95..b704ec57c 100644 --- a/launch/Configuration.scala +++ b/launch/Configuration.scala @@ -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 } \ No newline at end of file diff --git a/launch/src/main/resources/sbt.boot.properties0.10.0 b/launch/src/main/resources/sbt.boot.properties0.10.0 new file mode 100644 index 000000000..47a411edb --- /dev/null +++ b/launch/src/main/resources/sbt.boot.properties0.10.0 @@ -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} \ No newline at end of file diff --git a/launch/src/main/resources/sbt.boot.properties0.10.1 b/launch/src/main/resources/sbt.boot.properties0.10.1 new file mode 100644 index 000000000..3c734b08d --- /dev/null +++ b/launch/src/main/resources/sbt.boot.properties0.10.1 @@ -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} \ No newline at end of file diff --git a/launch/src/main/resources/sbt.boot.properties0.11.0 b/launch/src/main/resources/sbt.boot.properties0.11.0 new file mode 100644 index 000000000..27727d7eb --- /dev/null +++ b/launch/src/main/resources/sbt.boot.properties0.11.0 @@ -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} \ No newline at end of file diff --git a/launch/src/main/resources/sbt.boot.properties0.11.1 b/launch/src/main/resources/sbt.boot.properties0.11.1 new file mode 100644 index 000000000..7439d2c13 --- /dev/null +++ b/launch/src/main/resources/sbt.boot.properties0.11.1 @@ -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} \ No newline at end of file diff --git a/launch/src/main/resources/sbt.boot.properties0.11.2 b/launch/src/main/resources/sbt.boot.properties0.11.2 new file mode 100644 index 000000000..6773ff547 --- /dev/null +++ b/launch/src/main/resources/sbt.boot.properties0.11.2 @@ -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} \ No newline at end of file diff --git a/launch/src/main/resources/sbt.boot.properties0.11.3 b/launch/src/main/resources/sbt.boot.properties0.11.3 new file mode 100644 index 000000000..e42b70738 --- /dev/null +++ b/launch/src/main/resources/sbt.boot.properties0.11.3 @@ -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} \ No newline at end of file diff --git a/launch/src/main/resources/sbt.boot.properties0.7 b/launch/src/main/resources/sbt.boot.properties0.7 new file mode 100644 index 000000000..b29cad683 --- /dev/null +++ b/launch/src/main/resources/sbt.boot.properties0.7 @@ -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}