ohair@425: #!/bin/bash ohair@425: # ohair@425: # Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. ohair@425: # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. ohair@425: # ohair@425: # This code is free software; you can redistribute it and/or modify it ohair@425: # under the terms of the GNU General Public License version 2 only, as ohair@425: # published by the Free Software Foundation. ohair@425: # ohair@425: # This code is distributed in the hope that it will be useful, but WITHOUT ohair@425: # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ohair@425: # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ohair@425: # version 2 for more details (a copy is included in the LICENSE file that ohair@425: # accompanied this code). ohair@425: # ohair@425: # You should have received a copy of the GNU General Public License version ohair@425: # 2 along with this work; if not, write to the Free Software Foundation, ohair@425: # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. ohair@425: # ohair@425: # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA ohair@425: # or visit www.oracle.com if you need additional information or have any ohair@425: # questions. ohair@425: # ohair@425: ohair@425: # Simple tool to diff two jar or zip files. It unpacks the jar/zip files and ohair@425: # reports if files differs and if files are new or missing. ohair@425: # Assumes gnu diff. ohair@425: ohair@425: # There are a few source files that have DOS line endings in the ohair@425: # jaxp/jaxws source drops, when the sources were added to the repository ohair@425: # the source files were converted to UNIX line endings. ohair@425: # For now we ignore these differences. ohair@425: DIFF_FLAGS="--strip-trailing-cr" ohair@425: #set -x ohair@425: ohair@425: if [ $# -lt 2 ] ohair@425: then ohair@425: echo "Diff two jar/zip files. Return codes: 0 - no diff, 1 - diff, 2 - couldn't perform diff" ohair@425: echo "Syntax: $0 old_archive new_archive [old_root new_root]" ohair@425: exit 2 ohair@425: fi ohair@425: ohair@425: if [ ! -f $1 ] ohair@425: then ohair@425: echo $1 does not exist ohair@425: exit 2 ohair@425: fi ohair@425: ohair@425: if [ ! -f $2 ] ohair@425: then ohair@425: echo $2 does not exist ohair@425: exit 2 ohair@425: fi ohair@425: ohair@425: IGNORES="cat" ohair@425: OLD=$(cd $(dirname $1) && pwd)/$(basename $1) ohair@425: NEW=$(cd $(dirname $2) && pwd)/$(basename $2) ohair@425: ohair@425: if [ $# -gt 3 ] ohair@425: then ohair@425: ROOT1=$(cd $3 && pwd) ohair@425: ROOT2=$(cd $4 && pwd) ohair@425: OLD_NAME=$(echo $OLD | sed "s|$ROOT1/||") ohair@425: NEW_NAME=$(echo $NEW | sed "s|$ROOT2/||") ohair@425: if [ $# == 5 ]; then IGNORES="$5"; fi ohair@425: else ohair@425: ROOT1=$(dirname $OLD)/ ohair@425: ROOT2=$(dirname $NEW)/ ohair@425: OLD_NAME=$OLD ohair@425: NEW_NAME=$NEW ohair@425: if [ $# == 3 ]; then IGNORES="$3"; fi ohair@425: fi ohair@425: ohair@425: if [ "`uname`" == "SunOS" ]; then erikj@458: if [ -f "`which gdiff`" ]; then erikj@458: DIFF=gdiff erikj@458: else erikj@458: DIFF=diff erikj@458: fi ohair@425: else ohair@425: DIFF=diff ohair@425: fi ohair@425: ohair@425: OLD_SUFFIX="${OLD##*.}" ohair@425: NEW_SUFFIX="${NEW##*.}" ohair@425: if [ "$OLD_SUFFIX" != "$NEW_SUFFIX" ]; then ohair@425: echo The files do not have the same suffix type! ohair@425: exit 2 ohair@425: fi ohair@425: erikj@445: if [ "$OLD_SUFFIX" != "zip" ] && [ "$OLD_SUFFIX" != "jar" ] && [ "$OLD_SUFFIX" != "sym" ]; then erikj@445: echo The files have to be zip, jar or sym! They are $OLD_SUFFIX ohair@425: exit 2 ohair@425: fi ohair@425: ohair@425: UNARCHIVE="unzip -q" ohair@425: ohair@425: TYPE="$OLD_SUFFIX" ohair@425: ohair@425: if cmp $OLD $NEW > /dev/null ohair@425: then ohair@425: # The files were bytewise identical. ohair@425: exit 0 ohair@425: fi ohair@425: ohair@425: # Not quite identical, the might still contain the same data. ohair@425: # Unpack the jar/zip files in temp dirs ohair@425: if test "x$COMPARE_ROOT" == "x"; then ohair@425: COMPARE_ROOT=/tmp/compare_root.$$ ohair@425: REMOVE_COMPARE_ROOT=true ohair@425: fi ohair@425: OLD_TEMPDIR=$COMPARE_ROOT/$OLD_NAME.old ohair@425: NEW_TEMPDIR=$COMPARE_ROOT/$NEW_NAME.new ohair@425: mkdir -p $OLD_TEMPDIR ohair@425: mkdir -p $NEW_TEMPDIR ohair@425: (cd $OLD_TEMPDIR && rm -rf * ; $UNARCHIVE $OLD) ohair@425: (cd $NEW_TEMPDIR && rm -rf * ; $UNARCHIVE $NEW) ohair@425: ohair@425: ONLY1=$(LANG=C $DIFF -rq $OLD_TEMPDIR $NEW_TEMPDIR | grep "^Only in $OLD_TEMPDIR") ohair@425: ohair@425: if [ -n "$ONLY1" ]; then ohair@425: echo " Only the OLD $OLD_NAME contains:" ohair@425: LANG=C $DIFF -rq $DIFF_FLAGS $OLD_TEMPDIR $NEW_TEMPDIR | grep "^Only in $OLD_TEMPDIR" \ ohair@425: | sed "s|Only in $OLD_TEMPDIR| |"g | sed 's|: |/|g' ohair@425: fi ohair@425: ohair@425: ONLY2=$(LANG=C $DIFF -rq $OLD_TEMPDIR $NEW_TEMPDIR | grep "^Only in $NEW_TEMPDIR") ohair@425: ohair@425: if [ -n "$ONLY2" ]; then ohair@425: echo " Only the NEW $NEW_NAME contains:" ohair@425: LANG=C $DIFF -rq $DIFF_FLAGS $OLD_TEMPDIR $NEW_TEMPDIR | grep "^Only in $NEW_TEMPDIR" \ ohair@425: | sed "s|Only in $NEW_TEMPDIR| |"g | sed 's|: |/|g' ohair@425: fi ohair@425: erikj@445: DIFFTEXT="/bin/bash `dirname $0`/difftext.sh" ohair@425: ohair@425: LANG=C $DIFF -rq $DIFF_FLAGS $OLD_TEMPDIR $NEW_TEMPDIR | grep differ | cut -f 2,4 -d ' ' | \ ohair@425: awk "{ print \"$DIFFTEXT \"\$1\" \"\$2 }" > $COMPARE_ROOT/diffing ohair@425: ohair@425: /bin/bash $COMPARE_ROOT/diffing > $COMPARE_ROOT/diffs ohair@425: ohair@425: if [ -s "$COMPARE_ROOT/diffs" ]; then ohair@425: echo " Differing files in $OLD_NAME" ohair@425: cat $COMPARE_ROOT/diffs | grep differ | $IGNORES | cut -f 2 -d ' ' | \ ohair@425: sed "s|$OLD_TEMPDIR| |g" ohair@425: fi ohair@425: ohair@425: # Clean up ohair@425: ohair@425: if [ "x$REMOVE_COMPARE_ROOT" == xtrue ]; then ohair@425: rm -rf $REMOVE_COMPARE_ROOT ohair@425: fi ohair@425: ohair@425: exit 1 ohair@425: