summaryrefslogtreecommitdiff
path: root/project
diff options
context:
space:
mode:
authorSeth Tisue <seth@tisue.net>2017-03-07 10:26:38 -0800
committerGitHub <noreply@github.com>2017-03-07 10:26:38 -0800
commit567aa14cc388c7315dc0d15405d6c583bfe3f3d7 (patch)
tree447f3ce3dc429b3dbdf300d9cdc42f984be1930d /project
parentee5ca5da03590844889c4c2d20bc711165bba2aa (diff)
parent992a1135836dadb9494bdaa7c0363dffc3b965c8 (diff)
downloadscala-567aa14cc388c7315dc0d15405d6c583bfe3f3d7.tar.gz
scala-567aa14cc388c7315dc0d15405d6c583bfe3f3d7.tar.bz2
scala-567aa14cc388c7315dc0d15405d6c583bfe3f3d7.zip
Merge pull request #5733 from szeiger/wip/use-jgit
Get commit SHA and date with JGit
Diffstat (limited to 'project')
-rw-r--r--project/VersionUtil.scala38
-rw-r--r--project/plugins.sbt5
2 files changed, 33 insertions, 10 deletions
diff --git a/project/VersionUtil.scala b/project/VersionUtil.scala
index ebc2488345..6215d54c59 100644
--- a/project/VersionUtil.scala
+++ b/project/VersionUtil.scala
@@ -2,8 +2,10 @@ 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._
@@ -64,6 +66,7 @@ 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)
@@ -74,16 +77,31 @@ object VersionUtil {
} 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)
val (canonicalV, mavenSuffix, osgiV, release) = suffix match {
case "SNAPSHOT" => (s"$base-$date-$sha", s"-SNAPSHOT", s"$base.v$date-$sha", false)
diff --git a/project/plugins.sbt b/project/plugins.sbt
index ca80c88a9e..58e2d6cdad 100644
--- a/project/plugins.sbt
+++ b/project/plugins.sbt
@@ -21,6 +21,11 @@ buildInfoPackage := "scalabuild"
libraryDependencies += "com.typesafe" %% "mima-reporter" % "0.1.13"
+libraryDependencies ++= Seq(
+ "org.eclipse.jgit" % "org.eclipse.jgit" % "4.6.0.201612231935-r",
+ "org.slf4j" % "slf4j-nop" % "1.7.23"
+)
+
concurrentRestrictions in Global := Seq(
Tags.limitAll(1) // workaround for https://github.com/sbt/sbt/issues/2970
)