Jeremy Katz e053ce
#!/bin/sh
Jeremy Katz e053ce
Jeremy Katz e053ce
# If using normal root, avoid changing anything.
Jeremy Katz e053ce
if [ -z "$RPM_BUILD_ROOT" -o "$RPM_BUILD_ROOT" = "/" ]; then
Jeremy Katz e053ce
	exit 0
Jeremy Katz e053ce
fi
Jeremy Katz e053ce
Jeremy Katz e053ce
# If zip is not installed, we can't repack the jars.
Jeremy Katz e053ce
if [ ! -x /usr/bin/zip ]; then
Jeremy Katz e053ce
	exit 0
Jeremy Katz e053ce
fi
Jeremy Katz e053ce
if [ ! -x /usr/bin/unzip ]; then
Jeremy Katz e053ce
	exit 0
Jeremy Katz e053ce
fi
Jeremy Katz e053ce
afe459
JARS=`find $RPM_BUILD_ROOT -type f -name \*.jar -not -size 0`
20a456
if [ ! -z "$JARS" ]; then
20a456
Jeremy Katz e053ce
	# make $RPM_BUILD_ROOT/tmp if it doesn't exist
Jeremy Katz e053ce
	rmtmp=0
Jeremy Katz e053ce
	if [ ! -x "$RPM_BUILD_ROOT/tmp" ]; then
Jeremy Katz e053ce
		mkdir -p $RPM_BUILD_ROOT/tmp
Jeremy Katz e053ce
		rmtmp=1
Jeremy Katz e053ce
	fi
20a456
20a456
	# unpack every jar, set the date of the files and directories and
Jeremy Katz e053ce
	# repack the jar
d22596
	OLD_IFS="$IFS"
d22596
	IFS=$(printf '\n\t')
Jeremy Katz e053ce
	for j in $JARS ; do
d22596
		JARNAME=`basename "$j"`
d22596
		JTMPDIR=`mktemp -d -p $RPM_BUILD_ROOT/tmp "$JARNAME.tmpdir.XXXXXXXXXX"` || exit 1
d22596
		JARDIR=`mktemp -d -p $RPM_BUILD_ROOT/tmp "$JARNAME.jardir.XXXXXXXXXX"` || exit 1
d22596
		TIMEREF=`mktemp -p $RPM_BUILD_ROOT/tmp "$JARNAME.timeref.XXXXXXXXXX"` || exit 1
20a456
d22596
		pushd "$JTMPDIR" > /dev/null
d22596
		/usr/bin/unzip -qq -o "$j"
76c839
		find -type d -exec chmod a+rx,u+w {} \;
76c839
		find -type f -exec chmod a+r,u+w {} \;
d22596
		rm -f "$j"
20a456
Jeremy Katz e053ce
		# Create the directories first.
ab5323
		find -type d | LC_ALL=C sort | while read d; do
ab5323
			mkdir -p "$JARDIR/$d"
20a456
        	done
Jeremy Katz e053ce
Jeremy Katz e053ce
		# Get the modtime from the newest ChangeLog. If the project
Jeremy Katz e053ce
		# doesn't have a ChangeLog, Jan 1, 1970 will be used.
Jeremy Katz e053ce
		DATE="1970-01-01 UTC"
Jeremy Katz e053ce
Jeremy Katz e053ce
		if [ -z $_PACKAGE_BUILD_DIR ]; then
Jeremy Katz e053ce
			_PACKAGE_BUILD_DIR=$RPM_BUILD_DIR/$RPM_PACKAGE_NAME-$RPM_PACKAGE_VERSION
Jeremy Katz e053ce
		fi
Jeremy Katz e053ce
Jeremy Katz e053ce
		if [ -d $_PACKAGE_BUILD_DIR ]; then
Jeremy Katz e053ce
			CHANGELOGS=`find $_PACKAGE_BUILD_DIR -type f -name ChangeLog`
Jeremy Katz e053ce
			if [ ! -z "$CHANGELOGS" ]; then
Jeremy Katz e053ce
				for c in $CHANGELOGS; do
Jeremy Katz e053ce
					TMPDATE=`stat -c %y $c | cut -d " " -f 1-2`
Jeremy Katz e053ce
					if [ `date --date="$TMPDATE" +%s` -gt `date --date="$DATE" +%s` ]; then
Jeremy Katz e053ce
						DATE="$TMPDATE"
Jeremy Katz e053ce
					fi
Jeremy Katz e053ce
				done
20a456
			fi
Jeremy Katz e053ce
		fi
Jeremy Katz e053ce
Jeremy Katz e053ce
		# move the contents over to the a new directory in order and set
ab5323
		# the times.
ab5323
		find -type f | LC_ALL=C sort | while read f; do
ab5323
			cp "$f" "$JARDIR/$f"
ab5323
			touch --date="$DATE" "$JARDIR/$f"
Jeremy Katz e053ce
        	done
Jeremy Katz e053ce
		popd > /dev/null
Jeremy Katz e053ce
Jeremy Katz e053ce
		# Set the times of the directories.
ab5323
		find "$JARDIR" -type d | while read d; do
ab5323
			touch --date="$DATE" "$d"
ab5323
		done
Jeremy Katz e053ce
Jeremy Katz e053ce
		# make the jar
d22596
		pushd "$JARDIR" > /dev/null
Jeremy Katz e053ce
Jeremy Katz e053ce
		if [ -n "`find -not -name '.'`" ]; then
be607b
			if [ -e META-INF/MANIFEST.MF ]; then
d22596
			    /usr/bin/zip -q -X -9 "$j" META-INF/MANIFEST.MF
be607b
			fi
d22596
			find * -not -name '.' | LC_ALL=C sort | /usr/bin/zip -u -q -X -9 "$j" -@
Jeremy Katz e053ce
		else
Jeremy Katz e053ce
			# Put the empty jar back
d22596
			touch "$j"
Jeremy Katz e053ce
		fi
Jeremy Katz e053ce
		popd > /dev/null
Jeremy Katz e053ce
Jeremy Katz e053ce
		# Cleanup.
d22596
		rm -rf "$JTMPDIR"
d22596
		rm -rf "$JARDIR"
d22596
		rm -f "$TIMEREF"
Jeremy Katz e053ce
	done
d22596
	IFS="$OLD_IFS"
Jeremy Katz e053ce
Jeremy Katz e053ce
	# remove $RPM_BUILD_ROOT/tmp if we created it
Jeremy Katz e053ce
	if [ $rmtmp -eq 1 ]; then
Jeremy Katz e053ce
		rm -rf $RPM_BUILD_ROOT/tmp
Jeremy Katz e053ce
	fi
Jeremy Katz e053ce
fi