]>
Commit | Line | Data |
---|---|---|
071d8496 JB |
1 | #!/bin/sh |
2 | # This script reads filenames from STDIN and outputs any relevant requires | |
3 | # information that needs to be included in the package. | |
4 | # | |
5 | # Based on rpm-4.4.2/scripts/find-req.pl | |
6 | # Authors: Elan Ruusamäe <glen@pld-linux.org> | |
7 | ||
8 | export PATH="/sbin:/usr/sbin:/bin:/usr/bin" | |
9 | ||
c026521f ER |
10 | # Set the prefix, unless it is overriden |
11 | : ${RPM_LIBDIR=/usr/lib/rpm} | |
12 | ||
c765bbf1 ER |
13 | # Enable debug: JAVADEPS_DEBUG=true |
14 | : ${JAVADEPS_DEBUG=false} | |
15 | ||
c026521f ER |
16 | # xsltproc for eclipse feature.xml |
17 | : ${xsltproc=/usr/bin/xsltproc} | |
18 | ||
e9576b98 ER |
19 | # "%define java_min_classdataversion 51.0" in spec to minimum version to be 51.0 |
20 | : ${MIN_CLASSDATAVERSION=} | |
21 | ||
52a22b3b ER |
22 | # save $- state, to enable in functions |
23 | debug=$- | |
24 | ||
e9576b98 ER |
25 | javaclassversionfilter() { |
26 | if [ "$MIN_CLASSDATAVERSION" ]; then | |
27 | set -- $* "$MIN_CLASSDATAVERSION" | |
28 | fi | |
29 | ||
30 | local v | |
31 | for v in $*; do | |
32 | echo "java(ClassDataVersion) >= $v" | |
33 | done | sort -V | tail -n 1 | |
34 | } | |
35 | ||
071d8496 | 36 | javaclassversion() { |
52a22b3b | 37 | set -$debug |
c765bbf1 | 38 | local mode=$1; shift |
2e8dae56 | 39 | [ $# -gt 0 ] || return 1 |
c765bbf1 ER |
40 | $JAVADEPS_DEBUG && echo >&2 ">> javaclassversion($mode): $*" |
41 | ||
42 | # process only requires | |
43 | [ "$mode" = requires ] || return $ret | |
071d8496 | 44 | |
2e8dae56 ER |
45 | local classver=$(echo "$@" | xargs -r file | grep -o 'compiled Java class data, version [0-9.]*' | awk '{print $NF}' | sort -u) |
46 | if [ -z "$classver" ]; then | |
47 | return 1 | |
48 | fi | |
49 | ||
e9576b98 | 50 | javaclassversionfilter $classver |
2e8dae56 | 51 | return 0 |
071d8496 JB |
52 | } |
53 | ||
54 | javajarversion() { | |
52a22b3b | 55 | set -$debug |
c765bbf1 ER |
56 | local mode=$1; shift |
57 | local jar=$1 | |
52a22b3b | 58 | local tmp ret=0 |
c765bbf1 | 59 | $JAVADEPS_DEBUG && echo >&2 ">> javajarversion($mode): $jar" |
071d8496 JB |
60 | |
61 | # check only files, symlinks could point outside buildroot | |
2e8dae56 | 62 | [ -f "$jar" -a ! -L "$jar" ] || return $ret |
071d8496 JB |
63 | |
64 | tmp=$(mktemp -d) | |
65 | unzip -q -d $tmp $jar >&2 | |
382c9030 ER |
66 | # workaround for .jar files with stupid permissions |
67 | chmod -R u+rwX $tmp | |
52a22b3b ER |
68 | |
69 | # find .jar and .class files | |
c765bbf1 | 70 | find_javadeps $mode $(find $tmp -type f -regextype posix-extended -regex '^.+\.(class|jar)$') || ret=1 |
0ffaea8b | 71 | rm -rf $tmp |
2e8dae56 ER |
72 | return $ret |
73 | } | |
071d8496 | 74 | |
c026521f ER |
75 | eclipse_feature() { |
76 | set -$debug | |
77 | local mode=$1; shift | |
78 | local file=$1 | |
79 | local ret=0 | |
80 | ||
81 | $JAVADEPS_DEBUG && echo >&2 ">> eclipse_feature($mode): $file" | |
82 | ||
83 | if [ ! -x $xsltproc ]; then | |
84 | return 0 | |
85 | fi | |
86 | ||
87 | $xsltproc --stringparam mode $mode ${RPM_LIBDIR}/eclipse-feature.xslt $file | |
88 | } | |
89 | ||
c765bbf1 | 90 | find_javadeps() { |
52a22b3b | 91 | set -$debug |
c765bbf1 | 92 | local mode=$1; shift |
2e8dae56 | 93 | local ret=0 |
0ffaea8b | 94 | |
c765bbf1 | 95 | $JAVADEPS_DEBUG && echo >&2 ">> find_javadeps($mode): $*" |
0ffaea8b | 96 | for file in $@; do |
071d8496 JB |
97 | case $file in |
98 | *.jar) | |
c765bbf1 | 99 | javajarversion $mode "$file" || ret=1 |
071d8496 JB |
100 | ;; |
101 | *.class) | |
c765bbf1 | 102 | javaclassversion $mode "$file" || { |
2e8dae56 ER |
103 | echo >&2 "ERROR: Class version could not be extracted from $file" |
104 | ret=1 | |
105 | } | |
071d8496 | 106 | ;; |
c026521f ER |
107 | */feature.xml) |
108 | eclipse_feature $mode "$file" || ret=1 | |
109 | ;; | |
0ffaea8b | 110 | *) |
c765bbf1 | 111 | $JAVADEPS_DEBUG && echo >&2 ">> find_javadeps($mode): no handle: $file" |
0ffaea8b | 112 | ;; |
071d8496 JB |
113 | esac |
114 | done | |
2e8dae56 | 115 | return $ret |
071d8496 JB |
116 | } |
117 | ||
2e8dae56 | 118 | ret=0 |
c765bbf1 ER |
119 | # default mode to requires for backward compat |
120 | mode=requires | |
121 | case $1 in | |
122 | -P|--provides) | |
123 | mode=provides | |
124 | shift | |
125 | ;; | |
126 | -R|--requires) | |
127 | mode=requires | |
128 | shift | |
129 | ;; | |
130 | esac | |
131 | ||
132 | t=$(mktemp) | |
133 | find_javadeps $mode $(cat -) > $t || ret=1 | |
52a22b3b | 134 | sort -u $t |
2e8dae56 | 135 | rm -f $t |
c765bbf1 | 136 | |
2e8dae56 | 137 | exit $ret |