Bug 411487 - CBI Build: Build Scout from Tag

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

Corrects publish.sh shell script to truncate nightly folder.

Change-Id: I9f3764cc7886071f8a1bb70a510c4d6e931bbcbd
Reviewed-on: https://git.eclipse.org/r/14769
Reviewed-by: Ken Lee <kle@bsiag.com>
IP-Clean: Ken Lee <kle@bsiag.com>
Tested-by: Ken Lee <kle@bsiag.com>
diff --git a/org.eclipse.scout.maven.plugins.updatesite/publish.sh b/org.eclipse.scout.maven.plugins.updatesite/publish.sh
index fbd8452..05136a5 100644
--- a/org.eclipse.scout.maven.plugins.updatesite/publish.sh
+++ b/org.eclipse.scout.maven.plugins.updatesite/publish.sh
@@ -8,8 +8,7 @@
 repositoriesDir=$workingDir
 stageTriggerFileName=doStage
 
-processZipFile()
-{
+processZipFile() {
   backupDir=$(pwd)
   zipFile=$backupDir"/"${1%?}
   sigOk=$2
@@ -21,7 +20,7 @@
     chmod -R g+w $stagingArea/working
 
     cd $stagingArea/working
-      for d in {[0-9\.]*,nightly,releases}
+    for d in {[0-9\.]*,nightly,releases}
      do
         if [ -d "$d" ]; then
            if  [ -d  $repositoriesDir/$d""_new ]; then
@@ -41,33 +40,50 @@
         fi
      done
 
-	truncateNightly $workingDir/nightly
+    truncateNightly $workingDir/nightly
 
-     #cleanup stagingArea
-     cp  $stagingArea/working/*.xml $repositoriesDir/
-     rm -rf $stagingArea/working
+    #cleanup stagingArea
+    cp  $stagingArea/working/*.xml $repositoriesDir/
+    rm -rf $stagingArea/working
     cd $backupDir
   else
     echo "md5 not valid for $zipFile!"
   fi
 }
 
-## remove old nightly repositories that are not contained in the composite updateiste
-truncateNightly(){
+## remove old nightly repositories that are not contained in the composite update site
+truncateNightly() {
 	cur=$(pwd)
 	dir=$1
+	echo "Current dir: ${cur}."
+	echo "Recursively truncate dir: ${dir}."
 	cd ${dir}
 	for d in *
 	do
 		if [ -d "$d" ]; then
-			truncateComposite "$d"
+			echo -e "\nTruncating Scout ${d} composite dir"
+			truncateScoutVersion "$d"
 		fi
-    done
+  done
 	cd ${cur}
 }
 
-# removes all folders starting with N that are not contained in the compositeContent.jar
-truncateComposite(){
+## removes sub folders starting with scout of a specific Scout version, e.g. scout.main, scout.rap
+truncateScoutVersion() {
+  curdir=$1
+  pushd ${curdir} > /dev/null
+  for dir in scout*
+  do
+    if [ -d "$dir" ]; then
+      echo -e "\t\tTruncating composite dir ${dir}"
+      truncateComposite "$dir"
+    fi
+  done
+  popd > /dev/null
+}
+
+## removes all folders starting with N that are not contained in the compositeContent.jar
+truncateComposite() {
 	cur=$(pwd)
 	compositeDir=$1
 
@@ -75,10 +91,11 @@
 	unzip -q compositeContent.jar
 		for sub in N*
 			do
+				echo -e "\t\t\tChecking nightly dir ${sub}"
 				if [ -d "$sub" ]; then
 					if ! (grep -q "$sub" compositeContent.xml);
 						then
-							echo "$sub is not contained in composite. Removing..";
+							echo -e "\t\t\t\t$sub is not contained in composite. Removing...";
 							rm -rf $sub
 					fi
 				fi