blob: e6e0d4e950da6cf292e69473bfda3617419fbe76 [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() {
Nicolas De Loof4675f042016-06-01 14:07:33 +02004 local plugin=$1; shift
Nicolas De Loof0ef5a622016-05-27 19:14:29 +02005
6 if [[ ! -f ${plugin}.hpi ]]; then
7
Nicolas De Loof4675f042016-06-01 14:07:33 +02008 url=${JENKINS_UC}/latest/${plugin}.hpi
Nicolas De Loof0ef5a622016-05-27 19:14:29 +02009 echo "download plugin : $plugin from $url"
10
11 curl -s -f -L $url -o ${plugin}.hpi
12 if [[ $? -ne 0 ]]
13 then
Nicolas De Loof4675f042016-06-01 14:07:33 +020014 # some plugin don't follow the rules about artifact ID
15 # typically: docker-plugin
16 curl -s -f -L $url -o ${plugin}-plugin.hpi
17 if [[ $? -ne 0 ]]
18 then
19 >&2 echo "failed to download plugin ${plugin}"
20 exit -1
21 fi
Nicolas De Loof0ef5a622016-05-27 19:14:29 +020022 fi
23 else
Baptiste Mathus0e7eac32016-05-29 16:14:40 +020024 echo "$plugin is already downloaded."
Nicolas De Loof0ef5a622016-05-27 19:14:29 +020025 fi
Nicolas De Loofa7a34c32016-05-30 09:10:58 +020026
27 if [[ ! -f ${plugin}.resolved ]]; then
28 resolveDependencies $1
29 fi
Nicolas De Loof0ef5a622016-05-27 19:14:29 +020030}
31
32function resolveDependencies() {
Nicolas De Loof4675f042016-06-01 14:07:33 +020033 local plugin=$1; shift
Nicolas De Loof0ef5a622016-05-27 19:14:29 +020034
Nicolas De Loofdfe81a32016-05-28 17:26:01 +020035 dependencies=`jrunscript -e '\
36 java.lang.System.out.println(\
37 new java.util.jar.JarFile("'${plugin}.hpi'")\
38 .getManifest()\
39 .getMainAttributes()\
40 .getValue("Plugin-Dependencies")\
41 );'`
Nicolas De Loof0ef5a622016-05-27 19:14:29 +020042
43 if [[ "$dependencies" == "null" ]]; then
Nicolas De Loofdfe81a32016-05-28 17:26:01 +020044 echo " > plugin has no dependencies"
Nicolas De Loof0ef5a622016-05-27 19:14:29 +020045 return
46 fi
47
48 echo " > depends on ${dependencies}"
49
50 IFS=',' read -a array <<< "${dependencies}"
51
52 for d in "${array[@]}"
53 do
54 plugin=$(echo $d | cut -d':' -f1 -)
55 if [[ $d == *"resolution:=optional"* ]]
56 then
57 echo "skipping optional dependency $plugin"
58 else
59 download $plugin
60 fi
61 done
Nicolas De Loofa7a34c32016-05-30 09:10:58 +020062 touch ${plugin}.resolved
Nicolas De Loof0ef5a622016-05-27 19:14:29 +020063}
64
Nicolas De Loofdfe81a32016-05-28 17:26:01 +020065for plugin in "$@"
66do
67 download $plugin
68done
Nicolas De Loofa7a34c32016-05-30 09:10:58 +020069
70# cleanup 'resolved' flag files
71rm *.resolved