sbt/project/Release.scala

55 lines
2.5 KiB
Scala
Raw Normal View History

2011-06-26 18:27:07 +02:00
import sbt._
import Keys._
import Status.{isSnapshot, publishStatus}
import org.apache.ivy.util.url.CredentialsStore
object Release extends Build
2011-06-26 18:27:07 +02:00
{
lazy val remoteBase = SettingKey[String]("remote-base")
lazy val remoteID = SettingKey[String]("remote-id")
lazy val launcherRemotePath = SettingKey[String]("launcher-remote-path")
lazy val deployLauncher = TaskKey[Unit]("deploy-launcher", "Upload the launcher to its traditional location for compatibility with existing scripts.")
2011-06-26 18:27:07 +02:00
val PublishRepoHost = "private-repo.typesafe.com"
2012-12-31 17:30:36 +01:00
def settings(nonRoots: => Seq[ProjectReference], launcher: TaskKey[File]): Seq[Setting[_]] =
if(CredentialsFile.exists) releaseSettings(nonRoots, launcher) else Nil
2011-06-26 18:27:07 +02:00
def releaseSettings(nonRoots: => Seq[ProjectReference], launcher: TaskKey[File]): Seq[Setting[_]] = Seq(
2011-06-26 18:27:07 +02:00
publishTo in ThisBuild <<= publishResolver,
remoteID <<= publishStatus("typesafe-ivy-" + _),
2012-12-31 17:30:36 +01:00
credentials in ThisBuild += Credentials(CredentialsFile),
remoteBase <<= publishStatus( "https://" + PublishRepoHost + "/typesafe/ivy-" + _ ),
launcherRemotePath <<= (organization, version, moduleName) { (org, v, n) => List(org, n, v, n + ".jar").mkString("/") },
publish <<= Seq(publish, Release.deployLauncher).dependOn,
deployLauncher <<= deployLauncher(launcher)
2011-06-26 18:27:07 +02:00
)
def snapshotPattern(version: String) = Resolver.localBasePattern.replaceAll("""\[revision\]""", version)
def publishResolver: Project.Initialize[Option[Resolver]] = (remoteID, remoteBase) { (id, base) =>
Some( Resolver.url("publish-" + id, url(base))(Resolver.ivyStylePatterns) )
}
lazy val CredentialsFile: File = Path.userHome / ".ivy2" / ".typesafe-credentials"
// this is no longer strictly necessary, since the launcher is now published as normal
// however, existing scripts expect the launcher to be in a certain place and normal publishing adds "jars/"
// to the published path
def deployLauncher(launcher: TaskKey[File]) =
2011-06-26 18:27:07 +02:00
(launcher, launcherRemotePath, credentials, remoteBase, streams) map { (launchJar, remotePath, creds, base, s) =>
val (uname, pwd) = getCredentials(creds, s.log)
val request = dispatch.classic.url(base) / remotePath <<< (launchJar, "binary/octet-stream") as (uname, pwd)
val http = new dispatch.classic.Http
2011-06-26 18:27:07 +02:00
try { http(request.as_str) } finally { http.shutdown() }
()
2011-06-26 18:27:07 +02:00
}
def getCredentials(cs: Seq[Credentials], log: Logger): (String, String) =
{
2012-12-31 17:30:36 +01:00
Credentials.forHost(cs, PublishRepoHost) match {
case Some(creds) => (creds.userName, creds.passwd)
case None => error("No credentials defined for " + PublishRepoHost)
}
2011-06-26 18:27:07 +02:00
}
}