package akka import sbt._ import sbt.Keys._ import sbt.Project.Initialize import java.io.File object Publish { final val Snapshot = "-SNAPSHOT" val defaultPublishTo = SettingKey[File]("default-publish-to") lazy val settings = Seq( crossPaths := false, pomExtra := akkaPomExtra, publishTo <<= akkaPublishTo, credentials ++= akkaCredentials, organizationName := "Typesafe Inc.", organizationHomepage := Some(url("http://www.typesafe.com")), publishMavenStyle := true, // Maven central cannot allow other repos. // TODO - Make sure all artifacts are on central. pomIncludeRepository := { x => false } ) lazy val versionSettings = Seq( commands += stampVersion ) def akkaPomExtra = { (2009 http://akka.io Apache 2 http://www.apache.org/licenses/LICENSE-2.0.txt repo git://github.com/akka/akka.git scm:git:git@github.com:akka/akka.git ) ++ makeDevelopersXml(Map( "jboner" -> "Jonas Boner", "viktorklang" -> "Viktor Klang", "rkuhn" -> "Roland Kuhn", "pvlugter" -> "Peter Vlugter" // TODO - More than the names in the last 10 commits )) } private[this] def makeDevelopersXml(users: Map[String,String]) = { for((id, user) <- users) yield {id}{user} } def sonatypePublishTo: Initialize[Option[Resolver]] = { version { v: String => val nexus = "https://oss.sonatype.org/" if (v.trim.endsWith("SNAPSHOT")) Some("snapshots" at nexus + "content/repositories/snapshots") else Some("releases" at nexus + "service/local/staging/deploy/maven2") } } 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)) } } def akkaCredentials: Seq[Credentials] = { val property = Option(System.getProperty("akka.publish.credentials")) property map (f => Credentials(new File(f))) toSeq } // timestamped versions def stampVersion = Command.command("stamp-version") { state => val extracted = Project.extract(state) extracted.append(List(version in ThisBuild ~= stamp), state) } 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)) } }