annotate bin/unshuffle_patch.sh @ 47945:49e605998d2b

8191313: Deprecate RMIConnectorServer.CREDENTIAL_TYPES Summary: Deprecated RMIConnectorServer.CREDENTIAL_TYPES Reviewed-by: rriggs, dfuchs Contributed-by: ujwal.vangapally@oracle.com
author uvangapally
date Tue, 21 Nov 2017 01:25:36 -0800
parents 71c04702a3d5
children
rev   line source
erikj@47217 1 #!/bin/bash
chegar@25854 2 #
erikj@47217 3 # Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
chegar@25854 4 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
chegar@25854 5 #
chegar@25854 6 # This code is free software; you can redistribute it and/or modify it
chegar@25854 7 # under the terms of the GNU General Public License version 2 only, as
chegar@25854 8 # published by the Free Software Foundation.
chegar@25854 9 #
chegar@25854 10 # This code is distributed in the hope that it will be useful, but WITHOUT
chegar@25854 11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
chegar@25854 12 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
chegar@25854 13 # version 2 for more details (a copy is included in the LICENSE file that
chegar@25854 14 # accompanied this code).
chegar@25854 15 #
chegar@25854 16 # You should have received a copy of the GNU General Public License version
chegar@25854 17 # 2 along with this work; if not, write to the Free Software Foundation,
chegar@25854 18 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
chegar@25854 19 #
chegar@25854 20 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
chegar@25854 21 # or visit www.oracle.com if you need additional information or have any
chegar@25854 22 # questions.
chegar@25854 23 #
chegar@25854 24
chegar@25854 25 # Script for updating a patch file as per the shuffled/unshuffled source location.
chegar@25854 26
chegar@25854 27 usage() {
erikj@47217 28 echo "Usage: $0 [-h|--help] [-v|--verbose] [-to9|-to10] [-r <repo>] <input_patch> <output_patch>"
erikj@47217 29 echo "where:"
erikj@47217 30 echo " -to9 create patches appropriate for a JDK 9 source tree"
erikj@47217 31 echo " When going to 9, the output patches will be suffixed with the"
erikj@47217 32 echo " repo name"
erikj@47217 33 echo " -to10 create patches appropriate for a JDK 10 source tree"
erikj@47217 34 echo " -r <repo> specify repo for source patch, set to 'top' for top repo"
erikj@47217 35 echo " <input_patch> is the input patch file, that needs shuffling/unshuffling"
erikj@47217 36 echo " <output_patch> is the updated patch file "
erikj@47217 37 echo " "
erikj@47217 38 exit 1
chegar@25854 39 }
chegar@25854 40
igerasim@26674 41 SCRIPT_DIR=`dirname $0`
chegar@25854 42 UNSHUFFLE_LIST=$SCRIPT_DIR"/unshuffle_list.txt"
chegar@25854 43
chegar@25854 44 if [ ! -f "$UNSHUFFLE_LIST" ] ; then
igerasim@26674 45 echo "FATAL: cannot find $UNSHUFFLE_LIST" >&2
chegar@25854 46 exit 1
chegar@25854 47 fi
chegar@25854 48
chegar@25854 49 vflag="false"
chegar@25854 50 while [ $# -gt 0 ]
chegar@25854 51 do
chegar@25854 52 case $1 in
chegar@25854 53 -h | --help )
chegar@25854 54 usage
chegar@25854 55 ;;
chegar@25854 56
chegar@25854 57 -v | --verbose )
chegar@25854 58 vflag="true"
chegar@25854 59 ;;
chegar@25854 60
erikj@47217 61 -r)
erikj@47217 62 repo="$2"
erikj@47217 63 shift
erikj@47217 64 ;;
erikj@47217 65
erikj@47217 66 -to9)
erikj@47217 67 shuffle_to=9
erikj@47217 68 ;;
erikj@47217 69
erikj@47217 70 -to10)
erikj@47217 71 shuffle_to=10
erikj@47217 72 ;;
erikj@47217 73
chegar@25854 74 -*) # bad option
chegar@25854 75 usage
chegar@25854 76 ;;
chegar@25854 77
erikj@47217 78 * ) # non option
chegar@25854 79 break
chegar@25854 80 ;;
chegar@25854 81 esac
chegar@25854 82 shift
chegar@25854 83 done
chegar@25854 84
chegar@25854 85 # Make sure we have the right number of arguments
erikj@47217 86 if [ ! $# -eq 2 ] ; then
igerasim@26674 87 echo "ERROR: Invalid number of arguments." >&2
chegar@25854 88 usage
chegar@25854 89 fi
chegar@25854 90
chegar@25854 91 # Check the given repo
erikj@47217 92 repos="top corba jaxp jaxws jdk langtools nashorn hotspot"
chegar@25854 93 found="false"
erikj@47217 94 if [ -n "$repo" ]; then
erikj@47217 95 for r in $repos ; do
erikj@47217 96 if [ $repo = "$r" ] ; then
erikj@47217 97 found="true"
erikj@47217 98 break;
erikj@47217 99 fi
erikj@47217 100 done
erikj@47217 101 if [ $found = "false" ] ; then
erikj@47217 102 echo "ERROR: Unknown repo: $repo. Should be one of [$repos]." >&2
erikj@47217 103 usage
ihse@27595 104 fi
erikj@47217 105 fi
erikj@47217 106
erikj@47217 107 if [ "$shuffle_to" != "9" -a "$shuffle_to" != "10" ]; then
erikj@47217 108 echo "ERROR: Must pick either -to9 or -to10"
erikj@47217 109 exit 1
erikj@47217 110 fi
erikj@47217 111
erikj@47217 112 # When going to 10, a repo must be specified for the source patch
erikj@47217 113 if [ "$shuffle_to" = "10" -a -z "$repo" ]; then
erikj@47217 114 echo "ERROR: Must specify src repo for JDK 9 patch"
erikj@47217 115 exit 1
chegar@25854 116 fi
chegar@25854 117
chegar@25854 118 # Check given input/output files
erikj@47217 119 input="$1"
igerasim@26674 120 if [ "x$input" = "x-" ] ; then
igerasim@26674 121 input="/dev/stdin"
igerasim@26674 122 fi
chegar@25854 123
igerasim@26674 124 if [ ! -f $input -a "x$input" != "x/dev/stdin" ] ; then
igerasim@26674 125 echo "ERROR: Cannot find input patch file: $input" >&2
chegar@25854 126 exit 1
chegar@25854 127 fi
chegar@25854 128
erikj@47217 129 output="$2"
igerasim@26674 130 if [ "x$output" = "x-" ] ; then
igerasim@26674 131 output="/dev/stdout"
igerasim@26674 132 fi
erikj@47217 133 base_output="$output"
igerasim@26674 134
erikj@47217 135 if [ "$shuffle_to" = "10" ]; then
erikj@47217 136 if [ -f $output -a "x$output" != "x/dev/stdout" ] ; then
erikj@47217 137 echo "ERROR: Output patch already exists: $output" >&2
erikj@47217 138 exit 1
erikj@47217 139 fi
erikj@47217 140 else
erikj@47217 141 for r in $repos; do
erikj@47217 142 if [ -f "$output.$r" ]; then
erikj@47217 143 echo "ERROR: Output patch already exists: $output.$r" >&2
erikj@47217 144 exit 1
erikj@47217 145 fi
erikj@47217 146 done
chegar@25854 147 fi
chegar@25854 148
chegar@25854 149 verbose() {
chegar@25854 150 if [ ${vflag} = "true" ] ; then
igerasim@26674 151 echo "$@" >&2
chegar@25854 152 fi
chegar@25854 153 }
chegar@25854 154
chegar@25854 155 unshuffle() {
chegar@25854 156 line=$@
chegar@25854 157 verbose "Attempting to rewrite: \"$line\""
chegar@25854 158
chegar@25854 159 # Retrieve the file name
chegar@25854 160 path=
chegar@25854 161 if echo "$line" | egrep '^diff' > /dev/null ; then
chegar@25854 162 if ! echo "$line" | egrep '\-\-git' > /dev/null ; then
igerasim@26674 163 echo "ERROR: Only git patches supported. Please use 'hg export --git ...'." >&2
chegar@25854 164 exit 1
chegar@25854 165 fi
chegar@25854 166 path="`echo "$line" | sed -e s@'diff --git a/'@@ -e s@' b/.*$'@@`"
chegar@25854 167 elif echo "$line" | egrep '^\-\-\-' > /dev/null ; then
chegar@25854 168 path="`echo "$line" | sed -e s@'--- a/'@@`"
chegar@25854 169 elif echo "$line" | egrep '^\+\+\+' > /dev/null ; then
chegar@25854 170 path="`echo "$line" | sed s@'+++ b/'@@`"
chegar@25854 171 fi
chegar@25854 172 verbose "Extracted path: \"$path\""
chegar@25854 173
chegar@25854 174 # Find the most specific matches in the shuffle list
chegar@25854 175 matches=
erikj@47217 176 if [ -n "$repo" -a "$repo" != "top" ]; then
erikj@47217 177 matchpath="$repo"/"$path"/x
erikj@47217 178 else
erikj@47217 179 matchpath="$path"/x
erikj@47217 180 fi
chegar@25854 181 while [ "$matchpath" != "" ] ; do
chegar@25854 182 matchpath="`echo $matchpath | sed s@'\(.*\)/.*$'@'\1'@`"
chegar@25854 183
erikj@47217 184 if [ "$shuffle_to" = "10" ] ; then
chegar@25854 185 pattern=": $matchpath$"
chegar@25854 186 else
chegar@25854 187 pattern="^$matchpath :"
chegar@25854 188 fi
chegar@25854 189 verbose "Attempting to find \"$matchpath\""
chegar@25854 190 matches=`egrep "$pattern" "$UNSHUFFLE_LIST"`
chegar@25854 191 if ! [ "x${matches}" = "x" ] ; then
chegar@25854 192 verbose "Got matches: [$matches]"
chegar@25854 193 break;
chegar@25854 194 fi
chegar@25854 195
chegar@25854 196 if ! echo "$matchpath" | egrep '.*/.*' > /dev/null ; then
chegar@25854 197 break;
chegar@25854 198 fi
chegar@25854 199 done
chegar@25854 200
chegar@25854 201 # Rewrite the line, if we have a match
chegar@25854 202 if ! [ "x${matches}" = "x" ] ; then
erikj@47217 203 shuffled="${matches%% : *}"
erikj@47217 204 unshuffled="${matches#* : }"
erikj@47217 205 patch_suffix_9=""
erikj@47217 206 for r in $repos; do
erikj@47217 207 if [ "$unshuffled" != "${unshuffled#$r}" ]; then
erikj@47217 208 unshuffled="${unshuffled#$r\/}"
erikj@47217 209 patch_suffix_9=".$r"
erikj@47217 210 fi
erikj@47217 211 done
erikj@47217 212 verbose "shuffled: $shuffled"
erikj@47217 213 verbose "unshuffled: $unshuffled"
erikj@47217 214 verbose "patch_suffix_9: $patch_suffix_9"
erikj@47217 215 if [ "$shuffle_to" = "10" ] ; then
chegar@25854 216 newline="`echo "$line" | sed -e s@"$unshuffled"@"$shuffled"@g`"
chegar@25854 217 else
chegar@25854 218 newline="`echo "$line" | sed -e s@"$shuffled"@"$unshuffled"@g`"
erikj@47217 219 output=$base_output$patch_suffix_9
erikj@47217 220 verbose "Writing to $output"
chegar@25854 221 fi
chegar@25854 222 verbose "Rewriting to \"$newline\""
chegar@25854 223 echo "$newline" >> $output
chegar@25854 224 else
chegar@25854 225 echo "WARNING: no match found for $path"
chegar@25854 226 echo "$line" >> $output
chegar@25854 227 fi
chegar@25854 228 }
chegar@25854 229
chegar@25854 230 while IFS= read -r line
chegar@25854 231 do
chegar@25854 232 if echo "$line" | egrep '^diff|^\-\-\-|^\+\+\+' > /dev/null ; then
chegar@25854 233 unshuffle "$line"
chegar@25854 234 else
chegar@25854 235 printf "%s\n" "$line" >> $output
chegar@25854 236 fi
chegar@25854 237 done < "$input"