externalized use of globals
diff --git a/hudson-scripts/clean-nightly.sh b/hudson-scripts/clean-nightly.sh
index 6d275f8..b283af7 100755
--- a/hudson-scripts/clean-nightly.sh
+++ b/hudson-scripts/clean-nightly.sh
@@ -24,8 +24,15 @@
unqualifiedVersion="${1}"
nbBuildToKeep="${2:-5}"
+LS_LEVEL=20
source "$(dirname "${0}")/init.sh"
-LSINFO "== Clean up '${unqualifiedVersion}' nightly builds (will keep the ${nbBuildToKeep} most recent) =="
+LSINFO "Cleaning up '${PROJECT_NAME} ${unqualifiedVersion}' nightly builds (will keep the ${nbBuildToKeep} most recent)"
-cleanUpdateSites "${UPDATE_NIGHTLY_HOME}" "${UPDATE_NIGHTLY_URL}" "${PROJECT_NAME}" "${NIGHTLY_FOLDER}" "${unqualifiedVersion}" "${nbBuildToKeep}"
\ No newline at end of file
+cleanUpdateSites \
+ "${UPDATE_NIGHTLY_HOME}" \
+ "${UPDATE_NIGHTLY_URL}" \
+ "${PROJECT_NAME}" \
+ "${NIGHTLY_FOLDER}" \
+ "${unqualifiedVersion}" \
+ "${nbBuildToKeep}"
\ No newline at end of file
diff --git a/hudson-scripts/init/1_labels.sh b/hudson-scripts/init/1_labels.sh
new file mode 100644
index 0000000..95265fa
--- /dev/null
+++ b/hudson-scripts/init/1_labels.sh
@@ -0,0 +1,33 @@
+#!/bin/sh
+# ====================================================================
+# Copyright (c) 2014 Obeo
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Contributors:
+# Obeo - initial API and implementation
+# ====================================================================
+
+streamRepositoryLabel() {
+ local projectName="${1}"
+ local category="${2}"
+ local streamName="${3}"
+
+ echo "${projectName}${streamName:+ ${streamName}${STREAM_NAME_SUFFIX}} ${category} builds"
+}
+
+streamLatestRepositoryLabel() {
+ local projectName="${1}"
+ local category="${2}"
+ local streamName="${3}"
+
+ echo "${projectName}${streamName:+ ${streamName}${STREAM_NAME_SUFFIX}} latest ${category} build"
+}
+
+streamLabel() {
+ local streamName="${1}"
+
+ echo "${streamName:+${streamName}${STREAM_NAME_SUFFIX}}"
+}
\ No newline at end of file
diff --git a/hudson-scripts/init/1_p2.sh b/hudson-scripts/init/1_p2.sh
index 9ddbda5..1c87de8 100644
--- a/hudson-scripts/init/1_p2.sh
+++ b/hudson-scripts/init/1_p2.sh
@@ -13,6 +13,8 @@
P2_ADMIN_VERSION="${P2_ADMIN_VERSION:-1.1.0}"
_initP2Admin() {
+ LSDEBUG "Initializing p2-admin ${P2_ADMIN_VERSION}"
+
local wd="${1}"
local osws=""
@@ -39,25 +41,21 @@
fi
local platformSpecifier="${osws}.${arch}"
- LSDEBUG "Platform specifier is '${platformSpecifier}'"
local p2AdminArchive="p2-admin-${P2_ADMIN_VERSION}-${platformSpecifier}.${archiveFileExtension}"
local p2AdminURL="https://github.com/mbarbero/p2-admin/releases/download/v${P2_ADMIN_VERSION}/${p2AdminArchive}"
# prevents re-downloading the p2-admin archive each time.
if [ ! -f "${wd}/${p2AdminArchive}" ]; then
- LSDEBUG "Unable to find p2-admin archive '${wd}/${p2AdminArchive}'"
- LSINFO "Downloading p2-admin '${p2AdminURL}'"
+ LSDEBUG "Downloading p2-admin '${p2AdminURL}'"
wget -q --no-check-certificate ${p2AdminURL} -O - > "${wd}/${p2AdminArchive}"
fi
# this way, we are sure to have a clean p2-admin install, without any p2-cache.
# the p2-admin archive will be unzipped afterwards.
if [ -d '${wd}/p2-admin' ]; then
- LSDEBUG "Removing previous 'p2-admin' folder"
rm -rf "${wd}/p2-admin"
fi
- LSDEBUG "Unziping '${p2AdminArchive}'"
tar zxf "${wd}/${p2AdminArchive}" -C "${wd}"
}
@@ -75,7 +73,6 @@
# Create a p2 index file for composite repositories
createP2Index() {
if [ ! -f "${1}/p2.index" ]; then
- LSDEBUG "Creating p2.index file in ${1}"
cat > "${1}/p2.index" <<EOF
version = 1
metadata.repository.factory.order = compositeContent.xml,\!
@@ -95,7 +92,6 @@
_initP2Admin "${WORKING_DIRECTORY}"
fi
- LSDEBUG "Creating redirection from '${name}'@'${from}' to '${to}'"
mkdir -p "${from}"
rm -f "${from}/compositeArtifacts."*
rm -f "${from}/compositeContent."*
diff --git a/hudson-scripts/init/1_paths.sh b/hudson-scripts/init/1_paths.sh
new file mode 100644
index 0000000..a391fc1
--- /dev/null
+++ b/hudson-scripts/init/1_paths.sh
@@ -0,0 +1,39 @@
+#!/bin/sh
+# ====================================================================
+# Copyright (c) 2014 Obeo
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Contributors:
+# Obeo - initial API and implementation
+# ====================================================================
+
+streamPath() {
+ local streamName="${1}"
+
+ echo "${streamName:+${STREAMS_FOLDER}/${streamName}${STREAM_NAME_SUFFIX}}"
+}
+
+streamAbsolutePath() {
+ local home="${1}"
+ local streamName="${2}"
+
+ local _streamPath="$(streamPath "${streamName}")"
+ echo "${home}${_streamPath:+/${_streamPath}}"
+}
+
+streamLatestPath() {
+ local streamName="${1}"
+
+ local _streamPath="$(streamPath "${streamName}")"
+ echo "${_streamPath:+${_streamPath}/}${LATEST_FOLDER}"
+}
+
+streamLatestAbsolutePath() {
+ local home="${1}"
+ local streamName="${2}"
+
+ echo "${home}/$(streamLatestPath "${streamName}")"
+}
\ No newline at end of file
diff --git a/hudson-scripts/init/3_update-site-publish.sh b/hudson-scripts/init/3_update-site-publish.sh
index 1069269..f5b5b3f 100644
--- a/hudson-scripts/init/3_update-site-publish.sh
+++ b/hudson-scripts/init/3_update-site-publish.sh
@@ -25,22 +25,22 @@
_updateLatestUpdateSite() {
local updateHome="${1}"
- local absolutePathToLatest="${updateHome}${2:+/${2}}"
- local prefix="${3}"
- local latestRepoLabel="${4}"
+ local stream="${2}"
+ local latestRepoLabel="${3}"
local currentPwd=$(pwd)
cd "${updateHome}"
- local allFilesWithPrefix=( $(echo "${prefix}"* | tr ' ' '\n' | grep -E '[0-9]+\.[0-9]+\.[0-9]+.*' || true) )
+ local updateSitesInStream=( $(echo "${stream}"* | tr ' ' '\n' | grep -E '[0-9]+\.[0-9]+\.[0-9]+.*' || true) )
cd "${currentPwd}"
- if [ ${#allFilesWithPrefix[@]} -gt 0 ]; then
- local latestUpdatePath=$( echo ${allFilesWithPrefix[@]} | tr ' ' '\n' | sort | tail -n 1 )
- local relpath=$( relativize ${absolutePathToLatest} ${updateHome}/${latestUpdatePath} )
- LSINFO "Creating redirection from '${absolutePathToLatest}' to '${latestUpdatePath}'"
+ if [ ${#updateSitesInStream[@]} -gt 0 ]; then
+ local absolutePathToLatest=$( streamLatestAbsolutePath "${updateHome}" "${stream}" )
+ local latestUpdateSite=$( echo ${updateSitesInStream[@]} | tr ' ' '\n' | sort | tail -n 1 )
+ local relpath=$( relativize ${absolutePathToLatest} ${updateHome}/${latestUpdateSite} )
+ LSDEBUG "Creating redirection from '${absolutePathToLatest}' to '${relpath}'"
createRedirect "${absolutePathToLatest}" "${relpath}" "${latestRepoLabel}"
else
- LSDEBUG "No folder in '${updateHome}' have a name that start with '${prefix}' and that match the regex '[0-9]+\.[0-9]+\.[0-9]+.*'."
+ LSDEBUG "No folder in '${updateHome}' have a name that start with '${stream}' and that match the regex '[0-9]+\.[0-9]+\.[0-9]+.*'."
fi
}
@@ -51,31 +51,28 @@
local qualifiedVersion="${4}"
local stream="${5}"
- local repoLabelPrefix="${projectName}${stream:+ ${stream}${STREAM_NAME_SUFFIX}}"
+ local _streamAbsolutePath=$( streamAbsolutePath "${updateHome}" "${stream}" )
+ local relativePathToUpdateSite=$( relativize "${_streamAbsolutePath}" "${updateHome}/${qualifiedVersion}" )
- local streamPath="${stream:+${STREAMS_FOLDER}/${stream}${STREAM_NAME_SUFFIX}}"
- local streamAbsolutePath="${updateHome}${streamPath:+/${streamPath}}"
- local relPathToUpdateSite=$( relativize "${streamAbsolutePath}" "${updateHome}/${qualifiedVersion}" )
-
- LSDEBUG "Adding '${relPathToUpdateSite}' to composite repository '${streamAbsolutePath}'"
+ LSDEBUG "Adding '${relativePathToUpdateSite}' to composite repository '$(streamLabel "${stream}")'"
compositeRepository \
- -location "${streamAbsolutePath}" \
- -add "${relPathToUpdateSite}" \
- -repositoryName "${repoLabelPrefix} ${category} builds" \
+ -location "${_streamAbsolutePath}" \
+ -add "${relativePathToUpdateSite}" \
+ -repositoryName $(streamRepositoryLabel "${projectName}" "${category}" "${stream}") \
-compressed
- createP2Index "${streamAbsolutePath}"
+ createP2Index "${_streamAbsolutePath}"
- LSDEBUG "Updating latest of stream '${stream}${STREAM_NAME_SUFFIX}' @ '${streamAbsolutePath}'"
- _updateLatestUpdateSite "${updateHome}" "${streamPath}${streamPath:+/}${LATEST_FOLDER}" "${stream}" "${repoLabelPrefix} latest ${category} build"
+ LSDEBUG "Updating latest link of ${category} stream '$(streamLabel "${stream}")'"
+ _updateLatestUpdateSite "${updateHome}" "${stream}" $(streamLatestRepositoryLabel "${projectName}" "${category}" "${stream}")
}
publishUpdateSite() {
local wd="${1}"
- local projectName="${2}"
- local category="${3}"
- local artifactURL="${4}"
- local qualifiedVersion="${5}"
- local updateHome="${6}"
+ local updateHome="${2}"
+ local projectName="${3}"
+ local category="${4}"
+ local artifactURL="${5}"
+ local qualifiedVersion="${6}"
# the update site
LSINFO "Downloading '${artifactURL}'"
@@ -91,8 +88,12 @@
cp -Rf "${wd}/${targetUpdateSiteName}/"* "${updateHome}/${qualifiedVersion}"
## streams update
+ LSINFO "Publishing update site in stream $(streamLabel $(unqualifiedVersion ${qualifiedVersion}))"
_publishUpdateSiteInStream "${updateHome}" "${projectName}" "${category}" "${qualifiedVersion}" "$(unqualifiedVersion ${qualifiedVersion})"
+ LSINFO "Publishing update site in stream $(streamLabel $(minorVersion ${qualifiedVersion}))"
_publishUpdateSiteInStream "${updateHome}" "${projectName}" "${category}" "${qualifiedVersion}" "$(minorVersion ${qualifiedVersion})"
+ LSINFO "Publishing update site in stream $(streamLabel $(majorVersion ${qualifiedVersion}))"
_publishUpdateSiteInStream "${updateHome}" "${projectName}" "${category}" "${qualifiedVersion}" "$(majorVersion ${qualifiedVersion})"
+ LSINFO "Publishing update site in global stream"
_publishUpdateSiteInStream "${updateHome}" "${projectName}" "${category}" "${qualifiedVersion}" ""
}
diff --git a/hudson-scripts/init/4_update-site-clean.sh b/hudson-scripts/init/4_update-site-clean.sh
index 22131c0..aaeec1d 100644
--- a/hudson-scripts/init/4_update-site-clean.sh
+++ b/hudson-scripts/init/4_update-site-clean.sh
@@ -13,37 +13,38 @@
_cleanNightly() {
local updateHome="${1}"
local updateURL="${2}"
- local streamPath="${updateHome}${3:+/${3}}"
+ local streamName="${3}"
local updateSiteToClean="${4}"
- local latestInStreamPath="${streamPath}/${LATEST_FOLDER}"
- local updateSiteURLToClean="${updateURL}/${updateSiteToClean}"
- local relpath=$( relativize ${streamPath} ${updateHome}/${updateSiteToClean} )
+ local _streamAbsolutePath=$( streamAbsolutePath "${updateHome}" "${streamName}" )
+ local relpath=$( relativize "${_streamAbsolutePath}" "${updateHome}/${updateSiteToClean}" )
- LSINFO "Removing '${relpath}' from '${streamPath}'"
- compositeRepository -location "${streamPath}" -remove "${relpath}"
+ LSDEBUG "Removing '${relpath}' from '${_streamAbsolutePath}'"
+ compositeRepository -location "${_streamAbsolutePath}" -remove "${relpath}"
##check the number of children in streamPath, if 0 remove folder (no need to check latest)
- local streamPathChild=( $(compositeRepository -location "${streamPath}" -list) )
- if [ ${#streamPathChild[@]} -eq 0 ]; then
- LSINFO "Removing folder '${streamPath}' as it has no children anymore"
- if [ "${streamPath}" = "${updateHome}" ]; then
+ local streamPathChildren=( $(compositeRepository -location "${_streamAbsolutePath}" -list) )
+ if [ ${#streamPathChildren[@]} -eq 0 ]; then
+ LSINFO "Removing folder '${_streamAbsolutePath}' as it has no children anymore"
+ if [ "${_streamAbsolutePath}" = "${updateHome}" ]; then
# do not remove home
- rm -rf "${streamPath}/"*
+ rm -rf "${_streamAbsolutePath}/"*
else
- rm -rf "${streamPath}"
+ rm -rf "${_streamAbsolutePath}"
fi
else
+ local latestInStreamPath=$( streamLatestAbsolutePath "${updateHome}" "${streamName}" )
local latestUpdateSiteInStream=( $(compositeRepository -location "${latestInStreamPath}" -list) )
- LSDEBUG "Current latest update site in stream '${streamPath}' is '${latestUpdateSiteInStream[@]}'"
+ LSDEBUG "Current latest update site in stream '${_streamAbsolutePath}' is '${latestUpdateSiteInStream[@]}'"
if [ ${#latestUpdateSiteInStream[@]} -gt 0 ]; then
+ local updateSiteURLToClean="${updateURL}/${updateSiteToClean}"
if [ ${#latestUpdateSiteInStream[@]} -gt 1 ]; then
LSDEBUG "There are more than a single update site referenced in the repository ${latestInStreamPath}"
compositeRepository -location "${latestInStreamPath}" -removeAll
compositeRepository -location "${latestInStreamPath}" -add "${relpath}"
elif [ "${updateSiteURLToClean}" = "${latestUpdateSiteInStream[0]}" ]; then
relpath=$( relativize ${latestInStreamPath} ${updateHome}/${updateSiteToClean} )
- LSINFO "Removing '${relpath}' from '${latestInStreamPath}'"
+ LSDEBUG "Removing '${relpath}' from '${latestInStreamPath}'"
compositeRepository -location "${latestInStreamPath}" -remove "${relpath}"
fi
fi
@@ -64,7 +65,7 @@
cd "${currentPwd}"
if [ ${#foldersWithUnqualifiedVersionPrefix[@]} -eq 0 ]; then
- LSINFO "No build '${unqualifiedVersion}' found in '${updateHome}, nothing to clean'"
+ LSINFO "No build '${unqualifiedVersion}' found in '${updateHome}', nothing to clean'"
exit 0
fi
@@ -83,18 +84,32 @@
local _majorVersion="$(majorVersion ${unqualifiedVersion})"
for updateSiteToClean in ${updateSitesToClean[@]}; do
- _cleanNightly "${updateHome}" "${updateURL}" "${STREAMS_FOLDER}/${unqualifiedVersion}${STREAM_NAME_SUFFIX}" "${updateSiteToClean}"
- _cleanNightly "${updateHome}" "${updateURL}" "${STREAMS_FOLDER}/${_minorVersion}${STREAM_NAME_SUFFIX}" "${updateSiteToClean}"
- _cleanNightly "${updateHome}" "${updateURL}" "${STREAMS_FOLDER}/${_majorVersion}${STREAM_NAME_SUFFIX}" "${updateSiteToClean}"
- _cleanNightly "${updateHome}" "${updateURL}" "" "${updateSiteToClean}"
+ LSINFO "Removing ${category} build '${updateSiteToClean}' from stream '$(streamLabel "${unqualifiedVersion}")'"
+ _cleanNightly "${updateHome}" "${updateURL}" "${unqualifiedVersion}" "${updateSiteToClean}"
+
+ LSINFO "Removing ${category} build '${updateSiteToClean}' from stream '$(streamLabel "${_minorVersion}")'"
+ _cleanNightly "${updateHome}" "${updateURL}" "${_minorVersion}" "${updateSiteToClean}"
+
+ LSINFO "Removing ${category} build '${updateSiteToClean}' from stream '$(streamLabel "${_majorVersion}")'"
+ _cleanNightly "${updateHome}" "${updateURL}" "${_majorVersion}" "${updateSiteToClean}"
+
+ LSINFO "Removing ${category} build '${updateSiteToClean}' from global stream"
+ _cleanNightly "${updateHome}" "${updateURL}" "" "${updateSiteToClean}"
- LSINFO "Removing folder '${updateHome}/${updateSiteToClean}'"
+ LSDEBUG "Removing folder '${updateHome}/${updateSiteToClean}'"
rm -rf "${updateHome}/${updateSiteToClean}"
done
- _updateLatestUpdateSite "${updateHome}" "${STREAMS_FOLDER}/${unqualifiedVersion}${STREAM_NAME_SUFFIX}/${LATEST_FOLDER}" "${unqualifiedVersion}" "${projectName} ${unqualifiedVersion}${STREAM_NAME_SUFFIX} latest ${category} build"
- _updateLatestUpdateSite "${updateHome}" "${STREAMS_FOLDER}/${_minorVersion}${STREAM_NAME_SUFFIX}/${LATEST_FOLDER}" "${_minorVersion}" "${projectName} ${_minorVersion}${STREAM_NAME_SUFFIX} latest ${category} build"
- _updateLatestUpdateSite "${updateHome}" "${STREAMS_FOLDER}/${_majorVersion}${STREAM_NAME_SUFFIX}/${LATEST_FOLDER}" "${_majorVersion}" "${projectName} ${_majorVersion}${STREAM_NAME_SUFFIX} latest ${category} build"
- _updateLatestUpdateSite "${updateHome}" "${LATEST_FOLDER}" "" "${projectName} latest ${category} build"
+ LSINFO "Updating latest link of ${category} stream '$(streamLabel "${unqualifiedVersion}")'"
+ _updateLatestUpdateSite "${updateHome}" "${unqualifiedVersion}" $(streamLatestRepositoryLabel "${projectName}" "${category}" "${unqualifiedVersion}")
+
+ LSINFO "Updating latest link of ${category} stream '$(streamLabel "${_minorVersion}")'"
+ _updateLatestUpdateSite "${updateHome}" "${_minorVersion}" $(streamLatestRepositoryLabel "${projectName}" "${category}" "${_minorVersion}")
+
+ LSINFO "Updating latest link of ${category} stream '$(streamLabel "${_majorVersion}")'"
+ _updateLatestUpdateSite "${updateHome}" "${_majorVersion}" $(streamLatestRepositoryLabel "${projectName}" "${category}" "${_majorVersion}")
+
+ LSINFO "Updating latest link of ${category} global stream"
+ _updateLatestUpdateSite "${updateHome}" "" $(streamLatestRepositoryLabel "${projectName}" "${category}" "")
fi
}
diff --git a/hudson-scripts/init/_0_log.sh b/hudson-scripts/init/_0_log.sh
index 0fedb07..1cbcdf1 100644
--- a/hudson-scripts/init/_0_log.sh
+++ b/hudson-scripts/init/_0_log.sh
@@ -67,7 +67,7 @@
LSLOG () {
local LEVEL=${1}
shift
- (( LEVEL < LS_LEVEL )) && return 1
+ (( LEVEL < LS_LEVEL )) && return 0
_LS_FIND_LEVEL_STR ${LEVEL}
# if no message was passed, read it from STDIN
local _MSG
diff --git a/hudson-scripts/init/_1_trap.sh b/hudson-scripts/init/_1_trap.sh
index 981fdca..5948df8 100644
--- a/hudson-scripts/init/_1_trap.sh
+++ b/hudson-scripts/init/_1_trap.sh
@@ -17,21 +17,24 @@
LSDEBUG "Program will exit, saving the environment variables to a file for later debugging"
env | sort > "${WORKING_DIRECTORY}/env.txt"
-
- if [ ${RETURN} -ne 0 -a ${RETURN} -lt 129 -o ${RETURN} -gt 165 ]; then
- cd "${_ON_LOAD_PWD}"
- LSCRITICAL "An error occurred"
- LSLOGSTACK
- fi
-
+
exit ${RETURN}
}
__onInterruption() {
local RETURN=$?
- LSDEBUG "Program has been interrupted"
+ LSINFO "Program has been interrupted"
exit ${RETURN}
}
-trap __onInterruption INT TERM #ERR #DEBUG #RETURN
+__onErr() {
+ local RETURN=$?
+ cd "${_ON_LOAD_PWD}"
+ LSCRITICAL "An error occurred"
+ LSLOGSTACK
+ exit ${RETURN}
+}
+
+trap __onErr ERR
+trap __onInterruption INT TERM #DEBUG #RETURN
trap __onExit EXIT
diff --git a/hudson-scripts/publish-nightly.sh b/hudson-scripts/publish-nightly.sh
index f8e96dc..fd08661 100755
--- a/hudson-scripts/publish-nightly.sh
+++ b/hudson-scripts/publish-nightly.sh
@@ -13,20 +13,28 @@
if [ $# -ne 2 ]; then
echo "Execution aborted. One or more of the required parameters is not set.
-Usage: $0 artifactURL unqualifiedVersion qualifiedVersion
+Usage: $0 artifactURL qualifiedVersion
- artifactURL: the URL where the zipped update site to publish can be donwload.
- qualifiedVersion: the qualified version of the update site to publish.
"
+exit 1
fi
artifactURL="${1}"
qualifiedVersion="${2}"
+LS_LEVEL=20
source "$(dirname "${0}")/init.sh"
-LSINFO "== Publishing nightly build '${PROJECT_NAME} ${qualifiedVersion}' == "
+LSINFO "Publishing nightly build '${PROJECT_NAME} ${qualifiedVersion}'"
-publishUpdateSite "${WORKING_DIRECTORY}" "${PROJECT_NAME}" "${NIGHTLY_FOLDER}" "${artifactURL}" "${qualifiedVersion}" "${UPDATE_NIGHTLY_HOME}"
+publishUpdateSite \
+ "${WORKING_DIRECTORY}" \
+ "${UPDATE_NIGHTLY_HOME}" \
+ "${PROJECT_NAME}" \
+ "${NIGHTLY_FOLDER}" \
+ "${artifactURL}" \
+ "${qualifiedVersion}"
-LSINFO "== '${PROJECT_NAME} ${qualifiedVersion}' has been published @ '${UPDATE_NIGHTLY_URL}/${qualifiedVersion}' == "
+LSINFO "'${PROJECT_NAME} ${qualifiedVersion}' has been published at '${UPDATE_NIGHTLY_URL}/${qualifiedVersion}'"