common/bin/diffjarzip.sh

Tue, 03 Jul 2012 16:11:12 -0700

author
erikj
date
Tue, 03 Jul 2012 16:11:12 -0700
changeset 458
c8d320b48626
parent 445
efd26e051e50
permissions
-rw-r--r--

7181504: Update of latest build-infra Makefiles
Reviewed-by: ohair

     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 #
    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.
    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
    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
    43 if [ ! -f $1 ]
    44 then
    45   echo $1 does not exist
    46   exit 2
    47 fi
    49 if [ ! -f $2 ]
    50 then
    51   echo $2 does not exist
    52   exit 2
    53 fi
    55 IGNORES="cat"
    56 OLD=$(cd $(dirname $1) && pwd)/$(basename $1)
    57 NEW=$(cd $(dirname $2) && pwd)/$(basename $2)
    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
    74 if [ "`uname`" == "SunOS" ]; then
    75     if [ -f "`which gdiff`" ]; then
    76         DIFF=gdiff
    77     else
    78         DIFF=diff
    79     fi
    80 else
    81     DIFF=diff
    82 fi
    84 OLD_SUFFIX="${OLD##*.}"
    85 NEW_SUFFIX="${NEW##*.}"
    86 if [ "$OLD_SUFFIX" != "$NEW_SUFFIX" ]; then
    87     echo The files do not have the same suffix type!
    88     exit 2
    89 fi
    91 if [ "$OLD_SUFFIX" != "zip" ] && [ "$OLD_SUFFIX" != "jar" ] && [ "$OLD_SUFFIX" != "sym" ]; then
    92     echo The files have to be zip, jar or sym! They are $OLD_SUFFIX
    93     exit 2
    94 fi
    96 UNARCHIVE="unzip -q"
    98 TYPE="$OLD_SUFFIX"
   100 if cmp $OLD $NEW > /dev/null
   101 then
   102     # The files were bytewise identical.
   103     exit 0
   104 fi
   106 # Not quite identical, the might still contain the same data.
   107 # Unpack the jar/zip files in temp dirs
   108 if test "x$COMPARE_ROOT" == "x"; then
   109     COMPARE_ROOT=/tmp/compare_root.$$
   110     REMOVE_COMPARE_ROOT=true
   111 fi
   112 OLD_TEMPDIR=$COMPARE_ROOT/$OLD_NAME.old
   113 NEW_TEMPDIR=$COMPARE_ROOT/$NEW_NAME.new
   114 mkdir -p $OLD_TEMPDIR
   115 mkdir -p $NEW_TEMPDIR
   116 (cd $OLD_TEMPDIR && rm -rf * ; $UNARCHIVE $OLD)
   117 (cd $NEW_TEMPDIR && rm -rf * ; $UNARCHIVE $NEW)
   119 ONLY1=$(LANG=C $DIFF -rq $OLD_TEMPDIR $NEW_TEMPDIR | grep "^Only in $OLD_TEMPDIR")
   121 if [ -n "$ONLY1" ]; then
   122     echo "        Only the OLD $OLD_NAME contains:"
   123     LANG=C $DIFF -rq $DIFF_FLAGS $OLD_TEMPDIR $NEW_TEMPDIR | grep "^Only in $OLD_TEMPDIR" \
   124         | sed "s|Only in $OLD_TEMPDIR|            |"g | sed 's|: |/|g'
   125 fi
   127 ONLY2=$(LANG=C $DIFF -rq $OLD_TEMPDIR $NEW_TEMPDIR | grep "^Only in $NEW_TEMPDIR")
   129 if [ -n "$ONLY2" ]; then
   130     echo "        Only the NEW $NEW_NAME contains:"
   131     LANG=C $DIFF -rq $DIFF_FLAGS $OLD_TEMPDIR $NEW_TEMPDIR | grep "^Only in $NEW_TEMPDIR" \
   132         | sed "s|Only in $NEW_TEMPDIR|            |"g | sed 's|: |/|g'
   133 fi
   135 DIFFTEXT="/bin/bash `dirname $0`/difftext.sh"
   137 LANG=C $DIFF -rq $DIFF_FLAGS $OLD_TEMPDIR $NEW_TEMPDIR | grep differ | cut -f 2,4 -d ' ' | \
   138    awk "{ print \"$DIFFTEXT \"\$1\" \"\$2 }" > $COMPARE_ROOT/diffing
   140 /bin/bash $COMPARE_ROOT/diffing > $COMPARE_ROOT/diffs
   142 if [ -s "$COMPARE_ROOT/diffs" ]; then
   143    echo "        Differing files in $OLD_NAME"
   144    cat $COMPARE_ROOT/diffs | grep differ | $IGNORES | cut -f 2 -d ' ' | \
   145           sed "s|$OLD_TEMPDIR|            |g"
   146 fi
   148 # Clean up
   150 if [ "x$REMOVE_COMPARE_ROOT" == xtrue ]; then
   151     rm -rf $REMOVE_COMPARE_ROOT
   152 fi
   154 exit 1

mercurial