1 |
#!/bin/sh |
#!/bin/sh |
2 |
|
|
3 |
TMPFILE=check-jni-methods.$$.1 |
# Fail if any command fails |
4 |
TMPFILE2=check-jni-methods.$$.2 |
set -e |
5 |
TMPFILE3=check-jni-methods.$$.3 |
# Don't override existing files |
6 |
|
set -C |
7 |
|
|
8 |
|
TMPFILE=/tmp/check-jni-methods.$$.1 |
9 |
|
TMPFILE2=/tmp/check-jni-methods.$$.2 |
10 |
|
TMPFILE3=/tmp/check-jni-methods.$$.3 |
11 |
|
|
12 |
# Find all methods defined in the header files generated |
# Find all methods defined in the header files generated |
13 |
# from the java source files. |
# from the java source files. |
18 |
# Find all methods in the JNI C source files. |
# Find all methods in the JNI C source files. |
19 |
find native/jni -name \*.c | \ |
find native/jni -name \*.c | \ |
20 |
xargs grep -h '^Java_' | \ |
xargs grep -h '^Java_' | \ |
21 |
LC_ALL=C sed -e 's,^\(Java_[a-z_A-Z0-9]*\) *(.*$,\1,' | \ |
LC_ALL=C sed -e 's,^\(Java_[a-z_A-Z0-9]*\) *(.*$,\1,' > $TMPFILE2 |
22 |
sort > $TMPFILE2 |
# Or in the the C++ files. (Note that cpp doesn't follow gnu conventions atm) |
23 |
|
# So we try to match both GNU style and some other style. |
24 |
|
find native/jni -name \*.cpp | \ |
25 |
|
xargs grep -h '^Java_' | \ |
26 |
|
LC_ALL=C sed -e 's,^\(Java_[a-z_A-Z0-9]*\) *(.*$,\1,' >> $TMPFILE2 |
27 |
|
find native/jni -name \*.cpp | \ |
28 |
|
xargs egrep -h '^(JNIEXPORT .* JNICALL )?Java_' | \ |
29 |
|
cut -f4 -d\ | \ |
30 |
|
LC_ALL=C sed -e 's,^\JNIEXPORT .* JNICALL \(Java_[a-z_A-Z0-9]*\) *(.*$,\1,' >> $TMPFILE2 |
31 |
|
mv $TMPFILE2 $TMPFILE3 |
32 |
|
sort $TMPFILE3 > $TMPFILE2 |
33 |
|
rm $TMPFILE3 |
34 |
|
|
35 |
# Write temporary ignore file. |
# Write temporary ignore file. |
36 |
cat > $TMPFILE3 << EOF |
cat > $TMPFILE3 << EOF |
40 |
EOF |
EOF |
41 |
|
|
42 |
# Compare again silently. |
# Compare again silently. |
43 |
diff -ub -0 $TMPFILE $TMPFILE2 | grep '^[+-]Java' | grep -q -v -f $TMPFILE3 |
# Use fgrep and direct the output to /dev/null for compatibility with older |
44 |
RESULT=$? |
# grep instead of using the non portable -q. |
45 |
|
if diff -b -U 0 $TMPFILE $TMPFILE2 | grep '^[+-]Java' | \ |
46 |
if test "$RESULT" = "0" ; then |
fgrep -v -f $TMPFILE3 > /dev/null; |
47 |
|
then |
48 |
|
PROBLEM=1 |
49 |
echo "Found a problem with the JNI methods declared and implemented." |
echo "Found a problem with the JNI methods declared and implemented." |
50 |
echo "(-) missing in implementation, (+) missing in header files" |
echo "(-) missing in implementation, (+) missing in header files" |
51 |
|
|
52 |
# Compare the found method lists. |
# Compare the found method lists. |
53 |
diff -ub -0 $TMPFILE $TMPFILE2 | grep '^[+-]Java' | grep -v -f $TMPFILE3 |
diff -b -U 0 $TMPFILE $TMPFILE2 | grep '^[+-]Java' | fgrep -v -f $TMPFILE3 |
54 |
fi |
fi |
55 |
|
|
56 |
# Cleanup. |
# Cleanup. |
57 |
rm -f $TMPFILE $TMPFILE2 $TMPFILE3 |
rm -f $TMPFILE $TMPFILE2 $TMPFILE3 |
58 |
|
|
59 |
if test "$RESULT" = "0" ; then |
if test "$PROBLEM" = "1" ; then |
60 |
exit 1 |
exit 1 |
61 |
fi |
fi |
62 |
|
|
63 |
exit 0 |
exit 0 |
|
|
|