sbt/project/StatusPlugin.scala

52 lines
1.6 KiB
Scala
Raw Permalink Normal View History

2014-05-01 18:50:07 +02:00
import sbt._
import Keys._
2011-06-26 18:27:07 +02:00
object StatusPlugin extends AutoPlugin {
override def requires = plugins.JvmPlugin
override def trigger = allRequirements
2011-06-26 18:27:07 +02:00
object autoImport {
2015-04-20 18:50:11 +02:00
lazy val publishStatus = settingKey[String]("possible values are snapshots or releases.")
}
import autoImport._
override def buildSettings: Seq[Setting[_]] = Seq(
2015-04-20 18:50:11 +02:00
isSnapshot := {
val SnapshotQualifier = """(.+)(-.*SNAPSHOT)(.*)""".r
val v = version.value
v match {
case SnapshotQualifier(_, _, _) => true
case _ => false
}
},
publishStatus := {
if (isSnapshot.value) "snapshots"
else "releases"
},
2014-05-01 18:50:07 +02:00
commands += stampVersion
)
def stampVersion = Command.command("stamp-version") { state =>
val extracted = Project.extract(state)
val status = extracted.get(publishStatus)
// Set new version AND lock down the publishStatus to what it was, as
// our release regexes no longer support ivy data format, due to other issues.
extracted.append(
(version in ThisBuild ~= stamp) ::
(publishStatus in ThisBuild := status) ::
Nil,
state)
2014-05-01 18:50:07 +02:00
}
def stamp(v: String): String =
2015-04-20 18:50:11 +02:00
{
val Snapshot = "-SNAPSHOT"
if (v endsWith Snapshot) (v stripSuffix Snapshot) + "-" + timestampString(System.currentTimeMillis)
else sys.error("Release version '" + v + "' cannot be stamped")
}
2014-05-01 18:50:07 +02:00
def timestampString(time: Long): String =
{
val format = new java.text.SimpleDateFormat("yyyyMMdd-HHmmss")
format.format(new java.util.Date(time))
}
}