]> git.pld-linux.org Git - packages/rpm.git/blob - find-java-req.sh
- fix header
[packages/rpm.git] / find-java-req.sh
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:/usr/X11R6/bin"
9
10 IGNORE_DEPS="@"
11 BUILDROOT="/"
12
13 # Loop over all args
14 while :; do
15 # Break out if there are no more args
16         case $# in
17         0)
18                 break
19                 ;;
20         esac
21
22 # Get the first arg, and shuffle
23         option=$1
24         shift
25
26 # Make all options have two hyphens
27         orig_option=$option     # Save original for error messages
28         case $option in
29         --*) ;;
30         -*) option=-$option ;;
31         esac
32
33         case $option in
34         --buildroot)
35                 BUILDROOT=$1
36                 shift
37                 ;;
38         --ignore_deps)
39                 IGNORE_DEPS=$1
40                 shift
41                 ;;
42         --help)
43                 echo $usage
44                 exit 0
45                 ;;
46         *)
47                 echo "$0: Unrecognized option: \"$orig_option\"; use --help for usage." >&2
48                 exit 1
49                 ;;
50         esac
51 done
52
53 javaclassversion() {
54         local ver
55         classver=$(file "$@" | grep -o 'compiled Java class data, version [0-9.]*' | awk '{print $NF}' | sort -u)
56         [ "$classver" ] || return
57         for v in $classver; do
58                 echo "java(ClassDataVersion) >= $v"
59         done
60 }
61
62 javajarversion() {
63         local jar="$1"
64
65         # check only files, symlinks could point outside buildroot
66         [ -f "$jar" -a ! -L "$jar" ] || return
67
68         tmp=$(mktemp -d)
69         unzip -q -d $tmp $jar >&2
70         javaclassversion $(find $tmp -type f -name '*.class')
71         rm -rf $tmp
72 }
73
74 for file in $(cat -); do
75         case $file in
76         *.jar)
77                 javajarversion "$file"
78                 unzip -p $file | javadeps --requires --rpmformat --keywords -
79         ;;
80         *.class)
81                 javaclassversion "$file"
82                 javadeps --requires --rpmformat --keywords $file
83         ;;
84         esac
85 done | sort -u | egrep -v \'$IGNORE_DEPS\'
This page took 0.036129 seconds and 4 git commands to generate.