forked from dwijnand/sbt-extras
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ivy-classpath
executable file
·151 lines (118 loc) · 3.49 KB
/
ivy-classpath
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/bin/sh
#
# ivy-classpath by paul phillips part of sbt-extras
# https://github.com/paulp/sbt-extras
#
# Todo - make it possible to leave out lots more
#
if ! which ivy >/dev/null; then
cat <<"EOM"
Error: no `ivy` command line program found.
On OSX with homebrew, you can 'brew install ivy', otherwise
save the following as executable 'ivy' and place it on your path.
#!/bin/sh
#
cd /path/to/ivy/distribution && java $JAVA_OPTS -jar ivy-2.2.0.jar "$@"
EOM
exit 1
fi
prog="$(basename $0)"
unset verbose
while getopts :v opt; do
case $opt in
v) verbose=true
esac
done
# This removes all the options from $@, as getopts doesn't touch it.
# After this, "$@" contains the non-option arguments.
shift $((OPTIND-1))
if [[ $# -eq 0 ]]; then
cat <<EOM
Usage: $prog [-v] [dependency dependency ...]
Resolves all dependencies through the ivy cache, downloading any required jars.
When complete, echoes a classpath containing all dependencies, including
transitively required ones. The format to express dependencies is
org%name%version
Example uses:
$prog com.typesafe.akka%akka%2.0 play%play_2.9.1%2.0
$prog org.ow2.asm%asm%latest.release net.databinder%dispatch-http_2.9.1%latest.snapshot
scala -Ylog-classpath -cp \$($prog com.typesafe.akka%akka-actor%2.0 com.google.guava%guava%11.0.2)
EOM
exit 0
fi
resolverNames="shared public"
dir="$(mktemp -dt ivyfetch)"
cd $dir
[[ $verbose ]] || echo >&2 "[Working... tail $dir/log for progress.]"
genIvySettings () {
cat <<EOM
<ivysettings>
<settings defaultResolver="default"/>
<include url="\${ivy.default.settings.dir}/ivysettings-public.xml"/>
<include url="\${ivy.default.settings.dir}/ivysettings-shared.xml"/>
<include url="\${ivy.default.settings.dir}/ivysettings-local.xml"/>
<!-- <include url="\${ivy.default.settings.dir}/ivysettings-main-chain.xml"/> -->
$("$@")
<include url="\${ivy.default.settings.dir}/ivysettings-default-chain.xml"/>
</ivysettings>
EOM
}
ibiblio() {
resolverNames="$resolverNames $1"
cat <<EOM
<ibiblio name="${1}" m2compatible="true" root="${2}"/>
EOM
}
ibiblioLines () {
local name="$1"
local url="$2"
ibiblio "${name}-releases" "${url}releases/"
ibiblio "${name}-snapshots" "${url}snapshots/"
}
chainLines () {
echo ' <chain name="main" dual="true" returnFirst="true" checkmodified="true">'
for id in $@; do
echo " <resolver ref=\"$id\" />"
done
echo ' </chain>'
}
ivyChain () {
echo '<include url="${ivy.default.settings.dir}/ivysettings-shared.xml"/>'
echo '<resolvers>'
ibiblioLines oss https://oss.sonatype.org/content/repositories/
ibiblioLines typesafe http://repo.typesafe.com/typesafe/maven-
ibiblioLines akka http://repo.akka.io/
ibiblio codahale http://repo.codahale.com/
chainLines $resolverNames
echo '</resolvers>'
}
resolveLine () {
( IFS="%" && set -- "$1" && printf ' <dependency org="%s" name="%s" rev="%s" force="true" changing="true" />' $* && echo "" )
}
genIvyResolve () {
cat <<EOM
<ivy-module version="2.0">
<info organisation="org.improving" module="ivy-classpath" />
<dependencies>
$( for dep in "$@"; do resolveLine "$dep" ; done )
</dependencies>
</ivy-module>
EOM
}
runner () {
# echo >&2 "$@"
"$@"
}
run () {
[[ $verbose ]] || exec &>log
genIvySettings ivyChain >ivysettings.xml
genIvyResolve "$@" >ivy.xml
[[ $verbose ]] && cat ivy.xml
ivy \
-cachepath $dir/classpath \
-settings $dir/ivysettings.xml \
-ivy $dir/ivy.xml
}
( run "$@" )
# and finally, the object of our desire
cat $dir/classpath