diff options
Diffstat (limited to 'project/VersionUtil.scala')
-rw-r--r-- | project/VersionUtil.scala | 76 |
1 files changed, 52 insertions, 24 deletions
diff --git a/project/VersionUtil.scala b/project/VersionUtil.scala index 3f9b727ef0..2363708f1d 100644 --- a/project/VersionUtil.scala +++ b/project/VersionUtil.scala @@ -1,15 +1,21 @@ +package scala.build + import sbt._ import Keys._ -import java.util.Properties +import java.util.{Date, Locale, Properties, TimeZone} import java.io.{File, FileInputStream} +import java.text.SimpleDateFormat + import scala.collection.JavaConverters._ import BuildSettings.autoImport._ object VersionUtil { lazy val copyrightString = settingKey[String]("Copyright string.") lazy val versionProperties = settingKey[Versions]("Version properties.") - lazy val generateVersionPropertiesFile = taskKey[File]("Generating version properties file.") - lazy val generateBuildCharacterPropertiesFile = taskKey[File]("Generating buildcharacter.properties file.") + lazy val buildCharacterPropertiesFile = settingKey[File]("The file which gets generated by generateBuildCharacterPropertiesFile") + lazy val generateVersionPropertiesFile = taskKey[File]("Generate version properties file.") + lazy val generateBuildCharacterPropertiesFile = taskKey[File]("Generate buildcharacter.properties file.") + lazy val extractBuildCharacterPropertiesFile = taskKey[File]("Extract buildcharacter.properties file from bootstrap scala-compiler.") lazy val globalVersionSettings = Seq[Setting[_]]( // Set the version properties globally (they are the same for all projects) @@ -24,15 +30,17 @@ object VersionUtil { ) lazy val generateBuildCharacterFileSettings = Seq[Setting[_]]( + buildCharacterPropertiesFile := ((baseDirectory in ThisBuild).value / "buildcharacter.properties"), generateBuildCharacterPropertiesFile := generateBuildCharacterPropertiesFileImpl.value ) - case class Versions(canonicalVersion: String, mavenVersion: String, osgiVersion: String, commitSha: String, commitDate: String, isRelease: Boolean) { + case class Versions(canonicalVersion: String, mavenBase: String, mavenSuffix: String, osgiVersion: String, commitSha: String, commitDate: String, isRelease: Boolean) { val githubTree = if(isRelease) "v" + mavenVersion else if(commitSha != "unknown") commitSha else "master" + def mavenVersion: String = mavenBase + mavenSuffix override def toString = s"Canonical: $canonicalVersion, Maven: $mavenVersion, OSGi: $osgiVersion, github: $githubTree" def toMap: Map[String, String] = Map( @@ -59,26 +67,42 @@ object VersionUtil { * suffix is used for releases. All other suffix values are treated as RC / milestone builds. The special suffix * value "SPLIT" is used to split the real suffix off from `baseVersion` instead and then apply the usual logic. */ private lazy val versionPropertiesImpl: Def.Initialize[Versions] = Def.setting { + val log = sLog.value val (base, suffix) = { val (b, s) = (baseVersion.value, baseVersionSuffix.value) if(s == "SPLIT") { - val split = """([\w+\.]+)(-[\w+\.]+)??""".r + val split = """([\w+\.]+)(-[\w+\.-]+)??""".r val split(b2, sOrNull) = b (b2, Option(sOrNull).map(_.drop(1)).getOrElse("")) } else (b, s) } - def executeTool(tool: String) = { - val cmd = - if (System.getProperty("os.name").toLowerCase.contains("windows")) - s"cmd.exe /c tools\\$tool.bat -p" - else s"tools/$tool" - Process(cmd).lines.head + val (dateObj, sha) = { + try { + // Use JGit to get the commit date and SHA + import org.eclipse.jgit.storage.file.FileRepositoryBuilder + import org.eclipse.jgit.revwalk.RevWalk + val db = new FileRepositoryBuilder().findGitDir.build + val head = db.resolve("HEAD") + if(head eq null) { + log.info("No git HEAD commit found -- Using current date and 'unknown' SHA") + (new Date, "unknown") + } else { + val commit = new RevWalk(db).parseCommit(head) + (new Date(commit.getCommitTime.toLong * 1000L), commit.getName.substring(0, 7)) + } + } catch { case ex: Exception => + log.error("Could not determine commit date + SHA: "+ex) + log.trace(ex) + (new Date, "unknown") + } + } + val date = { + val df = new SimpleDateFormat("yyyyMMdd-HHmmss", Locale.ENGLISH) + df.setTimeZone(TimeZone.getTimeZone("UTC")) + df.format(dateObj) } - - val date = executeTool("get-scala-commit-date") - val sha = executeTool("get-scala-commit-sha").substring(0, 7) // The script produces 10 digits at the moment val Patch = """\d+\.\d+\.(\d+)""".r def cross = base match { @@ -86,15 +110,15 @@ object VersionUtil { case _ => "pre" } - val (canonicalV, mavenV, osgiV, release) = suffix match { - case "SNAPSHOT" => (s"$base-$date-$sha", s"$base-$cross-SNAPSHOT", s"$base.v$date-$sha", false) - case "SHA-SNAPSHOT" => (s"$base-$date-$sha", s"$base-$cross-$sha-SNAPSHOT", s"$base.v$date-$sha", false) - case "SHA" => (s"$base-$sha", s"$base-$cross-$sha", s"$base.v$date-$sha", false) - case "" => (s"$base", s"$base", s"$base.v$date-VFINAL-$sha", true) - case suffix => (s"$base-$suffix", s"$base-$suffix", s"$base.v$date-$suffix-$sha", true) + val (canonicalV, mavenSuffix, osgiV, release) = suffix match { + case "SNAPSHOT" => (s"$base-$date-$sha", s"-$cross-SNAPSHOT", s"$base.v$date-$sha", false) + case "SHA-SNAPSHOT" => (s"$base-$date-$sha", s"-$cross-$sha-SNAPSHOT", s"$base.v$date-$sha", false) + case "SHA" => (s"$base-$sha", s"-$cross-$sha", s"$base.v$date-$sha", false) + case "" => (s"$base", "", s"$base.v$date-VFINAL-$sha", true) + case suffix => (s"$base-$suffix", s"-$suffix", s"$base.v$date-$suffix-$sha", true) } - Versions(canonicalV, mavenV, osgiV, sha, date, release) + Versions(canonicalV, base, mavenSuffix, osgiV, sha, date, release) } private lazy val generateVersionPropertiesFileImpl: Def.Initialize[Task[File]] = Def.task { @@ -103,7 +127,11 @@ object VersionUtil { } private lazy val generateBuildCharacterPropertiesFileImpl: Def.Initialize[Task[File]] = Def.task { - writeProps(versionProperties.value.toMap, (baseDirectory in ThisBuild).value / "buildcharacter.properties") + val v = versionProperties.value + writeProps(v.toMap ++ versionProps ++ Map( + "maven.version.base" -> v.mavenBase, + "maven.version.suffix" -> v.mavenSuffix + ), buildCharacterPropertiesFile.value) } private def writeProps(m: Map[String, String], propFile: File): File = { @@ -148,10 +176,10 @@ object VersionUtil { def bootstrapDep(baseDir: File, path: String, libName: String): ModuleID = { val sha = IO.read(baseDir / path / s"$libName.jar.desired.sha1").split(' ')(0) bootstrapOrganization(path) % libName % sha from - s"https://dl.bintray.com/typesafe/scala-sha-bootstrap/org/scala-lang/bootstrap/$sha/$path/$libName.jar" + s"https://repo.lightbend.com/typesafe/scala-sha-bootstrap/org/scala-lang/bootstrap/$sha/$path/$libName.jar" } - /** Copy a boostrap dependency JAR that is on the classpath to a file */ + /** Copy a bootstrap dependency JAR that is on the classpath to a file */ def copyBootstrapJar(cp: Seq[Attributed[File]], baseDir: File, path: String, libName: String): Unit = { val org = bootstrapOrganization(path) val resolved = cp.find { a => |