summaryrefslogtreecommitdiff
path: root/project
diff options
context:
space:
mode:
authorJosh Suereth <joshua.suereth@gmail.com>2011-12-08 14:05:56 -0500
committerJosh Suereth <joshua.suereth@gmail.com>2011-12-08 14:05:56 -0500
commit16ad68fa3aa5d1ccd55865c3d06fec142cf9d630 (patch)
tree442c49eab01e130f4f37f8c67a1bfb3608f74c2b /project
parentbb89d62826df72559eed37ffdfb61935b3d14c6d (diff)
downloadscala-16ad68fa3aa5d1ccd55865c3d06fec142cf9d630.tar.gz
scala-16ad68fa3aa5d1ccd55865c3d06fec142cf9d630.tar.bz2
scala-16ad68fa3aa5d1ccd55865c3d06fec142cf9d630.zip
Added local cache for project jars.
.desired.sha1 files now resolve into a local repository before being copied into the main repo. If the local repository exists and has a file, then there is no download necessary.
Diffstat (limited to 'project')
-rw-r--r--project/ShaResolve.scala28
1 files changed, 18 insertions, 10 deletions
diff --git a/project/ShaResolve.scala b/project/ShaResolve.scala
index 2b7fafd576..4d9579b07d 100644
--- a/project/ShaResolve.scala
+++ b/project/ShaResolve.scala
@@ -12,23 +12,24 @@ import scala.collection.{ mutable, immutable }
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.")
-
+ val binaryLibCache = SettingKey[File]("binary-lib-cache", "Location of the cache of binary libs for this scala build.")
def settings: Seq[Setting[_]] = Seq(
- pullBinaryLibs in ThisBuild <<= (baseDirectory, streams) map resolveLibs
+ binaryLibCache in ThisBuild := file(System.getProperty("user.home")) / ".sbt" / "cache" / "scala",
+ pullBinaryLibs in ThisBuild <<= (baseDirectory, binaryLibCache, streams) map resolveLibs
)
- def resolveLibs(dir: File, s: TaskStreams): Unit = {
+ def resolveLibs(dir: File, cacheDir: 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)
+ } pullFile(jar, sha + "/" + uri, cacheDir, s)
}
def getShaFromShafile(file: File): String = (IO read file split "\\s" headOption) getOrElse error("No SHA found for " + file)
@@ -41,11 +42,18 @@ object ShaResolve {
}
- 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 pullFile(file: File, uri: String, cacheDir: File, s: TaskStreams): Unit = {
+ val cachedFile = cacheDir / uri
+ if (!cachedFile.exists) {
+ // Ensure the directory for the cache exists.
+ cachedFile.getParentFile.mkdirs()
+ val url = remote_urlbase + "/" + uri
+ val fous = new java.io.FileOutputStream(cachedFile)
+ s.log.info("Pulling [" + cachedFile + "] to cache")
+ try Http(dispatch.url(url) >>> fous) finally fous.close()
+ }
+ s.log.info("Pulling [" + file + "] from local cache")
+ IO.copyFile(cachedFile, file)
}
def pushFile(file: File, uri: String, user: String, pw: String): Unit = {