[releng] Add JIRO publication script

Change-Id: Icbefa727f63730d8066510cfee347c6e5839022b
Signed-off-by: Pierre-Charles David <pierre-charles.david@obeo.fr>
diff --git a/org.eclipse.gmf.notation.repository/gmf-notation-jiro-publish.sh b/org.eclipse.gmf.notation.repository/gmf-notation-jiro-publish.sh
new file mode 100644
index 0000000..654ed33
--- /dev/null
+++ b/org.eclipse.gmf.notation.repository/gmf-notation-jiro-publish.sh
@@ -0,0 +1,188 @@
+#!/bin/bash
+# Copyright (c) 2012, 2016, 2019, 2020 IBM Corporation and others.
+# This program and the accompanying materials are made
+# available under the terms of the Eclipse Public License 2.0
+# which is available at https://www.eclipse.org/legal/epl-2.0/
+#
+# SPDX-License-Identifier: EPL-2.0
+#
+# Contributors:
+#   IBM - Initial API and implementation
+
+# Script needs 4-5 environment parameters:
+# Hudson job name: ${JOB_NAME}
+# Hudson build id: ${BUILD_ID}
+# Hudson workspace: ${WORKSPACE}
+# ${BUILD_TYPE}: n(ightly), m(aintenance), s(table), r(elease)
+# ${BUILD_LABEL}: An optional label to append to the version string when creating drop files, e.g. M5 or RC1
+#
+set -e
+
+export PROJECT_NAME="GMF Notation"
+export PROJECT_PREFIX="org.eclipse.gmf.notation"
+export SSH_ACCOUNT="genie.gmf-runtime@projects-storage.eclipse.org"
+
+if [ -z "$JOB_NAME" ]; then
+    echo "Error there is no Hudson JOB_NAME defined";
+    exit 0
+fi
+
+if [ -z "$BUILD_ID" ]; then
+    echo "Error there is no Hudson BUILD_ID defined";
+    exit 0
+fi
+
+if [ -z "$WORKSPACE" ]; then
+    echo "Error there is no Hudson WORKSPACE defined";
+    exit 0
+fi
+
+if [ -z "$BUILD_TYPE" ]; then
+    echo "Error there is no BUILD_TYPE defined";
+    exit 0
+else
+    buildType=$BUILD_TYPE
+fi
+
+if [ -z "$BUILD_LABEL" ]; then
+    echo "Error there is no BUILD_LABEL defined";
+    exit 0
+else
+    if [ "$BUILD_LABEL" != "NONE" ]; then
+        dropFilesLabel=$BUILD_LABEL
+    fi
+fi
+
+message() {
+    echo "$(date +%Y-%m-%d-%H:%M:%S) $1"
+}
+
+# Determine the local update site we want to publish from
+localTarget=${WORKSPACE}/org.eclipse.gmf.notation.repository/target
+localUpdateSite=${localTarget}/repository/
+message "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
+        m|M) remoteSite=maintenance ;;
+        i|I) remoteSite=interim ;;
+        s|S) remoteSite=milestones ;;
+        r|R) remoteSite=releases ;;
+        *) exit 0 ;;
+esac
+
+message "Publishing as $remoteSite (${buildType}) build"
+remoteUpdateSiteBase="modeling/gmp/gmf-notation/updates/staging/$remoteSite"
+remoteUpdateSite="/home/data/httpd/download.eclipse.org/$remoteUpdateSiteBase"
+message "Publishing to remote update-site: $remoteUpdateSite"
+
+if [ -z "$dropFilesLabel" -a "$buildType" != i  -a "$buildType" != I -a "$buildType" != r  -a "$buildType" != R ]; then
+    echo "Please provide a drop files label to append to the version (e.g. M5, RC1) if this is not an I or R build."
+    exit 0
+fi
+
+# Prepare a temp directory
+tmpDir="$localTarget/$JOB_NAME-publish-tmp"
+rm -fr $tmpDir
+mkdir -p $tmpDir
+cd $tmpDir
+message "Working in $(pwd)"
+
+# Compute dropDir
+qualifiedVersion=$(find "$localUpdateSite"/features/ -maxdepth 1 | grep "org.eclipse.gmf.notation_" | sed 's/.jar$//')
+qualifiedVersion=${qualifiedVersion#*_}
+qualifier=${qualifiedVersion##*.}
+qualifier=${qualifier#v}
+version=${qualifiedVersion%.*}
+dropDir="$(echo "$buildType" | tr '[:lower:]' '[:upper:]')$qualifier"
+message "dropDir is $dropDir"
+
+# Prepare local update site (merging is performed later, if required)
+stagedUpdateSite="updates/$remoteSite/$dropDir"
+mkdir -p "$stagedUpdateSite"
+cp -R "$localUpdateSite"/* "$stagedUpdateSite"
+message "Copied $localUpdateSite to local directory $stagedUpdateSite."
+
+# Append drop file suffix if one is specified
+if [ -n "$dropFilesLabel" ]; then
+    version=$version$dropFilesLabel
+    message "version is now $version"
+elif [ "$buildType" != r -a "$buildType" != R ]; then
+    version="$(echo "$buildType" | tr '[:lower:]' '[:upper:]')$qualifier"
+    message "version is now $version"
+else
+    message "version is now $version"
+fi
+
+# Publish the new repository
+message "Publishing local $stagedUpdateSite directory to remote update site $remoteUpdateSite/$dropDir"
+ssh "$SSH_ACCOUNT" mkdir -p $remoteUpdateSite
+scp -r "$stagedUpdateSite" "$SSH_ACCOUNT:$remoteUpdateSite"
+
+# Create/refresh the composite, with references only to the N=5 most recent builds (if nightly)
+
+create_composite() {
+    local name="$1"
+    shift
+    local location="$1"
+    shift
+
+    cat > "$location"/compositeArtifacts.xml <<EOF
+<?xml version='1.0' encoding='UTF-8'?>
+<?compositeArtifactRepository version='1.0.0'?>
+<repository name='$name $version' type='org.eclipse.equinox.internal.p2.artifact.repository.CompositeArtifactRepository' version='1.0.0'>
+  <properties size='1'>
+    <property name='p2.timestamp' value='$P2_TIMESTAMP'/>
+  </properties>
+  <children size='$#'>
+EOF
+
+    cat > "$location"/compositeContent.xml <<EOF
+<?xml version='1.0' encoding='UTF-8'?>
+<?compositeMetadataRepository version='1.0.0'?>
+<repository name='$name $version' type='org.eclipse.equinox.internal.p2.metadata.repository.CompositeMetadataRepository' version='1.0.0'>
+  <properties size='1'>
+    <property name='p2.timestamp' value='$P2_TIMESTAMP'/>
+  </properties>
+  <children size='$#'>
+EOF
+
+    for entry in "$@"; do
+        echo "    <child location='$entry'/>" >> "$location"/compositeArtifacts.xml
+        echo "    <child location='$entry'/>" >> "$location"/compositeContent.xml
+    done
+
+    cat >> "$location"/compositeArtifacts.xml <<EOF
+  </children>
+</repository>
+EOF
+
+    cat >> "$location"/compositeContent.xml <<EOF
+  </children>
+</repository>
+EOF
+
+}
+
+entries=""
+if ssh "$SSH_ACCOUNT" test -d "$remoteUpdateSite" ; then
+    message "Add existing update sites to the composite update site repository file."
+    if [ "$buildType" != "$R" ]; then
+        for e in $(ssh "$SSH_ACCOUNT" find ${remoteUpdateSite}/ -mindepth 1 -maxdepth 1 -type d | sort | tail -n 5); do
+            entries="$entries $(basename $e)"
+        done
+    else
+        for e in $(ssh "$SSH_ACCOUNT" find ${remoteUpdateSite}/ -mindepth 1 -maxdepth 1 -type d | sort); do
+            entries="$entries $(basename $e)"
+        done
+    fi
+fi
+
+message "Composite entries: $entries"
+create_composite "GMF Notation" . $entries
+ssh "$SSH_ACCOUNT" rm -f ${remoteUpdateSite}/compositeArtifacts.jar ${remoteUpdateSite}/compositeContent.jar
+ssh "$SSH_ACCOUNT" rm -f ${remoteUpdateSite}/compositeArtifacts.xml ${remoteUpdateSite}/compositeContent.xml
+scp composite*xml "$SSH_ACCOUNT:${remoteUpdateSite}"