Repository: incubator-brooklyn
Updated Branches:
  refs/heads/master 8489436ae -> 7234b83fd


Make change-versions.sh more resilient.

Support files with spaces, fail-fast, no matching files case.


Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/fc678ab5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/fc678ab5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/fc678ab5

Branch: refs/heads/master
Commit: fc678ab5211a5b7197b7ea8ecf0101b565b5b7b0
Parents: 8489436
Author: Svetoslav Neykov <[email protected]>
Authored: Fri Jan 23 15:05:49 2015 +0200
Committer: Svetoslav Neykov <[email protected]>
Committed: Fri Jan 23 15:35:46 2015 +0200

----------------------------------------------------------------------
 usage/scripts/change-version.sh | 28 +++++++++++++++++++---------
 1 file changed, 19 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/fc678ab5/usage/scripts/change-version.sh
----------------------------------------------------------------------
diff --git a/usage/scripts/change-version.sh b/usage/scripts/change-version.sh
index 0c0dbab..f9f7bc6 100755
--- a/usage/scripts/change-version.sh
+++ b/usage/scripts/change-version.sh
@@ -18,6 +18,8 @@
 # under the License.
 #
 
+set -e
+
 # changes the version everywhere
 # usage, e.g.:  change-version.sh 0.3.0-SNAPSHOT 0.3.0-RC1
 #          or:  change-version.sh MARKER 0.3.0-SNAPSHOT 0.3.0-RC1
@@ -45,16 +47,24 @@ VERSION_MARKER_NL=${VERSION_MARKER}_BELOW
 CURRENT_VERSION=$1
 NEW_VERSION=$2
 
-# grep --exclude-dir working only in recent versions, not on all platforms, 
replace with find
-# skip folders named "ignored" or .xxx (but not the current folder ".")
-# exclude log, war, etc. files
+# grep --exclude-dir working only in recent versions, not on all platforms, 
replace with find;
+# skip folders named "ignored" or .xxx (but not the current folder ".");
+# exclude log, war, etc. files;
+# use null delimiters so files containing spaces are supported;
+# pass /dev/null as the first file to search in, so the command doesn't fail 
if find doesn't match any files;
+# add || true for the case where grep doesn't have matches, so the script 
doesn't halt
+# If there's an error "Argument list too long" add -n20 to xargs arguments and 
loop over $FILE around sed
 FILES=`find . -type d \( -name ignored -or -name .?\* \) -prune \
-       -o -type f -not \( -name \*.log -or -name '*.war' -or -name '*.min.js' 
-or -name '*.min.css' \) -print | \
-       xargs grep -l "${VERSION_MARKER}\|${VERSION_MARKER_NL}"`
+       -o -type f -not \( -name \*.log -or -name '*.war' -or -name '*.min.js' 
-or -name '*.min.css' \) -print0 | \
+       xargs -0 grep -l "${VERSION_MARKER}\|${VERSION_MARKER_NL}" /dev/null || 
true`
+
+FILES_COUNT=`echo $FILES | wc | awk '{print $2}'`
 
-# search for files containing version markers
-sed -i.bak -e "/${VERSION_MARKER}/s/${CURRENT_VERSION}/${NEW_VERSION}/g" $FILES
-sed -i.bak -e "/${VERSION_MARKER_NL}/n;s/${CURRENT_VERSION}/${NEW_VERSION}/g" 
$FILES
+if [ ${FILES_COUNT} -ne 0 ]; then
+    # search for files containing version markers
+    sed -i.bak -e "/${VERSION_MARKER}/s/${CURRENT_VERSION}/${NEW_VERSION}/g" 
$FILES
+    sed -i.bak -e 
"/${VERSION_MARKER_NL}/n;s/${CURRENT_VERSION}/${NEW_VERSION}/g" $FILES
+fi
 
-echo "Changed ${CURRENT_VERSION} to ${NEW_VERSION} for "`echo $FILES | wc | 
awk '{print $2}'`" files"
+echo "Changed ${CURRENT_VERSION} to ${NEW_VERSION} for "${FILES_COUNT}" files"
 echo "(Do a \`find . -name \"*.bak\" -delete\`  to delete the backup files.)"

Reply via email to