2 # This script reads filenames from STDIN and outputs any relevant requires
3 # information that needs to be included in the package.
5 # Based on rpm-4.4.2/scripts/find-req.pl
6 # Authors: Elan Ruusamäe <glen@pld-linux.org>
8 export PATH="/sbin:/usr/sbin:/bin:/usr/bin"
10 # Set the prefix, unless it is overriden
11 : ${RPM_LIBDIR=/usr/lib/rpm}
13 # Enable debug: JAVADEPS_DEBUG=true
14 : ${JAVADEPS_DEBUG=false}
16 # xsltproc for eclipse feature.xml
17 : ${xsltproc=/usr/bin/xsltproc}
19 # "%define java_min_classdataversion 51.0" in spec to minimum version to be 51.0
20 : ${MIN_CLASSDATAVERSION=}
22 # save $- state, to enable in functions
25 javaclassversionfilter() {
26 if [ "$MIN_CLASSDATAVERSION" ]; then
27 set -- $* "$MIN_CLASSDATAVERSION"
32 echo "java(ClassDataVersion) >= $v"
33 done | sort -V | tail -n 1
39 [ $# -gt 0 ] || return 1
40 $JAVADEPS_DEBUG && echo >&2 ">> javaclassversion($mode): $*"
42 # process only requires
43 [ "$mode" = requires ] || return $ret
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
50 javaclassversionfilter $classver
59 $JAVADEPS_DEBUG && echo >&2 ">> javajarversion($mode): $jar"
61 # check only files, symlinks could point outside buildroot
62 [ -f "$jar" -a ! -L "$jar" ] || return $ret
65 unzip -q -d $tmp $jar >&2
66 # workaround for .jar files with stupid permissions
69 # find .jar and .class files
70 find_javadeps $mode $(find $tmp -type f -regextype posix-extended -regex '^.+\.(class|jar)$') || ret=1
81 $JAVADEPS_DEBUG && echo >&2 ">> eclipse_feature($mode): $file"
83 if [ ! -x $xsltproc ]; then
87 $xsltproc --stringparam mode $mode ${RPM_LIBDIR}/eclipse-feature.xslt $file
95 $JAVADEPS_DEBUG && echo >&2 ">> find_javadeps($mode): $*"
99 javajarversion $mode "$file" || ret=1
102 javaclassversion $mode "$file" || {
103 echo >&2 "ERROR: Class version could not be extracted from $file"
108 eclipse_feature $mode "$file" || ret=1
111 $JAVADEPS_DEBUG && echo >&2 ">> find_javadeps($mode): no handle: $file"
119 # default mode to requires for backward compat
133 find_javadeps $mode $(cat -) > $t || ret=1