]> git.pld-linux.org Git - packages/rpm.git/blame - rpm-java-requires
- avoid processing wrong xml files (xml must start with <feature>)
[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
52a22b3b
ER
10# save $- state, to enable in functions
11debug=$-
12
13# enable debug: FIND_JAVAREQ_DEBUG=true
14FIND_JAVAREQ_DEBUG=${FIND_JAVAREQ_DEBUG:-false}
15
071d8496 16javaclassversion() {
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
33javajarversion() {
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
53find_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
77t=$(mktemp)
78ret=0
0ffaea8b 79find_requires $(cat -) > $t || ret=1
52a22b3b 80sort -u $t
2e8dae56
ER
81rm -f $t
82exit $ret
This page took 0.364404 seconds and 4 git commands to generate.