2011-06-26 18:27:07 +02:00
|
|
|
import sbt._
|
|
|
|
|
import Keys._
|
|
|
|
|
import Status.{isSnapshot, publishStatus}
|
|
|
|
|
import org.apache.ivy.util.url.CredentialsStore
|
|
|
|
|
|
2011-07-09 22:54:41 +02:00
|
|
|
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")
|
2013-06-20 20:28:05 +02:00
|
|
|
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-07-09 22:54:41 +02:00
|
|
|
|
2011-06-26 18:27:07 +02:00
|
|
|
|
2012-12-31 17:30:36 +01:00
|
|
|
val PublishRepoHost = "typesafe.artifactoryonline.com"
|
|
|
|
|
|
2011-06-26 18:27:07 +02:00
|
|
|
def settings(nonRoots: => Seq[ProjectReference], launcher: ScopedTask[File]): Seq[Setting[_]] =
|
2013-06-20 20:28:05 +02:00
|
|
|
if(CredentialsFile.exists) releaseSettings(nonRoots, launcher) else Nil
|
2011-06-26 18:27:07 +02:00
|
|
|
|
|
|
|
|
def releaseSettings(nonRoots: => Seq[ProjectReference], launcher: ScopedTask[File]): Seq[Setting[_]] = Seq(
|
|
|
|
|
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-" + _ ),
|
2013-06-20 20:28:05 +02:00
|
|
|
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
|
|
|
)
|
2013-06-20 20:28:05 +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
|
2011-06-26 18:27:07 +02:00
|
|
|
def deployLauncher(launcher: ScopedTask[File]) =
|
|
|
|
|
(launcher, launcherRemotePath, credentials, remoteBase, streams) map { (launchJar, remotePath, creds, base, s) =>
|
|
|
|
|
val (uname, pwd) = getCredentials(creds, s.log)
|
2013-06-20 20:28:05 +02:00
|
|
|
val request = dispatch.classic.url(base) / remotePath <<< (launchJar, "binary/octet-stream") as (uname, pwd)
|
2013-02-13 21:03:31 +01:00
|
|
|
val http = new dispatch.classic.Http
|
2011-06-26 18:27:07 +02:00
|
|
|
try { http(request.as_str) } finally { http.shutdown() }
|
2013-06-20 20:28:05 +02:00
|
|
|
()
|
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
|
|
|
}
|
2011-07-09 22:54:41 +02:00
|
|
|
}
|