From c94d342b385fa510882721b8b7f2070750c60f0e Mon Sep 17 00:00:00 2001 From: Josh Suereth Date: Wed, 25 Jan 2012 21:33:59 -0500 Subject: Added caching to binary resolution. * Duplicated binary repo cache in ~/.sbt/cache/scala/ * Resolved to cache before copying to local dir if jar is misisng * Does *not* check SHA in cache currently --- tools/binary-repo-lib.sh | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/tools/binary-repo-lib.sh b/tools/binary-repo-lib.sh index 4221e3205c..3a75593f21 100755 --- a/tools/binary-repo-lib.sh +++ b/tools/binary-repo-lib.sh @@ -7,6 +7,8 @@ remote_urlbase="http://typesafe.artifactoryonline.com/typesafe/scala-sha-bootstr libraryJar="$(pwd)/lib/scala-library.jar" desired_ext=".desired.sha1" push_jar="$(pwd)/tools/push.jar" +# Cache dir has .sbt in it to line up with SBT build. +cache_dir="${HOME}/.sbt/cache/scala" # Checks whether or not curl is installed and issues a warning on failure. checkCurl() { @@ -126,6 +128,25 @@ pushJarFiles() { else echo "Binary changes have been pushed. You may now submit the new *${desired_ext} files to git." fi +} + +# Pulls a single binary artifact from a remote repository. +# Argument 1 - The uri to the file that should be downloaded. +# Argument 2 - SHA of the file... +# Returns: Cache location. +pullJarFileToCache() { + local uri=$1 + local sha=$2 + local cache_loc=$cache_dir/$uri + local cdir=$(dirname $cache_loc) + if [[ ! -d $cdir ]]; then + mkdir -p $cdir + fi + # TODO - Check SHA of local cache is accurate. + if [[ ! -f $cache_loc ]]; then + curlDownload $cache_loc ${remote_urlbase}/${uri} + fi + echo "$cache_loc" } # Pulls a single binary artifact from a remote repository. @@ -139,8 +160,9 @@ pullJarFile() { local jar_name=${jar#$jar_dir/} local version=${sha1% ?$jar_name} local remote_uri=${version}/${jar#$basedir/} - echo "Downloading from ${remote_urlbase}/${remote_uri}" - curlDownload $jar ${remote_urlbase}/${remote_uri} + echo "Resolving [${remote_uri}]" + local cached_file=$(pullJarFileToCache $remote_uri $version) + cp $cached_file $jar } # Pulls binary artifacts from the remote repository. @@ -152,7 +174,6 @@ pullJarFiles() { jar=${sha%$desired_ext} local valid=$(isJarFileValid $jar) if [[ "$valid" != "OK" ]]; then - echo "Obtaining [$jar] from binary repository..." pullJarFile $jar $basedir fi done -- cgit v1.2.3