Skip to content

Commit fc8b28d

Browse files
committed
melting-pot.sh: cache downloaded source code
So we don't hammer GitHub over and over...
1 parent f58cec9 commit fc8b28d

1 file changed

Lines changed: 23 additions & 6 deletions

File tree

melting-pot.sh

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@
7070
# Author: Curtis Rueden
7171
# ============================================================================
7272

73+
# -- Constants --
74+
75+
meltingPotCache="$HOME/.scijava/melting-pot"
76+
7377
# -- Functions --
7478

7579
stderr() { >&2 echo "$@"; }
@@ -423,18 +427,31 @@ retrieveSource() {
423427
test "$scmURL" || die "Cannot glean SCM URL for $1" 10
424428
local scmBranch
425429
test "$2" && scmBranch="$2" || scmBranch="$(scmTag "$1")"
426-
local dir="$(groupId "$1")/$(artifactId "$1")"
427-
debug "git clone \"$scmURL\" --branch \"$scmBranch\" --depth 1 \"$dir\""
428-
git clone "$scmURL" --branch "$scmBranch" --depth 1 "$dir" 2> /dev/null ||
429-
die "Could not fetch project source for $1" 3
430+
local g=$(groupId "$1")
431+
local a=$(artifactId "$1")
432+
local v=$(version "$1")
433+
local sourceDir="$meltingPotCache/$g/$a/$v"
434+
if [ -d "$sourceDir" ]
435+
then
436+
debug "Using previously fetched project source at $sourceDir"
437+
else
438+
# Source has never been fetched before. Save it into ~/.scijava/melting-pot.
439+
debug "git clone \"$scmURL\" --branch \"$scmBranch\" --depth 1 \"$sourceDir\""
440+
git clone "$scmURL" --branch "$scmBranch" --depth 1 "$sourceDir" 2> /dev/null ||
441+
die "Could not fetch project source for $1" 3
442+
fi
443+
# Copy the pristine cached source directory into the melting-pot structure.
444+
local destDir="$g/$a"
445+
mkdir -p "$(dirname "$destDir")"
446+
cp -rp "$sourceDir" "$destDir"
430447

431448
# Now verify that the cloned pom.xml contains the expected version!
432449
local expectedVersion=$(version "$1")
433-
local actualVersion=$(xpath "$dir/pom.xml" project version)
450+
local actualVersion=$(xpath "$destDir/pom.xml" project version)
434451
test "$expectedVersion" = "$actualVersion" ||
435452
die "POM for $1 contains wrong version: $actualVersion" 14
436453

437-
echo "$dir"
454+
echo "$destDir"
438455
}
439456

440457
# Gets the list of dependencies for the project in the CWD.

0 commit comments

Comments
 (0)