Skip to content

Commit

Permalink
Merge branch 'try/buildnumber'
Browse files Browse the repository at this point in the history
  • Loading branch information
eed3si9n committed Apr 16, 2012
2 parents 8d4ec7b + 479ca71 commit b311052
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/main/scala/sbtbuildinfo/Plugin.scala
Expand Up @@ -10,6 +10,7 @@ object Plugin extends sbt.Plugin {
lazy val buildInfoObject = SettingKey[String]("buildinfo-object")
lazy val buildInfoPackage = SettingKey[String]("buildinfo-package")
lazy val buildInfoKeys = SettingKey[Seq[Scoped]]("buildinfo-keys")
lazy val buildInfoBuildNumber = TaskKey[Int]("buildinfo-buildnumber")

case class BuildInfo(dir: File, obj: String, pkg: String, keys: Seq[Scoped],
proj: ProjectRef, state0: State) {
Expand Down Expand Up @@ -70,6 +71,24 @@ object Plugin extends sbt.Plugin {
}
}

private[this] def buildNumberTask(dir: File): Int = {
val file: File = dir / "buildinfo.properties"
val prop = new java.util.Properties

def readProp: Int = {
prop.load(new java.io.FileInputStream(file))
prop.getProperty("buildnumber", "0").toInt
}
def writeProp(value: Int) {
prop.setProperty("buildnumber", value.toString)
prop.store(new java.io.FileOutputStream(file), null)
}
val current = if (file.exists) readProp
else 0
writeProp(current + 1)
current
}

lazy val buildInfoSettings: Seq[Project.Setting[_]] = Seq(
buildInfo <<= (sourceManaged in Compile,
buildInfoObject, buildInfoPackage, buildInfoKeys, thisProjectRef, state) map {
Expand All @@ -78,6 +97,7 @@ object Plugin extends sbt.Plugin {
},
buildInfoObject := "BuildInfo",
buildInfoPackage := "buildinfo",
buildInfoKeys := Seq[Scoped](name, version, scalaVersion, sbtVersion)
buildInfoKeys := Seq[Scoped](name, version, scalaVersion, sbtVersion),
buildInfoBuildNumber <<= (baseDirectory) map { (dir) => buildNumberTask(dir) }
)
}

0 comments on commit b311052

Please sign in to comment.