Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Step one towards using project revision to build

  • Loading branch information...
commit 7780a3667f5f9977215eba80e483d90cbdcfbb94 1 parent 1ed57a4
Josh Suereth authored December 05, 2011
6  project/Layers.scala
... ...
@@ -1,5 +1,7 @@
1 1
 import sbt._
2 2
 import Keys._
  3
+import com.jsuereth.git.GitKeys.gitRunner
  4
+
3 5
 /** This trait stores all the helper methods to generate layers in Scala's layered build. */
4 6
 trait Layers extends Build {
5 7
   // TODO - Clean this up or use a self-type.
@@ -57,7 +59,7 @@ trait Layers extends Build {
57 59
           // TODO - Allow other scalac option settings.
58 60
           scalacOptions in Compile <++= (scalaSource in Compile) map (src => Seq("-sourcepath", src.getAbsolutePath)),
59 61
           classpathOptions := ClasspathOptions.manual,
60  
-          resourceGenerators in Compile <+= (baseDirectory, version, resourceManaged) map Release.generatePropertiesFile("library.properties"),
  62
+          resourceGenerators in Compile <+= (baseDirectory, version, resourceManaged, gitRunner) map Release.generatePropertiesFile("library.properties"),
61 63
           referenceScala
62 64
       )) :_*)
63 65
 
@@ -67,7 +69,7 @@ trait Layers extends Build {
67 69
         scalaSource in Compile <<= (baseDirectory) apply (_ / "src" / "compiler"),
68 70
         resourceDirectory in Compile <<= baseDirectory apply (_ / "src" / "compiler"),
69 71
         defaultExcludes in unmanagedResources := "*.scala",
70  
-        resourceGenerators in Compile <+= (baseDirectory, version, resourceManaged) map Release.generatePropertiesFile("compiler.properties"),
  72
+        resourceGenerators in Compile <+= (baseDirectory, version, resourceManaged, gitRunner) map Release.generatePropertiesFile("compiler.properties"),
71 73
         // Note, we might be able to use the default task, but for some reason ant was filtering files out.  Not sure what's up, but we'll
72 74
         // stick with that for now.
73 75
         unmanagedResources in Compile <<= (baseDirectory) map {
29  project/Release.scala
... ...
@@ -1,5 +1,6 @@
1 1
 import sbt._
2 2
 import Keys._
  3
+import _root_.com.jsuereth.git.GitRunner
3 4
 
4 5
 object Release {
5 6
 
@@ -65,15 +66,11 @@ object Release {
65 66
 
66 67
   /** This generates a  properties file, if it does not already exist, with the maximum lastmodified timestamp
67 68
     * of any source file. */
68  
-  def generatePropertiesFile(name: String)(baseDirectory: File, version: String, dir: File): Seq[File] = {
  69
+  def generatePropertiesFile(name: String)(baseDirectory: File, version: String, dir: File, git: GitRunner): Seq[File] = {
69 70
     val target = dir / name
70 71
     // TODO - Regenerate on triggers, like recompilation or something...
71  
-    // TODO - also think about pulling git last-commit for this...
72 72
     if (!target.exists) {
73  
-      val ts = getLastModified(baseDirectory)
74  
-      val formatter = new java.text.SimpleDateFormat("yyyyMMdd'T'HHmmss")
75  
-      formatter.setTimeZone(java.util.TimeZone.getTimeZone("GMT"))
76  
-      val fullVersion = version + "." + formatter.format(new java.util.Date(ts))
  73
+      val fullVersion = makeFullVersionString(baseDirectory, version, git)
77 74
       makePropertiesFile(target, fullVersion)
78 75
     }
79 76
     target :: Nil
@@ -83,12 +80,22 @@ object Release {
83 80
   def makePropertiesFile(f: File, version: String): Unit =
84 81
     IO.write(f, "version.number = "+version+"\ncopyright.string = Copyright 2002-2011, LAMP/EPFL")
85 82
 
86  
-  def makeFullVersionString(baseDirectory: File, baseVersion: String) = baseVersion+"."+getLastModified(baseDirectory)
  83
+  def makeFullVersionString(baseDirectory: File, baseVersion: String, git: GitRunner) = baseVersion+"."+getGitRevision(baseDirectory, git)+"."+currentDay
87 84
 
88  
-  // TODO - Something that doesn't take so long...
89  
-  def allSourceFiles(baseDirectory: File) = (baseDirectory / "src") ** ("*.scala" | "*.java" )
  85
+  // TODO - do we want this in the build number?
  86
+  def currentDay = (new java.text.SimpleDateFormat("yyyyMMdd'T'HHmmss")) format (new java.util.Date)
90 87
 
91  
-  def getLastModified(baseDirectory: File) =
92  
-    allSourceFiles(baseDirectory).get.map(_.lastModified).max
  88
+  def getGitRevision(baseDirectory: File, git: GitRunner) = {
  89
+    object outputStealer extends sbt.Logger {
  90
+      private val stdout = new StringBuilder
  91
+      private val stderr = new StringBuilder
  92
+      def log (level: Level.Value, message: ⇒ String): Unit = stdout append message
  93
+      def success (message: ⇒ String): Unit = ()
  94
+      def trace (t: ⇒ Throwable): Unit = ()
  95
+      def stdoutString = stdout.toString
  96
+    }
  97
+    git("describe", "HEAD", "--abbrev=7", "--match", "dev")(baseDirectory, outputStealer)
  98
+    outputStealer.stdoutString
  99
+  }
93 100
   
94 101
 }
7  project/plugins.sbt
... ...
@@ -0,0 +1,7 @@
  1
+resolvers += Resolver.url("Typesafe nightlies", url("https://typesafe.artifactoryonline.com/typesafe/ivy-snapshots/"))(Resolver.ivyStylePatterns)
  2
+
  3
+resolvers += Resolver.url("scalasbt", new URL("http://scalasbt.artifactoryonline.com/scalasbt/sbt-plugin-releases"))(Resolver.ivyStylePatterns)
  4
+
  5
+resolvers += "jgit-repo" at "http://download.eclipse.org/jgit/maven"
  6
+
  7
+
2  project/plugins/build.sbt
... ...
@@ -1,2 +0,0 @@
1  
-resolvers += Resolver.url("Typesafe nightlies", url("https://typesafe.artifactoryonline.com/typesafe/ivy-snapshots/"))(Resolver.ivyStylePatterns)
2  
-
4  project/plugins/project/Build.scala → project/project/Build.scala
... ...
@@ -1,7 +1,7 @@
1 1
 import sbt._
2 2
 object PluginDef extends Build {
3 3
   override def projects = Seq(root)
4  
-  lazy val root = Project("plugins", file(".")) dependsOn(proguard)
  4
+  lazy val root = Project("plugins", file(".")) dependsOn(proguard, git)
5 5
   lazy val proguard = uri("git://github.com/jsuereth/xsbt-proguard-plugin.git")
6  
-  //lazy val proguard = uri("git://github.com/siasia/xsbt-proguard-plugin.git")
  6
+  lazy val git = uri("git://github.com/sbt/sbt-git-plugin.git")
7 7
 }

0 notes on commit 7780a36

Please sign in to comment.
Something went wrong with that request. Please try again.