-
Notifications
You must be signed in to change notification settings - Fork 3
/
in
executable file
·42 lines (33 loc) · 1.48 KB
/
in
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env bash
set -euo pipefail
exec 3>&1 # make stdout available as fd 3 for the result
exec 1>&2 # redirect all output to stderr for logging
destination=$1
if [ -z "$destination" ]; then
echo "usage: $0 <path/to/destination>"
exit 1
fi
payload=$(mktemp /tmp/maven-cache-resource-in.XXXXXX)
cat > $payload <&0
# Parse URLs for settings.xml and settings-security.xml
settings_url=$(jq -r '.source.settings.url // ""' < $payload)
master_password=$(jq -r '.source."master-password" // ""' < $payload)
# Download settings.xml file if specified
if [[ -n "$settings_url" ]]; then
wget -q -t 3 -T 60 -O '/usr/share/maven/conf/settings.xml' "$settings_url"
cp -f /usr/share/maven/conf/settings.xml "$destination/settings.xml"
fi
# Write master password to settings-security.xml if specified
if [[ -n "$master_password" ]]; then
mkdir -p /root/.m2/
echo "<settingsSecurity><master>$master_password</master></settingsSecurity>" > /root/.m2/settings-security.xml
fi
# Forward request to the git resource to clone the source git repo
git_dir="$(mktemp -d -t git-resource-destination.XXXXXX)"
/opt/resource/git/in "$git_dir" < $payload >&3
# Check for pom.xml
cd "$git_dir"
[[ -f pom.xml ]] || { echo "There is no pom.xml in the git repo."; exit 1; }
# Use maven dependency plugin to cache dependencies
mvn -Dmaven.repo.local="$destination" -B --fail-never dependency:go-offline -DexcludeReactor=false
echo Downloaded $(du -hs $destination | cut -f1) in $(find $destination -type f | wc -l) files.