WAR FILE comparison

Command:
./wardiff.sh /tmp/YourWarName.war /tmp/OtherWarName.war

# name: wardiff.sh
# desc:	Takes two .war or .jar files as args and
#	explodes each in a separate directory, and then
#	does a dircmp (recursive directory/file compare)
#	on those directories.
#	Takes a simple and stupid approach to naming the
#	directories -
#
#	Directory 1 = "A_{name of war file 1}"
#	Directory 2 = "B_{name of war file 2}"
#
#	The A_ and B_ prefixes are simply a lazy way of
#	running into problems when the war files have the
#	same name.
#
# reqs:	. must be writable by current user.
# auth:	Rob Ries, Chessiecap, Inc. for NASD
# date:	Apr 2006

echo Args: $1 $2

WAR1=$1
WAR2=$2

case "x$OSTYPE" in
xcygwin)
	# Just in case they entered "C:\" or something, convert in order to test
	# absolute path.
	WAR1=`cygpath -u "$WAR1"`
	WAR2=`cygpath -u "$WAR2"`
	;;
esac

WAR1ABSOLUTEPATH=$(cd $(eval "dirname ${WAR1}");pwd)/$(eval "basename ${WAR1}")
WAR2ABSOLUTEPATH=$(cd $(eval "dirname ${WAR2}");pwd)/$(eval "basename ${WAR2}")

if test ! -r "$WAR1ABSOLUTEPATH"
then
	echo "Cannot read $WAR1ABSOLUTEPATH."
	exit 1
fi
if test ! -r "$WAR2ABSOLUTEPATH"
then
	echo "Cannot read $WAR2ABSOLUTEPATH."
	exit 1
fi

WARDIR1=A_`basename $WAR1ABSOLUTEPATH ".[jw]ar"`
WARDIR2=B_`basename $WAR2ABSOLUTEPATH ".[jw]ar"`

echo
echo "Using directory $WARDIR1	for	$WAR1ABSOLUTEPATH."
echo "Using directory $WARDIR2	for	$WAR2ABSOLUTEPATH."
echo

# Create directories to hold the unjar'ed .jar files.
mkdir $WARDIR1
if test $? -ne -0
then
	echo "Cannot mkdir $WARDIR1."
	exit 1
else
	echo "Created $WARDIR1."
fi

mkdir $WARDIR2
if test $? -ne -0
then
	echo "Cannot mkdir $WARDIR2."
	exit 1
else
	echo "Created $WARDIR2."
fi

# Unjar the .jar files.
case "x$OSTYPE" in
xcygwin)
	# cygwin jar had trouble with unix style names?
	# absolute path.
	WAR1ABSOLUTEPATH=`cygpath -m "$WAR1ABSOLUTEPATH"`
	WAR2ABSOLUTEPATH=`cygpath -m "$WAR2ABSOLUTEPATH"`
	;;
esac
cd $WARDIR1
jar xf $WAR1ABSOLUTEPATH
echo
if test $? -ne 0
then
	echo "Error unjarring $WAR1ABSOLUTEPATH."
	exit 1
else
	echo "Unjarred $WAR1ABSOLUTEPATH in $WARDIR1."
fi
cd ../$WARDIR2
jar xf $WAR2ABSOLUTEPATH
if test $? -ne 0
then
	echo "Error unjarring $WAR2ABSOLUTEPATH."
	exit 1
else
	echo "Unjarred $WAR2ABSOLUTEPATH in $WARDIR2."
fi

# Now do the compares.
cd ..
echo
case "x$OSTYPE" in
xcygwin)
	diff -rq $WARDIR1 $WARDIR2
	;;
*)
	dircmp $WARDIR1 $WARDIR2 | egrep -v "^same|^directory|omparison of .*Page [0-9]|^[      ]*$"
	;;
esac

# Clean up?
echo
echo "Do you want me to clean up or leave the exploded output in:"
echo "$WARDIR1"
echo "$WARDIR2"
echo "?"
echo "(If there are diffs, it is often necessary to do file-by-file diffs at this point,"
echo "so you may not want to clean up.)"
echo
echo "Enter Y to remove exploded output:"
read RESP
case "x$RESP" in
xY*|xy*)
	echo "Cleaning up..."
	rm -r $WARDIR1
	rm -r $WARDIR2
	;;
*)
	echo "Leaving temp directories..."
	;;
esac
echo "Done."
exit 0

This is for solaris.

If you use in common unix box. you may found dircmp command not found. Then just get rid of the line of dircmp and replace with

diff -rq $WARDIR1 $WARDIR2\
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s