2014-05-01 18:50:07 +02:00
|
|
|
import sbt._
|
|
|
|
|
import Keys._
|
2014-12-03 18:56:34 +01:00
|
|
|
import Status.publishStatus
|
2014-05-01 18:50:07 +02:00
|
|
|
import org.apache.ivy.util.url.CredentialsStore
|
2014-07-31 01:52:59 +02:00
|
|
|
import com.typesafe.sbt.JavaVersionCheckPlugin.autoImport._
|
2014-05-01 18:50:07 +02:00
|
|
|
|
|
|
|
|
object Release extends Build {
|
|
|
|
|
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.")
|
2014-06-04 17:26:30 +02:00
|
|
|
lazy val checkCredentials = TaskKey[Unit]("checkCredentials", "Checks to ensure credentials for this user exists.")
|
2014-05-01 18:50:07 +02:00
|
|
|
|
|
|
|
|
val PublishRepoHost = "private-repo.typesafe.com"
|
|
|
|
|
|
|
|
|
|
def settings(nonRoots: => Seq[ProjectReference], launcher: TaskKey[File]): Seq[Setting[_]] =
|
2014-06-04 17:26:30 +02:00
|
|
|
releaseSettings(nonRoots, launcher)
|
2014-05-01 18:50:07 +02:00
|
|
|
|
2014-06-04 17:26:30 +02:00
|
|
|
// Add credentials if they exist.
|
|
|
|
|
def lameCredentialSettings: Seq[Setting[_]] =
|
2014-07-10 23:46:41 +02:00
|
|
|
if (CredentialsFile.exists) Seq(credentials in ThisBuild += Credentials(CredentialsFile))
|
2014-06-04 17:26:30 +02:00
|
|
|
else Nil
|
2014-05-01 18:50:07 +02:00
|
|
|
def releaseSettings(nonRoots: => Seq[ProjectReference], launcher: TaskKey[File]): Seq[Setting[_]] = Seq(
|
|
|
|
|
publishTo in ThisBuild <<= publishResolver,
|
|
|
|
|
remoteID <<= publishStatus("typesafe-ivy-" + _),
|
|
|
|
|
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,
|
2014-06-04 17:26:30 +02:00
|
|
|
deployLauncher <<= deployLauncher(launcher),
|
|
|
|
|
checkCredentials := {
|
|
|
|
|
// Note - This will eitehr issue a failure or succeed.
|
|
|
|
|
getCredentials(credentials.value, streams.value.log)
|
|
|
|
|
}
|
2014-07-31 21:18:39 +02:00
|
|
|
) ++ lameCredentialSettings ++ javaVersionCheckSettings
|
2014-05-01 18:50:07 +02:00
|
|
|
|
|
|
|
|
def snapshotPattern(version: String) = Resolver.localBasePattern.replaceAll("""\[revision\]""", version)
|
2014-08-04 17:08:29 +02:00
|
|
|
def publishResolver: Def.Initialize[Option[Resolver]] = (remoteID, remoteBase) { (id, base) =>
|
2014-05-01 18:50:07 +02:00
|
|
|
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]) =
|
|
|
|
|
(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
|
|
|
|
|
try { http(request.as_str) } finally { http.shutdown() }
|
|
|
|
|
()
|
|
|
|
|
}
|
|
|
|
|
def getCredentials(cs: Seq[Credentials], log: Logger): (String, String) =
|
|
|
|
|
{
|
|
|
|
|
Credentials.forHost(cs, PublishRepoHost) match {
|
|
|
|
|
case Some(creds) => (creds.userName, creds.passwd)
|
2014-10-10 21:42:26 +02:00
|
|
|
case None => sys.error("No credentials defined for " + PublishRepoHost)
|
2014-05-01 18:50:07 +02:00
|
|
|
}
|
|
|
|
|
}
|
2014-07-31 01:52:59 +02:00
|
|
|
|
|
|
|
|
def javaVersionCheckSettings = Seq(
|
|
|
|
|
javaVersionPrefix in javaVersionCheck := Some("1.6")
|
|
|
|
|
)
|
2011-07-09 22:54:41 +02:00
|
|
|
}
|