]> git.pld-linux.org Git - packages/rpm.git/blame - rpm-java-requires
- it uses bash syntax, maybe should be rewritten
[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
10javaclassversion() {
2e8dae56 11 [ $# -gt 0 ] || return 1
071d8496 12
2e8dae56
ER
13 local classver=$(echo "$@" | xargs -r file | grep -o 'compiled Java class data, version [0-9.]*' | awk '{print $NF}' | sort -u)
14 if [ -z "$classver" ]; then
15 return 1
16 fi
17
18 local v
071d8496
JB
19 for v in $classver; do
20 echo "java(ClassDataVersion) >= $v"
21 done
2e8dae56 22 return 0
071d8496
JB
23}
24
25javajarversion() {
26 local jar="$1"
2e8dae56 27 local ret=0
071d8496
JB
28
29 # check only files, symlinks could point outside buildroot
2e8dae56 30 [ -f "$jar" -a ! -L "$jar" ] || return $ret
071d8496
JB
31
32 tmp=$(mktemp -d)
33 unzip -q -d $tmp $jar >&2
2e8dae56
ER
34 javaclassversion $(find $tmp -type f -name '*.class') || {
35 echo >&2 "ERROR: Class version could not be extracted from $jar"
36 ret=1
37 }
071d8496 38 rm -rf $tmp
071d8496 39
2e8dae56
ER
40 return $ret
41}
071d8496
JB
42
43find_requires() {
2e8dae56 44 local ret=0
071d8496
JB
45 for file in $FILES; do
46 case $file in
47 *.jar)
2e8dae56 48 javajarversion "$file" || ret=1
071d8496
JB
49 ;;
50 *.class)
2e8dae56
ER
51 javaclassversion "$file" || {
52 echo >&2 "ERROR: Class version could not be extracted from $file"
53 ret=1
54 }
071d8496
JB
55 ;;
56 esac
57 done
2e8dae56 58 return $ret
071d8496
JB
59}
60
2e8dae56
ER
61FILES=$(cat -)
62
63t=$(mktemp)
64ret=0
65find_requires > $t || ret=1
66rm -f $t
67exit $ret
This page took 0.044431 seconds and 4 git commands to generate.