Update the publish script to publish composite update sites
diff --git a/org.eclipse.gmf.notation.repository/gmf-notation-hipp-publish.sh b/org.eclipse.gmf.notation.repository/gmf-notation-hipp-publish.sh
index cbc4ff1..71a0286 100644
--- a/org.eclipse.gmf.notation.repository/gmf-notation-hipp-publish.sh
+++ b/org.eclipse.gmf.notation.repository/gmf-notation-hipp-publish.sh
@@ -11,46 +11,46 @@
 # Script may take 5-6 command line parameters:
 # Hudson job name: ${JOB_NAME}
 # Hudson build id: ${BUILD_ID}
+# Hudson workspace: ${WORKSPACE}
 # $1: Build type: n(ightly), m(aintenance), s(table), r(elease)
-# $2: Whether to merge the site with an existing one: (y)es, (n)o
-# $3: Whether to generate udpate-site and SDK drop files: (y)es, (n)o
-# $4: An optional label to append to the version string when creating drop files, e.g. M5 or RC1
+# $2: An optional label to append to the version string when creating drop files, e.g. M5 or RC1
 # 
-jobName=${JOB_NAME}
-buildId=${BUILD_ID}
-if [ $# -eq 3 -o $# -eq 4 ]; then
+set -e
+
+if [ $# -eq 1 -o $# -eq 2 ]; then
 	buildType=$1
-	merge=$2
-	dropFiles=$3
 	if [ -n "$4" ]; then
 		dropFilesLabel=$4
 	fi
 else
+	echo "Usage: $0 [i | s | r | m] [qualifier]"
+	echo "Example: $0 i"
+	echo "Example: $0 s M7"
+	exit 1
 	if [ $# -ne 0 ]; then
 		exit 1
 	fi
 fi
 
-if [ -z "$jobName" ]; then
-	echo "Error there is no jobName"; 
+if [ -z "$JOB_NAME" ]; then
+	echo "Error there is no Hudson JOB_NAME defined"; 
 	exit 0
 fi
 
-if [ -z "$buildId" ]; then
-	echo "Error there is no buildId"; 
+if [ -z "$BUILD_ID" ]; then
+	echo "Error there is no Hudson BUILD_ID defined"; 
 	exit 0
 fi
 
-# Determine the local update site we want to publish to
-localUpdateSite=${WORKSPACE}/update-site
-echo "Using local update-site: $localUpdateSite"
-
-# Select the build type
-if [ -z "$buildType" ]; then
-	echo -n "Please select which type of build you want to publish to [i(ntegration), m(aintenance), s(table), r(elease)]: "
-	read buildType
+if [ -z "$WORKSPACE" ]; then
+	echo "Error there is no Hudson WORKSPACE defined"; 
+	exit 0
 fi
-echo "Publishing as $buildType build"
+
+# Determine the local update site we want to publish from
+localTarget=${WORKSPACE}/org.eclipse.gmf.notation.repository/target
+localUpdateSite=${localTarget}/repository/
+echo "`date +%Y-%m-%d-%H:%M:%S` Using local update-site: $localUpdateSite"
 
 # Determine remote update site we want to promote to (integration and maintenance are published on interim site, stable builds on milestone site, release builds on releases site)
 case $buildType in
@@ -60,47 +60,27 @@
 	r|R) remoteSite=releases ;;
 	*) exit 0 ;;
 esac
+echo "`date +%Y-%m-%d-%H:%M:%S` Publishing as $remoteSite ( $buildType ) build"
 remoteUpdateSiteBase="modeling/gmp/gmf-notation/updates/$remoteSite"
 remoteUpdateSite="/home/data/httpd/download.eclipse.org/$remoteUpdateSiteBase"
-echo "Publishing to remote update-site: $remoteUpdateSite"
+echo "`date +%Y-%m-%d-%H:%M:%S` Publishing to remote update-site: $remoteUpdateSite"
 
-if [ -d "$remoteUpdateSite" ]; then
-	if [ -z "$merge" ]; then
-		echo -n "Do you want to merge with the existing update-site? [(y)es, (n)o]:"
-		read merge
-	fi
-	if [ "$merge" != y -a "$merge" != n ]; then
-		exit 0
-	fi
-else
-	merge=n
-fi
-echo "Merging with existing site: $merge"
-
-if [ -z "$dropFiles" ]; then
-	echo -n "Do you want to create update-site and SDK drop files? [(y)es, (n)o]:"
-	read dropFiles
-fi
-if [ "$dropFiles" != y -a "$dropFiles" != n ]; then
+if [ -z "$dropFilesLabel" -a "$buildType" != i ]; then
+	echo "Please provide a drop files label to append to the version (e.g. M5, RC1) if this is not an I build."
 	exit 0
 fi
-echo "Generating update-site and SDK drop files: $dropFiles"
-
-if [ -z "$dropFilesLabel" -a "$dropFiles" = y -a "$buildType" != i ]; then
-	echo -n "Please enter a drop files label to append to the version (e.g. M5, RC1) or leave empty to skip this [<empty>]:"
-	read dropFilesLabel
-fi
 
 # Prepare a temp directory
-tmpDir="$jobName-publish-tmp"
+tmpDir="$localTarget/$JOB_NAME-publish-tmp"
 rm -fr $tmpDir
-mkdir -p $tmpDir/update-site
+mkdir -p $tmpDir
 cd $tmpDir
+echo "`date +%Y-%m-%d-%H:%M:%S` Working in `pwd`"
 
-# Download and prepare Eclipse SDK, which is needed to merge update site and postprocess repository 
-echo "Downloading eclipse to $PWD"
-cp /home/data/httpd/download.eclipse.org/eclipse/downloads/drops4/R-4.2.2-201302041200/eclipse-SDK-4.2.2-linux-gtk-x86_64.tar.gz .
-tar -xzf eclipse-SDK-4.2.2-linux-gtk-x86_64.tar.gz
+# Download and prepare Eclipse SDK, which is needed to process the update site
+echo "`date +%Y-%m-%d-%H:%M:%S` Downloading eclipse to $PWD"
+cp /home/data/httpd/download.eclipse.org/eclipse/downloads/drops4/R-4.4-201406061215/eclipse-SDK-4.4-linux-gtk-x86_64.tar.gz .
+tar -xzf eclipse-SDK-4.4-linux-gtk-x86_64.tar.gz
 cd eclipse
 chmod 700 eclipse
 cd ..
@@ -109,133 +89,148 @@
 	exit
 fi
 # Prepare Eclipse SDK to provide WTP releng tools (used to postprocess repository, i.e set p2.mirrorsURL property)
-echo "Installing WTP Releng tools"
+echo "`date +%Y-%m-%d-%H:%M:%S` Installing WTP Releng tools"
 ./eclipse/eclipse -nosplash --launcher.suppressErrors -clean -debug -application org.eclipse.equinox.p2.director -repository http://download.eclipse.org/webtools/releng/repository/ -installIUs org.eclipse.wtp.releng.tools.feature.feature.group
 # Clean up
-echo "Cleaning up"
-rm eclipse-SDK-4.2.2-linux-gtk-x86_64.tar.gz
-
-# Prepare local update site (merging is performed later, if required)
-cp -R $localUpdateSite/* update-site/
-echo "Copied $localUpdateSite to local directory update-site."
+rm eclipse-SDK-4.4-linux-gtk-x86_64.tar.gz
 
 # Generate drop files
-if [ "$dropFiles" = y ]; then
-	echo "Converting update site to runnable form"
-	./eclipse/eclipse -nosplash -consoleLog -application org.eclipse.equinox.p2.repository.repo2runnable -source file:update-site -destination file:drops/eclipse
-	qualifiedVersion=$(find drops/eclipse/features/ -maxdepth 1 | grep "gmf.runtime.notation_")
-	echo "qualifiedVersion is $qualifiedVersion"
-	qualifiedVersion=${qualifiedVersion#*_}
-	echo "qualifiedVersion is $qualifiedVersion"
-	qualifier=${qualifiedVersion##*.}
-	echo "qualifier is $qualifier"
-	version=${qualifiedVersion%.*}
-	echo "version is $version"
-	dropDir="$version/$(echo $buildType | tr '[:lower:]' '[:upper:]')$qualifier"
-	echo "dropDir is $dropDir"
-	localDropDir=drops/$dropDir
-	echo "Creating drop files in local directory $localDropDir"
-	mkdir -p $localDropDir
+echo "`date +%Y-%m-%d-%H:%M:%S` Converting update site to runnable form"
+./eclipse/eclipse -nosplash -consoleLog -application org.eclipse.equinox.p2.repository.repo2runnable -source file:$localUpdateSite -destination file:drops/eclipse
+qualifiedVersion=$(find $localUpdateSite/features/ -maxdepth 1 | grep "gmf.runtime.notation_" | sed 's/.jar$//')
+echo "`date +%Y-%m-%d-%H:%M:%S` qualifiedVersion is $qualifiedVersion"
+qualifiedVersion=${qualifiedVersion#*_}
+echo "`date +%Y-%m-%d-%H:%M:%S` qualifiedVersion is $qualifiedVersion"
+qualifier=${qualifiedVersion##*.}
+echo "`date +%Y-%m-%d-%H:%M:%S` qualifier is $qualifier"
+qualifier=${qualifier#v}
+echo "`date +%Y-%m-%d-%H:%M:%S` qualifier is $qualifier"
+version=${qualifiedVersion%.*}
+echo "`date +%Y-%m-%d-%H:%M:%S` version is $version"
+dropDir="$(echo $buildType | tr '[:lower:]' '[:upper:]')$qualifier"
+echo "`date +%Y-%m-%d-%H:%M:%S` dropDir is $dropDir"
+localDropDir=drops/$version/$dropDir
+echo "`date +%Y-%m-%d-%H:%M:%S` Creating drop files in local directory $tmpDir/$localDropDir"
+mkdir -p $localDropDir
 
-	cp eclipse/epl-v10.html drops/eclipse
-	cp eclipse/notice.html drops/eclipse
-	cd drops
-				
-	# Append drop file suffix if one is specified				
-	if [ -n "$dropFilesLabel" ]; then
-		version=$version$dropFilesLabel
-		echo "version is now $version"
-	elif [ "$buildType" != r -a "$buildType" != R ]; then
-		version="$(echo $buildType | tr '[:lower:]' '[:upper:]')$qualifier"
-		echo "version is now $version"
-	else
-		echo "version is now $version"
-	fi
-				
-	# gmf-notation runtime
-	zip -r $dropDir/gmf-notation-$version.zip \
-		eclipse/epl-v10.html eclipse/notice.html \
-		eclipse/features/org.eclipse.gmf.runtime.notation_* \
-		eclipse/plugins/org.eclipse.gmf.runtime.notation_* \
-		eclipse/plugins/org.eclipse.gmf.runtime.notation.edit_*
-	md5sum $dropDir/gmf-notation-$version.zip > $dropDir/gmf-notation-$version.zip.md5
-	echo "Created gmf-notation-$version.zip"
-				
-	# gmf-notation SDK
-	zip -r $dropDir/gmf-sdk-notation-$version.zip \
-		eclipse/epl-v10.html eclipse/notice.html \
-		eclipse/features/org.eclipse.gmf.runtime.notation.sdk_* \
-		eclipse/features/org.eclipse.gmf.runtime.notation.source_* \
-		eclipse/features/org.eclipse.gmf.runtime.notation_* \
-		eclipse/plugins/org.eclipse.gmf.runtime.notation_* \
-		eclipse/plugins/org.eclipse.gmf.runtime.notation.edit_* \
-		eclipse/plugins/org.eclipse.gmf.runtime.notation.sdk_* \
-		eclipse/plugins/org.eclipse.gmf.runtime.notation.source_* \
-		eclipse/plugins/org.eclipse.gmf.runtime.notation.edit.source_* \
-		eclipse/plugins/org.eclipse.gmf.runtime.notation.sdk.source_*
-	md5sum $dropDir/gmf-sdk-notation-$version.zip > $dropDir/gmf-sdk-notation-$version.zip.md5
-	echo "Created gmf-sdk-notation-$version.zip"
-				
-	# gmf-notation automated-tests
-	zip -r $dropDir/gmf-tests-notation-$version.zip \
-		eclipse/epl-v10.html eclipse/notice.html \
-		eclipse/plugins/org.eclipse.gmf.tests.runtime.notation_* \
-		eclipse/features/org.eclipse.gmf.tests.runtime.notation_*
-	md5sum $dropDir/gmf-tests-notation-$version.zip > $dropDir/gmf-tests-notation-$version.zip.md5
-	echo "Created gmf-tests-notation-$version.zip"
-				
-	cd ../update-site
+# Prepare local update site (merging is performed later, if required)
+stagedUpdateSite="updates/$remoteSite/$dropDir"
+mkdir -p $stagedUpdateSite
+cp -R $localUpdateSite/* $stagedUpdateSite
+echo "`date +%Y-%m-%d-%H:%M:%S` Copied $localUpdateSite to local directory $stagedUpdateSite."
 
-	zip -r ../$localDropDir/gmf-notation-Update-$version.zip features plugins binary artifacts.jar content.jar
-	md5sum ../$localDropDir/gmf-notation-Update-$version.zip > ../$localDropDir/gmf-notation-Update-$version.zip.md5
-	echo "Created gmf-notation-Update-Site-$version.zip"
-	cd ..
-
-	#generating build.cfg file to be referenced from downloads web page
-	echo "hudson.job.name=${JOB_NAME}" > $localDropDir/build.cfg
-	echo "hudson.job.id=${BUILD_NUMBER} (${jobDir##*/})" >> $localDropDir/build.cfg
-	echo "hudson.job.url=${BUILD_URL}" >> $localDropDir/build.cfg
-
-	remoteDropDir=/home/data/httpd/download.eclipse.org/modeling/gmp/gmf-notation/downloads/drops/$dropDir
-	mkdir -p $remoteDropDir
-	cp -R $localDropDir/* $remoteDropDir/
+# Append drop file suffix if one is specified				
+if [ -n "$dropFilesLabel" ]; then
+	version=$version$dropFilesLabel
+	echo "`date +%Y-%m-%d-%H:%M:%S` version is now $version"
+elif [ "$buildType" != r -a "$buildType" != R ]; then
+	version="$(echo $buildType | tr '[:lower:]' '[:upper:]')$qualifier"
+	echo "`date +%Y-%m-%d-%H:%M:%S` version is now $version"
+else
+	echo "`date +%Y-%m-%d-%H:%M:%S` version is now $version"
 fi
+				
+cp eclipse/epl-v10.html drops/eclipse
+cp eclipse/notice.html drops/eclipse
+cd drops
 
-if [ "$merge" = y ]; then
-	echo "Merging existing site into local one."
-	./eclipse/eclipse -nosplash --launcher.suppressErrors -clean -debug -application org.eclipse.equinox.p2.metadata.repository.mirrorApplication -source file:$remoteUpdateSite -destination file:update-site
-	./eclipse/eclipse -nosplash --launcher.suppressErrors -clean -debug -application org.eclipse.equinox.p2.artifact.repository.mirrorApplication -source file:$remoteUpdateSite -destination file:update-site
-	echo "Merged $remoteUpdateSite into local directory update-site."
-fi
+# gmf-notation SDK
+zip -r ../$localDropDir/gmf-sdk-notation-$version.zip \
+	eclipse/epl-v10.html eclipse/notice.html \
+	eclipse/features/org.eclipse.gmf.runtime.notation.sdk_* \
+	eclipse/features/org.eclipse.gmf.runtime.notation.source_* \
+	eclipse/features/org.eclipse.gmf.runtime.notation_* \
+	eclipse/plugins/org.eclipse.gmf.runtime.notation_* \
+	eclipse/plugins/org.eclipse.gmf.runtime.notation.edit_* \
+	eclipse/plugins/org.eclipse.gmf.runtime.notation.sdk_* \
+	eclipse/plugins/org.eclipse.gmf.runtime.notation.source_* \
+	eclipse/plugins/org.eclipse.gmf.runtime.notation.edit.source_* \
+	eclipse/plugins/org.eclipse.gmf.runtime.notation.sdk.source_*
+md5sum ../$localDropDir/gmf-sdk-notation-$version.zip > ../$localDropDir/gmf-sdk-notation-$version.zip.md5
+echo "`date +%Y-%m-%d-%H:%M:%S` Created gmf-sdk-notation-$version.zip"
+				
+# gmf-notation runtime
+zip -r ../$localDropDir/gmf-notation-$version.zip \
+	eclipse/epl-v10.html eclipse/notice.html \
+	eclipse/features/org.eclipse.gmf.runtime.notation_* \
+	eclipse/plugins/org.eclipse.gmf.runtime.notation_* \
+	eclipse/plugins/org.eclipse.gmf.runtime.notation.edit_*
+md5sum ../$localDropDir/gmf-notation-$version.zip > ../$localDropDir/gmf-notation-$version.zip.md5
+echo "`date +%Y-%m-%d-%H:%M:%S` Created gmf-notation-$version.zip"
+				
+# gmf-notation automated-tests
+zip -r ../$localDropDir/gmf-tests-notation-$version.zip \
+	eclipse/epl-v10.html eclipse/notice.html \
+	eclipse/plugins/org.eclipse.gmf.tests.runtime.notation_* \
+	eclipse/features/org.eclipse.gmf.tests.runtime.notation_*
+md5sum ../$localDropDir/gmf-tests-notation-$version.zip > ../$localDropDir/gmf-tests-notation-$version.zip.md5
+echo "`date +%Y-%m-%d-%H:%M:%S` Created gmf-tests-notation-$version.zip"
+	
+cd $tmpDir
+		
+cd $stagedUpdateSite
+zip -r ../../../$localDropDir/gmf-notation-Update-$version.zip features plugins binary artifacts.jar content.jar
+md5sum ../../../$localDropDir/gmf-notation-Update-$version.zip > ../../../$localDropDir/gmf-notation-Update-$version.zip.md5
+echo "`date +%Y-%m-%d-%H:%M:%S` Created gmf-notation-Update-Site-$version.zip"
+
+cd $tmpDir
+
+#generating build.cfg file to be referenced from downloads web page
+echo "hudson.job.name=${JOB_NAME}" > $localDropDir/build.cfg
+echo "hudson.job.id=${BUILD_NUMBER} (${jobDir##*/})" >> $localDropDir/build.cfg
+echo "hudson.job.url=${BUILD_URL}" >> $localDropDir/build.cfg
+
+remoteDropDir=/home/data/httpd/download.eclipse.org/modeling/gmp/gmf-notation/downloads/$localDropDir
+mkdir -p $remoteDropDir
+cp -R $localDropDir/* $remoteDropDir/
+echo "`date +%Y-%m-%d-%H:%M:%S` Published drop files in local directory $tmpDir/$localDropDir to $remoteDropDir"
 
 # Ensure p2.mirrorURLs property is used in update site
-echo "Setting p2.mirrorsURL to http://www.eclipse.org/downloads/download.php?format=xml&file=/$remoteUpdateSiteBase"
-./eclipse/eclipse -nosplash --launcher.suppressErrors -clean -debug -application org.eclipse.wtp.releng.tools.addRepoProperties -vmargs -DartifactRepoDirectory=$PWD/update-site -Dp2MirrorsURL="http://www.eclipse.org/downloads/download.php?format=xml&file=/$remoteUpdateSiteBase"
+echo "`date +%Y-%m-%d-%H:%M:%S` Setting p2.mirrorsURL to http://www.eclipse.org/downloads/download.php?format=xml&file=/$remoteUpdateSiteBase"
+./eclipse/eclipse -nosplash --launcher.suppressErrors -clean -debug -application org.eclipse.wtp.releng.tools.addRepoProperties -vmargs -DartifactRepoDirectory=$PWD/$stagedUpdateSite -Dp2MirrorsURL="http://www.eclipse.org/downloads/download.php?format=xml&file=/$remoteUpdateSiteBase"
 
 # Create p2.index file
-if [ ! -e "update-site/p2.index" ]; then
-	echo "Creating p2.index file"
-	echo "version = 1" > update-site/p2.index
-	echo "metadata.repository.factory.order = content.xml,\!" >> update-site/p2.index
-	echo "artifact.repository.factory.order = artifacts.xml,\!" >> update-site/p2.index
+if [ ! -e "$stagedUpdateSite/p2.index" ]; then
+	echo "`date +%Y-%m-%d-%H:%M:%S` Creating p2.index file"
+	echo "version = 1" > $stagedUpdateSite/p2.index
+	echo "metadata.repository.factory.order = content.xml,\!" >> $stagedUpdateSite/p2.index
+	echo "artifact.repository.factory.order = artifacts.xml,\!" >> $stagedUpdateSite/p2.index
 fi
-		
+
 # Backup then clean remote update site
-echo "Creating backup of remote update site."
 if [ -d "$remoteUpdateSite" ]; then
-	if [ -d BACKUP ]; then
-		rm -fr BACKUP
+	echo "`date +%Y-%m-%d-%H:%M:%S` Creating backup of remote update site $remoteUpdateSite to $tmpDir/BACKUP."
+	if [ -d $tmpDir/BACKUP ]; then
+		rm -fr $tmpDir/BACKUP
 	fi
-	mkdir BACKUP
-	cp -R $remoteUpdateSite/* BACKUP/
+	mkdir $tmpDir/BACKUP
+	cp -R $remoteUpdateSite $tmpDir/BACKUP
 	rm -fr $remoteUpdateSite
 fi
 
-echo "Publishing contents of local update-site directory to remote update site $remoteUpdateSite"
+echo "`date +%Y-%m-%d-%H:%M:%S` Publishing local $stagedUpdateSite directory to remote update site $remoteUpdateSite/$dropDir"
 mkdir -p $remoteUpdateSite
-cp -R update-site/* $remoteUpdateSite/
+cp -R $stagedUpdateSite $remoteUpdateSite
+
+# Create the composite update site
+cat > p2.composite.repository.xml <<EOF
+<?xml version="1.0" encoding="UTF-8"?>
+<project name="p2 composite repository">
+<target name="default">
+<p2.composite.repository>
+<repository compressed="true" location="${remoteUpdateSite}" name="${JOB_NAME}"/>
+<add>
+<repository location="${dropDir}"/>
+</add>
+</p2.composite.repository>
+</target>
+</project>
+EOF
+
+echo "`date +%Y-%m-%d-%H:%M:%S` Update the composite update site"
+./eclipse/eclipse -nosplash --launcher.suppressErrors -clean -debug -application org.eclipse.ant.core.antRunner -buildfile p2.composite.repository.xml default
 
 # Clean up
-echo "Cleaning up"
-rm -fr eclipse
-rm -fr update-site
+echo "`date +%Y-%m-%d-%H:%M:%S` Cleaning up"
+#rm -fr eclipse
+#rm -fr update-site