]> git.pld-linux.org Git - packages/rpm.git/blame - rpm-java-requires
- rel 48; force glob() to use lstat now; we can avoid using internal copy now + we...
[packages/rpm.git] / rpm-java-requires
CommitLineData
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
8export PATH="/sbin:/usr/sbin:/bin:/usr/bin"
9
c765bbf1
ER
10# Enable debug: JAVADEPS_DEBUG=true
11: ${JAVADEPS_DEBUG=false}
12
52a22b3b
ER
13# save $- state, to enable in functions
14debug=$-
15
071d8496 16javaclassversion() {
52a22b3b 17 set -$debug
c765bbf1 18 local mode=$1; shift
2e8dae56 19 [ $# -gt 0 ] || return 1
c765bbf1
ER
20 $JAVADEPS_DEBUG && echo >&2 ">> javaclassversion($mode): $*"
21
22 # process only requires
23 [ "$mode" = requires ] || return $ret
071d8496 24
2e8dae56
ER
25 local classver=$(echo "$@" | xargs -r file | grep -o 'compiled Java class data, version [0-9.]*' | awk '{print $NF}' | sort -u)
26 if [ -z "$classver" ]; then
27 return 1
28 fi
29
30 local v
071d8496 31 for v in $classver; do
12a4ba07 32 echo "java(ClassDataVersion) >= $v"
071d8496 33 done
2e8dae56 34 return 0
071d8496
JB
35}
36
37javajarversion() {
52a22b3b 38 set -$debug
c765bbf1
ER
39 local mode=$1; shift
40 local jar=$1
52a22b3b 41 local tmp ret=0
c765bbf1 42 $JAVADEPS_DEBUG && echo >&2 ">> javajarversion($mode): $jar"
071d8496
JB
43
44 # check only files, symlinks could point outside buildroot
2e8dae56 45 [ -f "$jar" -a ! -L "$jar" ] || return $ret
071d8496
JB
46
47 tmp=$(mktemp -d)
48 unzip -q -d $tmp $jar >&2
382c9030
ER
49 # workaround for .jar files with stupid permissions
50 chmod -R u+rwX $tmp
52a22b3b
ER
51
52 # find .jar and .class files
c765bbf1 53 find_javadeps $mode $(find $tmp -type f -regextype posix-extended -regex '^.+\.(class|jar)$') || ret=1
0ffaea8b 54 rm -rf $tmp
2e8dae56
ER
55 return $ret
56}
071d8496 57
c765bbf1 58find_javadeps() {
52a22b3b 59 set -$debug
c765bbf1 60 local mode=$1; shift
2e8dae56 61 local ret=0
0ffaea8b 62
c765bbf1 63 $JAVADEPS_DEBUG && echo >&2 ">> find_javadeps($mode): $*"
0ffaea8b 64 for file in $@; do
071d8496
JB
65 case $file in
66 *.jar)
c765bbf1 67 javajarversion $mode "$file" || ret=1
071d8496
JB
68 ;;
69 *.class)
c765bbf1 70 javaclassversion $mode "$file" || {
2e8dae56
ER
71 echo >&2 "ERROR: Class version could not be extracted from $file"
72 ret=1
73 }
071d8496 74 ;;
0ffaea8b 75 *)
c765bbf1 76 $JAVADEPS_DEBUG && echo >&2 ">> find_javadeps($mode): no handle: $file"
0ffaea8b 77 ;;
071d8496
JB
78 esac
79 done
2e8dae56 80 return $ret
071d8496
JB
81}
82
2e8dae56 83ret=0
c765bbf1
ER
84# default mode to requires for backward compat
85mode=requires
86case $1 in
87-P|--provides)
88 mode=provides
89 shift
90 ;;
91-R|--requires)
92 mode=requires
93 shift
94 ;;
95esac
96
97t=$(mktemp)
98find_javadeps $mode $(cat -) > $t || ret=1
52a22b3b 99sort -u $t
2e8dae56 100rm -f $t
c765bbf1 101
2e8dae56 102exit $ret
This page took 0.135075 seconds and 4 git commands to generate.