Creating tools to aid in ONOS release process.

Change-Id: I6fba9c6cfbd943fead7005fa09eba2d7af6ac821
diff --git a/tools/build/onos-build-docs b/tools/build/onos-build-docs
index 861582a..fcdd3f7 100755
--- a/tools/build/onos-build-docs
+++ b/tools/build/onos-build-docs
@@ -1,6 +1,6 @@
 #!/bin/bash
 # -----------------------------------------------------------------------------
-# Builds the ONOS from source.
+# Builds the ONOS Java API docs.
 # -----------------------------------------------------------------------------
 
 [ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1
diff --git a/tools/build/onos-change-version b/tools/build/onos-change-version
new file mode 100755
index 0000000..0bba6cd
--- /dev/null
+++ b/tools/build/onos-change-version
@@ -0,0 +1,36 @@
+#!/bin/bash
+# -----------------------------------------------------------------------------
+# Changes ONOS version in POM files, and other release artifacts.
+# -----------------------------------------------------------------------------
+
+[ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1
+. $ONOS_ROOT/tools/build/envDefaults
+
+export NEW_VERSION=$1
+[ -z "$NEW_VERSION" ] && echo "New ONOS version not specified" && exit 1
+
+export NEW_VERSION_SHORT=${NEW_VERSION%-SNAPSHOT}
+
+cd $ONOS_ROOT
+
+# Augment the version of the main pom and the modules nested underneath.
+mvn versions:set -DnewVersion=$NEW_VERSION versions:commit
+
+# Augment the version of the Java API pom files and the overview.html file.
+for pom in docs/pom.xml docs/external.xml; do
+    sed -i "" -E "1,/<version>/s/<version>[^<]*</<version>$NEW_VERSION</g" $pom
+    sed -i "" -E "1,/<doctitle>/s/<doctitle>ONOS Java API[^<]*</<doctitle>ONOS Java API ($NEW_VERSION)</g" $pom
+done
+
+# Augment the version in envDefaults, onos.py and archetypes test
+sed -i "" -E "s/ONOS_VERSION:-[^$]*/ONOS_VERSION:-$NEW_VERSION_SHORT./" $ONOS_ROOT/tools/build/envDefaults
+sed -i "" -E "s/features\/.*\/xml/features\/$NEW_VERSION\/xml/" $ONOS_ROOT/tools/test/topos/onos.py
+sed -i "" -E "s/ -Dversion=.*\"/ -Dversion=$NEW_VERSION\"/" $ONOS_ROOT/tools/test/bin/onos-archetypes-test
+
+# Augment the version in archetypes tree.
+mvn -f tools/package/archetypes/pom.xml versions:set -DnewVersion=$NEW_VERSION versions:commit
+for atype in api bundle cli; do
+    pom="tools/package/archetypes/$atype/src/main/resources/archetype-resources/pom.xml"
+    sed -i "" -E "1,/<onos.version>/s/<onos.version>[^<]*</<onos.version>$NEW_VERSION</g" $pom
+done
+
diff --git a/tools/build/onos-release b/tools/build/onos-release
new file mode 100755
index 0000000..9cb25a3
--- /dev/null
+++ b/tools/build/onos-release
@@ -0,0 +1,37 @@
+#!/bin/bash
+# -----------------------------------------------------------------------------
+# Drives the ONOS release process.
+# -----------------------------------------------------------------------------
+
+[ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1
+. $ONOS_ROOT/tools/build/envDefaults
+
+export NEW_VERSION=$1
+[ -z "$NEW_VERSION" ] && echo "New ONOS version not specified" && exit 1
+
+export NEW_VERSION_SHORT=${NEW_VERSION%-SNAPSHOT}
+[ "$NEW_VERSION" != "$NEW_VERSION_SHORT" ] && echo "Version is a SNAPSHOT" && exit 1;
+
+cd $ONOS_ROOT
+
+# TODO: Create a new branch for this activity?
+
+# Change the version
+onos-change-version $NEW_VERSION
+
+# Build ONOS & deploy to staging repo using the release profile.
+onos-build && onos-package && mvn -Prelease clean deploy -DskipTests
+
+# Build ONOS docs
+onos-build-docs
+
+# Build ONOS archetypes & deploy to staging repo using the release profile.
+# Note that release of the staging repository is a separate manual step.
+cd tools/package/archetype
+mvn clean install && onos-archetype-test && mvn -Prelease clean deploy
+
+# Commit newly versioned artifacts and issue a tag.
+git commit -a -m"Tagging $NEW_VERSION"
+git tag -sm"Tagging $NEW_VERSION" $NEW_VERSION #signed tag
+
+# TODO: push?
diff --git a/tools/build/onos-snapshot b/tools/build/onos-snapshot
new file mode 100755
index 0000000..10da019
--- /dev/null
+++ b/tools/build/onos-snapshot
@@ -0,0 +1,25 @@
+#!/bin/bash
+# -----------------------------------------------------------------------------
+# Drives the ONOS snapshot process.
+# -----------------------------------------------------------------------------
+
+[ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1
+. $ONOS_ROOT/tools/build/envDefaults
+
+export NEW_VERSION=$1
+[ -z "$NEW_VERSION" ] && echo "New ONOS version not specified" && exit 1
+
+export NEW_VERSION_SHORT=${NEW_VERSION%-SNAPSHOT}
+[ "$NEW_VERSION" = "$NEW_VERSION_SHORT" ] && echo "Version is not a SNAPSHOT" && exit 1;
+
+cd $ONOS_ROOT
+
+# TODO: Create a new branch for this activity?
+
+# Change the version
+onos-change-version $NEW_VERSION
+
+# Commit newly versioned artifacts.
+git commit -a -m"Starting snapshot $NEW_VERSION"
+
+# TODO: push?
diff --git a/tools/build/onos-upload-bits b/tools/build/onos-upload-bits
new file mode 100755
index 0000000..3ac6bd6
--- /dev/null
+++ b/tools/build/onos-upload-bits
@@ -0,0 +1,10 @@
+#!/bin/bash
+# -----------------------------------------------------------------------------
+# Uploads ONOS distributable bits.
+# -----------------------------------------------------------------------------
+
+[ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1
+. $ONOS_ROOT/tools/build/envDefaults
+
+# TODO: upload to EC2
+
diff --git a/tools/build/onos-upload-docs b/tools/build/onos-upload-docs
new file mode 100755
index 0000000..550895e
--- /dev/null
+++ b/tools/build/onos-upload-docs
@@ -0,0 +1,21 @@
+#!/bin/bash
+# -----------------------------------------------------------------------------
+# Uploads ONOS Java API docs.
+# -----------------------------------------------------------------------------
+
+[ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1
+. $ONOS_ROOT/tools/build/envDefaults
+
+user=${1:-jenkins}
+remote=$user@wiki.onosproject.org
+
+scp $ONOS_ROOT/docs/target/onos-apidocs-$ONOS_VERSION.tar.gz $remote:/tmp
+ssh $remote "
+    mkdir -p /var/www/api/$ONOS_VERSION
+    cd /var/www/api/$ONOS_VERSION
+    tar zxf /tmp/onos-apidocs-$ONOS_VERSION.tar.gz
+    mv onos-apidocs-$ONOS_VERSION/* .
+    rm -rf onos-apidocs-$ONOS_VERSION
+
+    # TODO: optionally bump /var/www/api/index.html
+"