pekko/project/Publish.scala

68 lines
1.8 KiB
Scala
Raw Normal View History

2011-09-23 10:21:03 +02:00
package akka
2011-07-08 18:01:19 +12:00
import sbt._
2011-12-09 21:55:49 +13:00
import sbt.Keys._
import sbt.Project.Initialize
2011-07-08 18:01:19 +12:00
import java.io.File
object Publish {
final val Snapshot = "-SNAPSHOT"
2011-12-09 21:55:49 +13:00
val defaultPublishTo = SettingKey[File]("default-publish-to")
2011-07-08 18:01:19 +12:00
lazy val settings = Seq(
crossPaths := false,
pomExtra := akkaPomExtra,
2011-12-09 21:55:49 +13:00
publishTo <<= akkaPublishTo,
credentials ++= akkaCredentials,
organizationName := "Typesafe Inc.",
organizationHomepage := Some(url("http://www.typesafe.com"))
2011-07-08 18:01:19 +12:00
)
lazy val versionSettings = Seq(
commands += stampVersion
)
def akkaPomExtra = {
<inceptionYear>2009</inceptionYear>
<url>http://akka.io</url>
<licenses>
<license>
<name>Apache 2</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>
}
2011-12-09 21:55:49 +13:00
def akkaPublishTo: Initialize[Option[Resolver]] = {
defaultPublishTo { default =>
val property = Option(System.getProperty("akka.publish.repository"))
val repo = property map { "Akka Publish Repository" at _ }
repo orElse Some(Resolver.file("Default Local Repository", default))
}
2011-07-08 18:01:19 +12:00
}
def akkaCredentials: Seq[Credentials] = {
val property = Option(System.getProperty("akka.publish.credentials"))
property map (f => Credentials(new File(f))) toSeq
}
2011-12-09 21:55:49 +13:00
// timestamped versions
2011-07-08 18:01:19 +12:00
2011-12-09 21:55:49 +13:00
def stampVersion = Command.command("stamp-version") { state =>
2011-07-08 18:01:19 +12:00
val extracted = Project.extract(state)
2011-12-09 21:55:49 +13:00
extracted.append(List(version in ThisBuild ~= stamp), state)
2011-07-08 18:01:19 +12:00
}
def stamp(version: String): String = {
if (version endsWith Snapshot) (version stripSuffix Snapshot) + "-" + timestamp(System.currentTimeMillis)
else version
}
def timestamp(time: Long): String = {
val format = new java.text.SimpleDateFormat("yyyyMMdd-HHmmss")
format.format(new java.util.Date(time))
}
}