From 7780a3667f5f9977215eba80e483d90cbdcfbb94 Mon Sep 17 00:00:00 2001 From: Josh Suereth Date: Mon, 5 Dec 2011 10:12:44 -0500 Subject: Step one towards using project revision to build --- project/plugins.sbt | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 project/plugins.sbt (limited to 'project/plugins.sbt') diff --git a/project/plugins.sbt b/project/plugins.sbt new file mode 100644 index 0000000000..2dfee4b5c9 --- /dev/null +++ b/project/plugins.sbt @@ -0,0 +1,7 @@ +resolvers += Resolver.url("Typesafe nightlies", url("https://typesafe.artifactoryonline.com/typesafe/ivy-snapshots/"))(Resolver.ivyStylePatterns) + +resolvers += Resolver.url("scalasbt", new URL("http://scalasbt.artifactoryonline.com/scalasbt/sbt-plugin-releases"))(Resolver.ivyStylePatterns) + +resolvers += "jgit-repo" at "http://download.eclipse.org/jgit/maven" + + -- cgit v1.2.3 From 47fb0d381022bda800b7f8ee234224aa20020e4a Mon Sep 17 00:00:00 2001 From: Josh Suereth Date: Mon, 5 Dec 2011 15:52:10 -0500 Subject: Adding SHA resolve to the SBT build so that we don't need the push/pull binary libs script anymore. Only pull is implemented. --- project/Build.scala | 4 ++-- project/ShaResolve.scala | 57 ++++++++++++++++++++++++++++++++++++++++++++++++ project/plugins.sbt | 2 ++ 3 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 project/ShaResolve.scala (limited to 'project/plugins.sbt') diff --git a/project/Build.scala b/project/Build.scala index dd75b92734..6ffdffa005 100644 --- a/project/Build.scala +++ b/project/Build.scala @@ -141,7 +141,7 @@ object ScalaBuild extends Build with Layers { //commands += Release.setStarrHome ) // Note: Root project is determined by lowest-alphabetical project that has baseDirectory as file("."). we use aaa_ to 'win'. - lazy val aaa_root = Project("scala", file(".")) settings(projectSettings: _*) + lazy val aaa_root = Project("scala", file(".")) settings(projectSettings: _*) settings(ShaResolve.settings: _*) // External dependencies used for various projects lazy val externalDeps: Setting[_] = libraryDependencies <<= (sbtVersion)(v => @@ -206,7 +206,7 @@ object ScalaBuild extends Build with Layers { // Need a report on this... // TODO - Resolve STARR from a repo.. - lazy val STARR = scalaInstance <<= appConfiguration map { app => + lazy val STARR = scalaInstance <<= (appConfiguration, ShaResolve.pullBinaryLibs in ThisBuild) map { (app, _) => val launcher = app.provider.scalaProvider.launcher val library = file("lib/scala-library.jar") val compiler = file("lib/scala-compiler.jar") diff --git a/project/ShaResolve.scala b/project/ShaResolve.scala new file mode 100644 index 0000000000..2b7fafd576 --- /dev/null +++ b/project/ShaResolve.scala @@ -0,0 +1,57 @@ +import sbt._ + +import Build._ +import Keys._ +import Project.Initialize +import scala.collection.{ mutable, immutable } + + + + +/** Helpers to resolve SHA artifacts from typesafe repo. */ +object ShaResolve { + import dispatch.{Http,url} + val remote_urlbase="http://typesafe.artifactoryonline.com/typesafe/scala-sha-bootstrap/org/scala-lang/bootstrap" + + val pullBinaryLibs = TaskKey[Unit]("pull-binary-libs", "Pulls binary libs by the SHA key.") + val pushBinaryLibs = TaskKey[Unit]("push-binary-libs", "Pushes binary libs whose SHA has changed.") + + + def settings: Seq[Setting[_]] = Seq( + pullBinaryLibs in ThisBuild <<= (baseDirectory, streams) map resolveLibs + ) + + def resolveLibs(dir: File, s: TaskStreams): Unit = { + for { + (file, name) <- dir ** "*.desired.sha1" x relativeTo(dir) + uri = name.dropRight(13) + jar = dir / uri + if !jar.exists || !isValidSha(file) + sha = getShaFromShafile(file) + } pullFile(jar, sha + "/" + uri, s) + } + + def getShaFromShafile(file: File): String = (IO read file split "\\s" headOption) getOrElse error("No SHA found for " + file) + + + def isValidSha(file: File): Boolean = + try (Process(Seq("shasum", "-p", "--check", file.getAbsolutePath), Some(file.getParentFile)).!! contains "OK") + catch { + case t: Exception => false + } + + + def pullFile(file: File, uri: String, s: TaskStreams): Unit = { + val url = remote_urlbase + "/" + uri + val fous = new java.io.FileOutputStream(file) + s.log.info("Pulling [" + url + "] to [" + file + "]") + try Http(dispatch.url(url) >>> fous) finally fous.close() + } + + def pushFile(file: File, uri: String, user: String, pw: String): Unit = { + val url = remote_urlbase + "/" + uri + val sender = dispatch.url(url).PUT.as(user,pw) <<< (file, "application/java-archive") + // TODO - output to logger. + Http(sender >>> System.out) + } +} diff --git a/project/plugins.sbt b/project/plugins.sbt index 2dfee4b5c9..b49ece7527 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -4,4 +4,6 @@ resolvers += Resolver.url("scalasbt", new URL("http://scalasbt.artifactoryonline resolvers += "jgit-repo" at "http://download.eclipse.org/jgit/maven" +libraryDependencies += "net.databinder" %% "dispatch-http" % "0.8.6" + -- cgit v1.2.3