Bug 411487 - CBI Build: Build Scout from Tag

https://bugs.eclipse.org/bugs/show_bug.cgi?id=411487

Updates shell scripts to enable builds from a specific tag.

Change-Id: I0db8f9224fbbf535fe46e7fcbbcfd9591a7c6636
Reviewed-on: https://git.eclipse.org/r/14219
Reviewed-by: Ken Lee <kle@bsiag.com>
IP-Clean: Ken Lee <kle@bsiag.com>
Tested-by: Ken Lee <kle@bsiag.com>
diff --git a/checkoutToBranch.sh b/checkoutToBranch.sh
index 9e10f77..939e2cf 100755
--- a/checkoutToBranch.sh
+++ b/checkoutToBranch.sh
@@ -1,11 +1,82 @@
+LOCAL_BRANCH=$1
+BUILD_FROM_TAG=$2
+REMOTE_BRANCH=$3
+FALLBACK_BRANCH=$4
+ROOT_PATH=$5
+SCOUT_SUBMODULE=0
+CHECKOUT_SUCCESSFUL=0
+
+function isScoutSubmodule()
+{
+	SCOUT_SUBMODULE=0
+	if [ ! -z $(pwd | grep $ROOT_PATH/org.eclipse.scout) ]; then
+		SCOUT_SUBMODULE=1
+	fi
+}
+
+function buildFromTag()
+{
+	local tag=$1
+	local localbranch=$1
+	local remotebranch=$2
+	git fetch --tags
+	git show-ref --tags --verify --quiet refs/tags/$tag
+	if [ $? -eq 0 ]; then
+		git checkout $tag
+	else
+		checkoutLocalOrRemoteBranch $localbranch $remotebranch
+	fi
+}
+
+function checkoutLocalBranch()
+{
+	local localbranch=$1
+	local remotebranch=$2
+	
+	CHECKOUT_SUCCESSFUL=0
+	if [ ! -z "$(git branch | grep $localbranch)" ]; then
+		git checkout $localbranch
+		git pull origin $remotebranch
+		CHECKOUT_SUCCESSFUL=1
+	fi
+}
+
+function checkoutRemoteBranch()
+{
+	local localbranch=$1
+	local remotebranch=$2
+
+	CHECKOUT_SUCCESSFUL=0	
+	if [ ! -z "$(git branch -r | grep origin/$remotebranch)" ]; then
+		git checkout -b $localbranch origin/$remotebranch
+		git pull origin $remotebranch
+		CHECKOUT_SUCCESSFUL=1
+	fi
+}
+
+function checkoutLocalOrRemoteBranch()
+{
+	local localbranch=$1
+	local remotebranch=$2
+	
+	CHECKOUT_SUCCESSFUL=0
+	checkoutLocalBranch $localbranch $remotebranch
+	
+	if [ $CHECKOUT_SUCCESSFUL -eq 0 ]; then
+		checkoutRemoteBranch $localbranch $remotebranch
+	fi
+}
+
 git rm --cached -r . > /dev/null
 git reset --hard > /dev/null
-git show-branch $1
-if [ "$?" = "0" ]; then
-	git checkout $1
+
+isScoutSubmodule
+if [ $SCOUT_SUBMODULE -eq 1 ]; then
+	if [ $BUILD_FROM_TAG == "true" ]; then
+		buildFromTag $LOCAL_BRANCH $REMOTE_BRANCH
+	else
+		checkoutLocalOrRemoteBranch $LOCAL_BRANCH $REMOTE_BRANCH
+	fi
 else
-	git checkout master
-fi
-if $2; then
-	git pull
+	checkoutLocalOrRemoteBranch $FALLBACK_BRANCH $FALLBACK_BRANCH
 fi
\ No newline at end of file
diff --git a/org.eclipse.cbi.maven.plugins b/org.eclipse.cbi.maven.plugins
index 159e888..ae5d149 160000
--- a/org.eclipse.cbi.maven.plugins
+++ b/org.eclipse.cbi.maven.plugins
@@ -1 +1 @@
-Subproject commit 159e888408dbfa8fe3d5eea8b91dd8dbc2112a0e
+Subproject commit ae5d14938b5b0ba78c7ba232c4b88d3752df9ebb
diff --git a/org.eclipse.scout.rt b/org.eclipse.scout.rt
index 29a7cca..9cc8a4b 160000
--- a/org.eclipse.scout.rt
+++ b/org.eclipse.scout.rt
@@ -1 +1 @@
-Subproject commit 29a7cca7568ce521e53820d3a40c5a1dd98fd0d1
+Subproject commit 9cc8a4b3f5cc6565a5800470bbfa8dac27d4b9e0
diff --git a/updateSubmodules.sh b/updateSubmodules.sh
index 6a205d6..84b1eae 100755
--- a/updateSubmodules.sh
+++ b/updateSubmodules.sh
@@ -1,6 +1,24 @@
 #!/bin/sh
-ROOT_PATH=`pwd`
-BRANCH=$(expr "$1" \| "master")
-PULL=$(expr "$2" \| "true")
+ROOT_PATH=`dirname $(readlink -f $0)`
+LOCAL_BRANCH="develop"
+BUILD_FROM_TAG="false"
+REMOTE_BRANCH="develop"
+FALLBACK_BRANCH="master"
 
-git submodule foreach "('$ROOT_PATH/checkoutToBranch.sh' $BRANCH $PULL)"
\ No newline at end of file
+if [ ! -z "$1" ]; then
+	LOCAL_BRANCH=$1
+fi
+
+if [ ! -z "$2" ]; then
+	BUILD_FROM_TAG=$2
+fi
+
+if [ ! -z "$3" ]; then
+	REMOTE_BRANCH=$3
+fi
+
+if [ ! -z "$4" ]; then
+	FALLBACK_BRANCH=$4
+fi
+
+git submodule foreach --recursive "('$ROOT_PATH/checkoutToBranch.sh' $LOCAL_BRANCH $BUILD_FROM_TAG $REMOTE_BRANCH $FALLBACK_BRANCH $ROOT_PATH)"