[DCAE-1] Added script to update version in POM. 05/1705/1
authorCarsten Lund <lund@research.att.com>
Mon, 6 Mar 2017 20:55:49 +0000 (20:55 +0000)
committerCarsten Lund <lund@research.att.com>
Mon, 6 Mar 2017 20:55:49 +0000 (20:55 +0000)
Change-Id: I1f6f74602ed5720afd7291ae77236ab0532aa041
Signed-off-by: Carsten Lund <lund@research.att.com>
update-version.sh [new file with mode: 0644]

diff --git a/update-version.sh b/update-version.sh
new file mode 100644 (file)
index 0000000..2d459d0
--- /dev/null
@@ -0,0 +1,51 @@
+#!/bin/bash
+
+## Will update POM in workspace with release version
+
+if [ ! -e version.properties ]; then
+    echo "Missing version.properties"
+    exit 1
+fi
+
+## will setup variable release_version
+source ./version.properties
+
+RELEASE_VERSION=$release_version
+
+echo Changing POM version to $RELEASE_VERSION
+
+## handle POM
+for file in $(find . -name pom.xml); do
+    VERSION=$(xpath -q -e '//project/version/text()' $file)
+    PVERSION=$(xpath -q -e '//project/parent/version/text()' $file)
+    echo before changes VERSION=$VERSION PVERSION=$PVERSION file=$file
+    if [ "$VERSION" != "" ]; then
+        awk -v v=$RELEASE_VERSION '
+            /<version>/ {
+                if (! done) {
+                    sub(/<version>.*</,"<version>" v "<",$0)
+                    done = 1
+                }
+            }
+            { print $0 }
+        ' $file > $file.tmp
+        mv $file.tmp $file
+    fi
+    if [ "$PVERSION" != "" ]; then
+        awk -v v=$RELEASE_VERSION '
+            /<version>/ {
+                if (parent && ! done) {
+                    sub(/<version>.*</,"<version>" v "<",$0)
+                    done = 1
+                }
+            }
+            /<parent>/ { parent = 1 }
+            { print $0 }
+        ' $file > $file.tmp
+        mv $file.tmp $file
+    fi
+    VERSION=$(xpath -q -e '//project/version/text()' $file)
+    PVERSION=$(xpath -q -e '//project/parent/version/text()' $file)
+    echo after changes VERSION=$VERSION PVERSION=$PVERSION file=$file
+done
+