#!/bin/sh

RPMS_ROOT='/work/CDs/all/full-11.0-x86_64/suse'
INDEX_FILE='scan-java.out'
JARS_ROOT='jars'

touch $INDEX_FILE

cat $RPMS_ROOT/find-name-rpm | while read RPM; do
	rm -rf $JARS_ROOT
	mkdir -p $JARS_ROOT
	echo $RPM
	RPM_BASE_NAME=`basename $RPM .rpm`
	if [ -z "`rpm2cpio $RPMS_ROOT/$RPM | cpio -t '*.jar'`" ]; then
		echo No jar in $RPM_BASE_NAME
	 	continue
	fi
    cd $JARS_ROOT
	rpm2cpio $RPMS_ROOT/$RPM | cpio -i --verbose --make-directories '*.jar'
    cd ..
	for JAR in `find $JARS_ROOT -name '*.jar' -type f`; do
		JAR_BASE_NAME=`basename $JAR .jar`
		fastjar -t -f $JAR | grep '.*\.class' | grep -v '.*$.*' | sed -e 's/\//./g' -e 's/\.class$//' -e "s/^/$RPM_BASE_NAME $JAR_BASE_NAME /" >> $INDEX_FILE
	done
done

echo Done
