]>
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 | ||
52a22b3b ER |
10 | # save $- state, to enable in functions |
11 | debug=$- | |
12 | ||
13 | # enable debug: FIND_JAVAREQ_DEBUG=true | |
14 | FIND_JAVAREQ_DEBUG=${FIND_JAVAREQ_DEBUG:-false} | |
15 | ||
071d8496 | 16 | javaclassversion() { |
52a22b3b | 17 | set -$debug |
2e8dae56 | 18 | [ $# -gt 0 ] || return 1 |
52a22b3b | 19 | $FIND_JAVAREQ_DEBUG && echo >&2 ">> class: $*" |
071d8496 | 20 | |
2e8dae56 ER |
21 | local classver=$(echo "$@" | xargs -r file | grep -o 'compiled Java class data, version [0-9.]*' | awk '{print $NF}' | sort -u) |
22 | if [ -z "$classver" ]; then | |
23 | return 1 | |
24 | fi | |
25 | ||
26 | local v | |
071d8496 JB |
27 | for v in $classver; do |
28 | echo "java(ClassDataVersion) >= $v" | |
29 | done | |
2e8dae56 | 30 | return 0 |
071d8496 JB |
31 | } |
32 | ||
33 | javajarversion() { | |
52a22b3b | 34 | set -$debug |
071d8496 | 35 | local jar="$1" |
52a22b3b ER |
36 | local tmp ret=0 |
37 | $FIND_JAVAREQ_DEBUG && echo >&2 ">> jar: $jar" | |
071d8496 JB |
38 | |
39 | # check only files, symlinks could point outside buildroot | |
2e8dae56 | 40 | [ -f "$jar" -a ! -L "$jar" ] || return $ret |
071d8496 JB |
41 | |
42 | tmp=$(mktemp -d) | |
43 | unzip -q -d $tmp $jar >&2 | |
382c9030 ER |
44 | # workaround for .jar files with stupid permissions |
45 | chmod -R u+rwX $tmp | |
52a22b3b ER |
46 | |
47 | # find .jar and .class files | |
ca4a59ce | 48 | find_requires $(find $tmp -type f -regextype posix-extended -regex '^.+\.(class|jar)$') || ret=1 |
0ffaea8b | 49 | rm -rf $tmp |
2e8dae56 ER |
50 | return $ret |
51 | } | |
071d8496 JB |
52 | |
53 | find_requires() { | |
52a22b3b | 54 | set -$debug |
2e8dae56 | 55 | local ret=0 |
0ffaea8b ER |
56 | |
57 | $FIND_JAVAREQ_DEBUG && echo >&2 ">> find_requires: $*" | |
58 | for file in $@; do | |
071d8496 JB |
59 | case $file in |
60 | *.jar) | |
2e8dae56 | 61 | javajarversion "$file" || ret=1 |
071d8496 JB |
62 | ;; |
63 | *.class) | |
2e8dae56 ER |
64 | javaclassversion "$file" || { |
65 | echo >&2 "ERROR: Class version could not be extracted from $file" | |
66 | ret=1 | |
67 | } | |
071d8496 | 68 | ;; |
0ffaea8b ER |
69 | *) |
70 | $FIND_JAVAREQ_DEBUG && echo >&2 ">> find_requires: no handle: $file" | |
71 | ;; | |
071d8496 JB |
72 | esac |
73 | done | |
2e8dae56 | 74 | return $ret |
071d8496 JB |
75 | } |
76 | ||
2e8dae56 ER |
77 | t=$(mktemp) |
78 | ret=0 | |
0ffaea8b | 79 | find_requires $(cat -) > $t || ret=1 |
52a22b3b | 80 | sort -u $t |
2e8dae56 ER |
81 | rm -f $t |
82 | exit $ret |