]>
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 | ||
52a22b3b ER |
19 | # save $- state, to enable in functions |
20 | debug=$- | |
21 | ||
071d8496 | 22 | javaclassversion() { |
52a22b3b | 23 | set -$debug |
c765bbf1 | 24 | local mode=$1; shift |
2e8dae56 | 25 | [ $# -gt 0 ] || return 1 |
c765bbf1 ER |
26 | $JAVADEPS_DEBUG && echo >&2 ">> javaclassversion($mode): $*" |
27 | ||
28 | # process only requires | |
29 | [ "$mode" = requires ] || return $ret | |
071d8496 | 30 | |
2e8dae56 ER |
31 | local classver=$(echo "$@" | xargs -r file | grep -o 'compiled Java class data, version [0-9.]*' | awk '{print $NF}' | sort -u) |
32 | if [ -z "$classver" ]; then | |
33 | return 1 | |
34 | fi | |
35 | ||
36 | local v | |
071d8496 | 37 | for v in $classver; do |
12a4ba07 | 38 | echo "java(ClassDataVersion) >= $v" |
071d8496 | 39 | done |
2e8dae56 | 40 | return 0 |
071d8496 JB |
41 | } |
42 | ||
43 | javajarversion() { | |
52a22b3b | 44 | set -$debug |
c765bbf1 ER |
45 | local mode=$1; shift |
46 | local jar=$1 | |
52a22b3b | 47 | local tmp ret=0 |
c765bbf1 | 48 | $JAVADEPS_DEBUG && echo >&2 ">> javajarversion($mode): $jar" |
071d8496 JB |
49 | |
50 | # check only files, symlinks could point outside buildroot | |
2e8dae56 | 51 | [ -f "$jar" -a ! -L "$jar" ] || return $ret |
071d8496 JB |
52 | |
53 | tmp=$(mktemp -d) | |
54 | unzip -q -d $tmp $jar >&2 | |
382c9030 ER |
55 | # workaround for .jar files with stupid permissions |
56 | chmod -R u+rwX $tmp | |
52a22b3b ER |
57 | |
58 | # find .jar and .class files | |
c765bbf1 | 59 | find_javadeps $mode $(find $tmp -type f -regextype posix-extended -regex '^.+\.(class|jar)$') || ret=1 |
0ffaea8b | 60 | rm -rf $tmp |
2e8dae56 ER |
61 | return $ret |
62 | } | |
071d8496 | 63 | |
c026521f ER |
64 | eclipse_feature() { |
65 | set -$debug | |
66 | local mode=$1; shift | |
67 | local file=$1 | |
68 | local ret=0 | |
69 | ||
70 | $JAVADEPS_DEBUG && echo >&2 ">> eclipse_feature($mode): $file" | |
71 | ||
72 | if [ ! -x $xsltproc ]; then | |
73 | return 0 | |
74 | fi | |
75 | ||
76 | $xsltproc --stringparam mode $mode ${RPM_LIBDIR}/eclipse-feature.xslt $file | |
77 | } | |
78 | ||
c765bbf1 | 79 | find_javadeps() { |
52a22b3b | 80 | set -$debug |
c765bbf1 | 81 | local mode=$1; shift |
2e8dae56 | 82 | local ret=0 |
0ffaea8b | 83 | |
c765bbf1 | 84 | $JAVADEPS_DEBUG && echo >&2 ">> find_javadeps($mode): $*" |
0ffaea8b | 85 | for file in $@; do |
071d8496 JB |
86 | case $file in |
87 | *.jar) | |
c765bbf1 | 88 | javajarversion $mode "$file" || ret=1 |
071d8496 JB |
89 | ;; |
90 | *.class) | |
c765bbf1 | 91 | javaclassversion $mode "$file" || { |
2e8dae56 ER |
92 | echo >&2 "ERROR: Class version could not be extracted from $file" |
93 | ret=1 | |
94 | } | |
071d8496 | 95 | ;; |
c026521f ER |
96 | */feature.xml) |
97 | eclipse_feature $mode "$file" || ret=1 | |
98 | ;; | |
0ffaea8b | 99 | *) |
c765bbf1 | 100 | $JAVADEPS_DEBUG && echo >&2 ">> find_javadeps($mode): no handle: $file" |
0ffaea8b | 101 | ;; |
071d8496 JB |
102 | esac |
103 | done | |
2e8dae56 | 104 | return $ret |
071d8496 JB |
105 | } |
106 | ||
2e8dae56 | 107 | ret=0 |
c765bbf1 ER |
108 | # default mode to requires for backward compat |
109 | mode=requires | |
110 | case $1 in | |
111 | -P|--provides) | |
112 | mode=provides | |
113 | shift | |
114 | ;; | |
115 | -R|--requires) | |
116 | mode=requires | |
117 | shift | |
118 | ;; | |
119 | esac | |
120 | ||
121 | t=$(mktemp) | |
122 | find_javadeps $mode $(cat -) > $t || ret=1 | |
52a22b3b | 123 | sort -u $t |
2e8dae56 | 124 | rm -f $t |
c765bbf1 | 125 | |
2e8dae56 | 126 | exit $ret |