brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sjcorb...@apache.org
Subject [1/3] incubator-brooklyn git commit: Improve change-version.sh script
Date Thu, 22 Jan 2015 14:53:39 GMT
Repository: incubator-brooklyn
Updated Branches:
  refs/heads/master c563e653a -> a850f450a


Improve change-version.sh script

* Remove the usage of pcregrep which is not installed by default on OS X or Linux.
* Support for passing the version marker as an argument.
* Simplify the code, no need for loops.


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

Branch: refs/heads/master
Commit: c32c7b4b841f229da5c683f2289bd0ddd379bdfa
Parents: fe42507
Author: Svetoslav Neykov <svetoslav.neykov@cloudsoftcorp.com>
Authored: Wed Jan 21 16:14:54 2015 +0200
Committer: Svetoslav Neykov <svetoslav.neykov@cloudsoftcorp.com>
Committed: Wed Jan 21 16:14:54 2015 +0200

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


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c32c7b4b/usage/scripts/change-version.sh
----------------------------------------------------------------------
diff --git a/usage/scripts/change-version.sh b/usage/scripts/change-version.sh
index c257ff3..c338dd8 100755
--- a/usage/scripts/change-version.sh
+++ b/usage/scripts/change-version.sh
@@ -18,8 +18,7 @@
 # under the License.
 #
 
-# changes the BROOKLYN version everywhere
-
+# changes the version everywhere
 # usage, e.g.:  change-version.sh 0.3.0-SNAPSHOT 0.3.0-RC1
 
 [ -d .git ] || {
@@ -27,62 +26,31 @@
   exit 1
 }
 
-[[ -z "$3" && ! -z "$2" ]] || {
-  echo "Usage:  "$0" CURRENT_VERSION NEW_VERSION"
-  echo " e.g.:  "$0" 0.3.0-SNAPSHOT 0.3.0-RC1"
+if [ "$#" -eq 2 ]; then
+  VERSION_MARKER=BROOKLYN_VERSION
+elif [ "$#" -eq 3 ]; then
+  VERSION_MARKER=$1_VERSION
+  shift;
+else
+  echo "Usage:  "$0" [VERSION_MARKER] CURRENT_VERSION NEW_VERSION"
+  echo " e.g.:  "$0" BROOKLYN 0.3.0-SNAPSHOT 0.3.0-RC1"
   exit 1
-}
+fi
 
 # remove binaries and stuff
-if [[ -f pom.xml ]] ; then mvn clean ; fi
-
-LABEL1=BROOKLYN_VERSION
-LABEL2=BROOKLYN_VERSION_BELOW
+if [ -f pom.xml ] && [ -d target ] ; then mvn clean ; fi
 
+VERSION_MARKER_NL=${VERSION_MARKER}_BELOW
 CURRENT_VERSION=$1
 NEW_VERSION=$2
 
-# exclude dot files, and exclude log, war, and .min.js files
-# TODO not sure if the \/\..+ is needed
-GREP_ARGS="-r -l --exclude_dir=^\..+|\/\..+ --exclude=.*\.(log|war|min.js)"
-
-# look for lines (where we can put the literal $LABEL1 in an inline comment) matching
-# ... ${CURRENT_VERSION} ... BROOKLYN_VERSION
-# Repeatedly replace, until no more occurrences of current_version.*label
-
-# search for every file containing LABEL1
-FILES1=`pcregrep $GREP_ARGS "${CURRENT_VERSION}.*${LABEL1}" .`
-for x in $FILES1 ; do
-  while grep --quiet -E "${CURRENT_VERSION}.*${LABEL1}" $x; do
-    sed -i .bak "s/${CURRENT_VERSION}\(.*\)${LABEL1}/${NEW_VERSION}\1${LABEL1}/" $x
-  done
-done
-
-echo "One-line pattern with label after changed these files: $FILES1"
-
-# search for every file containing LABEL1
-FILES1=`pcregrep $GREP_ARGS "${LABEL1}.*${CURRENT_VERSION}" .`
-for x in $FILES1 ; do
-  while grep --quiet -E "${LABEL1}.*${CURRENT_VERSION}" $x; do
-    sed -i .bak "s/${LABEL1}\(.*\)${CURRENT_VERSION}/${LABEL1}\1${NEW_VERSION}/" $x
-  done
-done
-
-echo "One-line pattern with label before changed these files: $FILES1"
-
-# or two-lines for situations where comments must be entire-line (e.g. scripts)
-# put the comment on the line before the version
-# using sed as per http://blog.ergatides.com/2012/01/24/using-sed-to-search-and-replace-contents-of-next-line-in-a-file/
-# to match:
-# ... BROOKLYN_VERSION_BELOW ...
-# ... ${CURRENT_VERSION} ...
-
-FILES2=`pcregrep $GREP_ARGS -M "${LABEL2}.*\n.*${CURRENT_VERSION}" .`
-for x in $FILES2 ; do
-  sed -i .bak -e '/'"${LABEL2}"'/{n;s/'"${CURRENT_VERSION}"'/'"${NEW_VERSION}"'/g;}' $x
-done
+# exclude dot files, and exclude log, war, etc. files
+GREP_ARGS='-r -l --exclude-dir=^\. --exclude=\.(log|war|min.js|min.css)$'
 
-echo "Two-line pattern changed these files: $FILES2"
+# search for files containing version markers
+FILES=`grep $GREP_ARGS "${VERSION_MARKER}\|${VERSION_MARKER_NL}" .`
+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
 
-echo "Changed ${CURRENT_VERSION} to ${NEW_VERSION} for "`echo $FILES1 $FILES2 | wc | awk
'{print $2}'`" files"
+echo "Changed ${CURRENT_VERSION} to ${NEW_VERSION} for "`echo $FILES | wc | awk '{print $2}'`"
files"
 echo "(Do a \`find . -name \"*.bak\" -delete\`  to delete the backup files.)"


Mime
View raw message