diff options
author | Josh Suereth <joshua.suereth@gmail.com> | 2012-04-03 11:36:07 -0400 |
---|---|---|
committer | Josh Suereth <joshua.suereth@gmail.com> | 2012-04-03 11:36:07 -0400 |
commit | 4467438a58a3ce0342c1ab608b02b0f880c61aaf (patch) | |
tree | 24fbaa747309b4ea7eba029b9ccfafc62cd986ad /project/Versions.scala | |
parent | 9894b2c9bcfe9cec0a6853b69148e0c8b5a2508d (diff) | |
download | scala-4467438a58a3ce0342c1ab608b02b0f880c61aaf.tar.gz scala-4467438a58a3ce0342c1ab608b02b0f880c61aaf.tar.bz2 scala-4467438a58a3ce0342c1ab608b02b0f880c61aaf.zip |
Fixed up versioning scheme.
SBT build should now mimic ant build for versions.
Diffstat (limited to 'project/Versions.scala')
-rw-r--r-- | project/Versions.scala | 45 |
1 files changed, 39 insertions, 6 deletions
diff --git a/project/Versions.scala b/project/Versions.scala index fdfc6304fd..5f1fe0cacc 100644 --- a/project/Versions.scala +++ b/project/Versions.scala @@ -7,35 +7,68 @@ import java.io.FileInputStream import com.jsuereth.git.GitRunner import com.jsuereth.git.GitKeys.gitRunner +case class VersionInfo(canonical: String, + maven: String, + osgi: String) - +/** this file is responsible for setting up Scala versioning schemes and updating all the necessary bits. */ object Versions { val buildNumberFile = SettingKey[File]("scala-build-number-file") // TODO - Make this a setting? - val buildNumberProps = TaskKey[BaseBuildNumber]("scala-build-number-props") + val buildNumberProps = SettingKey[BaseBuildNumber]("scala-build-number-props") val buildRelease = SettingKey[Boolean]("scala-build-release", "This is set to true if we're building a release.") val mavenSuffix = SettingKey[String]("scala-maven-suffix", "This is set to whatever maven suffix is required.") val gitSha = TaskKey[String]("scala-git-sha", "The sha of the current git commit.") val gitDate = TaskKey[String]("scala-git-date", "The date of the current git commit.") - val mavenVersion = TaskKey[String]("scala-maven-version", "The maven version number.") + val mavenVersion = SettingKey[String]("scala-maven-version", "The maven version number.") val osgiVersion = TaskKey[String]("scala-osgi-version", "The OSGi version number.") val canonicalVersion = TaskKey[String]("scala-canonical-version", "The canonical version number.") + val scalaVersions = TaskKey[VersionInfo]("scala-version-info", "The scala versions used for this build.") + + def settings: Seq[Setting[_]] = Seq( buildNumberFile <<= baseDirectory apply (_ / "build.number"), - buildNumberProps <<= buildNumberFile map loadBuildNumberProps, + buildNumberProps <<= buildNumberFile apply loadBuildNumberProps, buildRelease := Option(System.getProperty("build.release")) map (!_.isEmpty) getOrElse false, mavenSuffix <<= buildRelease apply pickMavenSuffix, - mavenVersion <<= (buildNumberProps, mavenSuffix) map makeMavenVersion, + mavenVersion <<= (buildNumberProps, mavenSuffix) apply makeMavenVersion, gitSha <<= (gitRunner, baseDirectory, streams) map getGitSha, gitDate <<= (gitRunner, baseDirectory, streams) map getGitDate, osgiVersion <<= (buildNumberProps, gitDate, gitSha) map makeOsgiVersion, - canonicalVersion <<= (buildRelease, mavenVersion, buildNumberProps, gitDate, gitSha) map makeCanonicalVersion + canonicalVersion <<= (buildRelease, mavenVersion, buildNumberProps, gitDate, gitSha) map makeCanonicalVersion, + scalaVersions <<= (canonicalVersion, mavenVersion, osgiVersion) map VersionInfo.apply ) + + /** This generates a properties file, if it does not already exist, with the maximum lastmodified timestamp + * of any source file. */ + def generateVersionPropertiesFile(name: String)(dir: File, versions: VersionInfo, s: TaskStreams): Seq[File] = { + // TODO - We can probably clean this up by moving caching bits elsewhere perhaps.... + val target = dir / name + // TODO - Regenerate on triggers, like recompilation or something... + def hasSameVersion: Boolean = { + val props = new java.util.Properties + val in = new java.io.FileInputStream(target) + try props.load(in) finally in.close() + versions.canonical == (props getProperty "version.number") + } + if (!target.exists || !hasSameVersion) { + makeVersionPropertiesFile(target, versions) + } + target :: Nil + } + + // This creates the *.properties file used to determine the current version of scala at runtime. TODO - move these somewhere utility like. + def makeVersionPropertiesFile(f: File, versions: VersionInfo): Unit = + IO.write(f, "version.number = "+versions.canonical+"\n"+ + "osgi.number = "+versions.osgi+"\n"+ + "maven.number = "+versions.maven+"\n"+ + "copyright.string = Copyright 2002-2011, LAMP/EPFL") + def makeCanonicalVersion(isRelease: Boolean, mvnVersion: String, base: BaseBuildNumber, gitDate: String, gitSha: String): String = if(isRelease) mvnVersion else { |