|
1 #!/bin/bash |
|
2 # |
|
3 # Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. |
|
4 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
5 # |
|
6 # This code is free software; you can redistribute it and/or modify it |
|
7 # under the terms of the GNU General Public License version 2 only, as |
|
8 # published by the Free Software Foundation. |
|
9 # |
|
10 # This code is distributed in the hope that it will be useful, but WITHOUT |
|
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
12 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
13 # version 2 for more details (a copy is included in the LICENSE file that |
|
14 # accompanied this code). |
|
15 # |
|
16 # You should have received a copy of the GNU General Public License version |
|
17 # 2 along with this work; if not, write to the Free Software Foundation, |
|
18 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
19 # |
|
20 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
21 # or visit www.oracle.com if you need additional information or have any |
|
22 # questions. |
|
23 # |
|
24 |
|
25 # Simple tool to diff two jar or zip files. It unpacks the jar/zip files and |
|
26 # reports if files differs and if files are new or missing. |
|
27 # Assumes gnu diff. |
|
28 |
|
29 # There are a few source files that have DOS line endings in the |
|
30 # jaxp/jaxws source drops, when the sources were added to the repository |
|
31 # the source files were converted to UNIX line endings. |
|
32 # For now we ignore these differences. |
|
33 DIFF_FLAGS="--strip-trailing-cr" |
|
34 #set -x |
|
35 |
|
36 if [ $# -lt 2 ] |
|
37 then |
|
38 echo "Diff two jar/zip files. Return codes: 0 - no diff, 1 - diff, 2 - couldn't perform diff" |
|
39 echo "Syntax: $0 old_archive new_archive [old_root new_root]" |
|
40 exit 2 |
|
41 fi |
|
42 |
|
43 if [ ! -f $1 ] |
|
44 then |
|
45 echo $1 does not exist |
|
46 exit 2 |
|
47 fi |
|
48 |
|
49 if [ ! -f $2 ] |
|
50 then |
|
51 echo $2 does not exist |
|
52 exit 2 |
|
53 fi |
|
54 |
|
55 IGNORES="cat" |
|
56 OLD=$(cd $(dirname $1) && pwd)/$(basename $1) |
|
57 NEW=$(cd $(dirname $2) && pwd)/$(basename $2) |
|
58 |
|
59 if [ $# -gt 3 ] |
|
60 then |
|
61 ROOT1=$(cd $3 && pwd) |
|
62 ROOT2=$(cd $4 && pwd) |
|
63 OLD_NAME=$(echo $OLD | sed "s|$ROOT1/||") |
|
64 NEW_NAME=$(echo $NEW | sed "s|$ROOT2/||") |
|
65 if [ $# == 5 ]; then IGNORES="$5"; fi |
|
66 else |
|
67 ROOT1=$(dirname $OLD)/ |
|
68 ROOT2=$(dirname $NEW)/ |
|
69 OLD_NAME=$OLD |
|
70 NEW_NAME=$NEW |
|
71 if [ $# == 3 ]; then IGNORES="$3"; fi |
|
72 fi |
|
73 |
|
74 if [ "`uname`" == "SunOS" ]; then |
|
75 DIFF=gdiff |
|
76 else |
|
77 DIFF=diff |
|
78 fi |
|
79 |
|
80 OLD_SUFFIX="${OLD##*.}" |
|
81 NEW_SUFFIX="${NEW##*.}" |
|
82 if [ "$OLD_SUFFIX" != "$NEW_SUFFIX" ]; then |
|
83 echo The files do not have the same suffix type! |
|
84 exit 2 |
|
85 fi |
|
86 |
|
87 if [ "$OLD_SUFFIX" != "zip" ] && [ "$OLD_SUFFIX" != "jar" ]; then |
|
88 echo The files have to be zip or jar! They are $OLD_SUFFIX |
|
89 exit 2 |
|
90 fi |
|
91 |
|
92 UNARCHIVE="unzip -q" |
|
93 |
|
94 TYPE="$OLD_SUFFIX" |
|
95 |
|
96 if cmp $OLD $NEW > /dev/null |
|
97 then |
|
98 # The files were bytewise identical. |
|
99 exit 0 |
|
100 fi |
|
101 |
|
102 # Not quite identical, the might still contain the same data. |
|
103 # Unpack the jar/zip files in temp dirs |
|
104 if test "x$COMPARE_ROOT" == "x"; then |
|
105 COMPARE_ROOT=/tmp/compare_root.$$ |
|
106 REMOVE_COMPARE_ROOT=true |
|
107 fi |
|
108 OLD_TEMPDIR=$COMPARE_ROOT/$OLD_NAME.old |
|
109 NEW_TEMPDIR=$COMPARE_ROOT/$NEW_NAME.new |
|
110 mkdir -p $OLD_TEMPDIR |
|
111 mkdir -p $NEW_TEMPDIR |
|
112 (cd $OLD_TEMPDIR && rm -rf * ; $UNARCHIVE $OLD) |
|
113 (cd $NEW_TEMPDIR && rm -rf * ; $UNARCHIVE $NEW) |
|
114 |
|
115 ONLY1=$(LANG=C $DIFF -rq $OLD_TEMPDIR $NEW_TEMPDIR | grep "^Only in $OLD_TEMPDIR") |
|
116 |
|
117 if [ -n "$ONLY1" ]; then |
|
118 echo " Only the OLD $OLD_NAME contains:" |
|
119 LANG=C $DIFF -rq $DIFF_FLAGS $OLD_TEMPDIR $NEW_TEMPDIR | grep "^Only in $OLD_TEMPDIR" \ |
|
120 | sed "s|Only in $OLD_TEMPDIR| |"g | sed 's|: |/|g' |
|
121 fi |
|
122 |
|
123 ONLY2=$(LANG=C $DIFF -rq $OLD_TEMPDIR $NEW_TEMPDIR | grep "^Only in $NEW_TEMPDIR") |
|
124 |
|
125 if [ -n "$ONLY2" ]; then |
|
126 echo " Only the NEW $NEW_NAME contains:" |
|
127 LANG=C $DIFF -rq $DIFF_FLAGS $OLD_TEMPDIR $NEW_TEMPDIR | grep "^Only in $NEW_TEMPDIR" \ |
|
128 | sed "s|Only in $NEW_TEMPDIR| |"g | sed 's|: |/|g' |
|
129 fi |
|
130 |
|
131 DIFFTEXT=`dirname $0`/difftext.sh |
|
132 |
|
133 LANG=C $DIFF -rq $DIFF_FLAGS $OLD_TEMPDIR $NEW_TEMPDIR | grep differ | cut -f 2,4 -d ' ' | \ |
|
134 awk "{ print \"$DIFFTEXT \"\$1\" \"\$2 }" > $COMPARE_ROOT/diffing |
|
135 |
|
136 /bin/bash $COMPARE_ROOT/diffing > $COMPARE_ROOT/diffs |
|
137 |
|
138 if [ -s "$COMPARE_ROOT/diffs" ]; then |
|
139 echo " Differing files in $OLD_NAME" |
|
140 cat $COMPARE_ROOT/diffs | grep differ | $IGNORES | cut -f 2 -d ' ' | \ |
|
141 sed "s|$OLD_TEMPDIR| |g" |
|
142 fi |
|
143 |
|
144 # Clean up |
|
145 |
|
146 if [ "x$REMOVE_COMPARE_ROOT" == xtrue ]; then |
|
147 rm -rf $REMOVE_COMPARE_ROOT |
|
148 fi |
|
149 |
|
150 exit 1 |
|
151 |