blob: 8430539c71fa62d2f8b84810e6d26a874553bc06 [file] [log] [blame]
Nicolas De Loofdfe81a32016-05-28 17:26:01 +02001#! /bin/bash
Nicolas De Loof0ef5a622016-05-27 19:14:29 +02002
3function download() {
4 plugin=$1
5
6 if [[ ! -f ${plugin}.hpi ]]; then
7
8 url=http://updates.jenkins-ci.org/latest/${plugin}.hpi
9 echo "download plugin : $plugin from $url"
10
11 curl -s -f -L $url -o ${plugin}.hpi
12 if [[ $? -ne 0 ]]
13 then
14 >&2 echo "failed to download plugin ${plugin}"
15 exit -1
16 fi
17 else
Baptiste Mathus0e7eac32016-05-29 16:14:40 +020018 echo "$plugin is already downloaded."
Nicolas De Loof0ef5a622016-05-27 19:14:29 +020019 fi
Nicolas De Loofa7a34c32016-05-30 09:10:58 +020020
21 if [[ ! -f ${plugin}.resolved ]]; then
22 resolveDependencies $1
23 fi
Nicolas De Loof0ef5a622016-05-27 19:14:29 +020024}
25
26function resolveDependencies() {
27 plugin=$1
28
Nicolas De Loofdfe81a32016-05-28 17:26:01 +020029 dependencies=`jrunscript -e '\
30 java.lang.System.out.println(\
31 new java.util.jar.JarFile("'${plugin}.hpi'")\
32 .getManifest()\
33 .getMainAttributes()\
34 .getValue("Plugin-Dependencies")\
35 );'`
Nicolas De Loof0ef5a622016-05-27 19:14:29 +020036
37 if [[ "$dependencies" == "null" ]]; then
Nicolas De Loofdfe81a32016-05-28 17:26:01 +020038 echo " > plugin has no dependencies"
Nicolas De Loof0ef5a622016-05-27 19:14:29 +020039 return
40 fi
41
42 echo " > depends on ${dependencies}"
43
44 IFS=',' read -a array <<< "${dependencies}"
45
46 for d in "${array[@]}"
47 do
48 plugin=$(echo $d | cut -d':' -f1 -)
49 if [[ $d == *"resolution:=optional"* ]]
50 then
51 echo "skipping optional dependency $plugin"
52 else
53 download $plugin
54 fi
55 done
Nicolas De Loofa7a34c32016-05-30 09:10:58 +020056 touch ${plugin}.resolved
Nicolas De Loof0ef5a622016-05-27 19:14:29 +020057}
58
59
Nicolas De Loofdfe81a32016-05-28 17:26:01 +020060shift
61for plugin in "$@"
62do
63 download $plugin
64done
Nicolas De Loofa7a34c32016-05-30 09:10:58 +020065
66# cleanup 'resolved' flag files
67rm *.resolved