refactored publish-nightly script
diff --git a/hudson-scripts/init/0_constants.sh b/hudson-scripts/init/0_constants.sh
index fec7282..6bc67c3 100644
--- a/hudson-scripts/init/0_constants.sh
+++ b/hudson-scripts/init/0_constants.sh
@@ -17,6 +17,8 @@
 
 # Private constants
 export UPDATE_FOLDER="${UPDATE_FOLDER:-updates}"
+export STREAMS_FOLDER="${STREAMS_FOLDER:-streams}"
+export LATEST_FOLDER="${LATEST_FOLDER:-latest}"
 export NIGHTLY_FOLDER="${NIGHTLY_FOLDER:-nightly}"
 export INTEGRATION_FOLDER="${INTEGRATION_FOLDER:-integration}"
 export RELEASES_FOLDER="${RELEASES_FOLDER:-releases}"
diff --git a/hudson-scripts/init/2_functions.sh b/hudson-scripts/init/2_functions.sh
index 8a2d933..6103ce5 100644
--- a/hudson-scripts/init/2_functions.sh
+++ b/hudson-scripts/init/2_functions.sh
@@ -10,49 +10,6 @@
 #    Obeo - initial API and implementation
 # ====================================================================
 
-# retrieved from http://stackoverflow.com/a/12498485
-relpath() {
-    # both $1 and $2 are absolute paths beginning with /
-    # returns relative path to $2/$targetPath from $1/$sourcePath
-    local sourcePath=$1
-    local targetPath=$2
-
-    local common_part=$sourcePath # for now
-    local result="" # for now
- 
-    while [[ "${targetPath#$common_part}" == "${targetPath}" ]]; do
-        # no match, means that candidate common part is not correct
-        # go up one level (reduce common part)
-
-        common_part="$(dirname $common_part)"
-        # and record that we went back, with correct / handling
-        if [[ -z $result ]]; then
-            result=".."
-        else
-            result="../$result"
-        fi
-    done
-
-    if [[ $common_part == "/" ]]; then
-        # special case for root (no common path)
-        result="$result/"
-    fi
-
-    # since we now have identified the common part,
-    # compute the non-common part
-    local forward_part="${targetPath#$common_part}"
-
-    # and now stick all parts together
-    if [[ -n $result ]] && [[ -n $forward_part ]]; then
-        result="$result$forward_part"
-    elif [[ -n $forward_part ]]; then
-        # extra slash removal
-        result="${forward_part:1}"
-    fi
-
-    echo $result
-}
-
 updateLatest() {
     local latestPath=$1
     local prefix=$2
@@ -66,7 +23,7 @@
     if [ ${#allFilesWithPrefix[@]} -gt 0 ]; then
         local latestUpdatePath=$( echo ${allFilesWithPrefix[@]} | tr ' ' '\n' | sort | tail -n 1 )
         if [ ! -z "${latestUpdatePath}" ]; then
-            local relpath=$( relpath ${latestPath} ${UPDATE_NIGHTLY_HOME}/${latestUpdatePath} )
+            local relpath=$( relativize ${latestPath} ${UPDATE_NIGHTLY_HOME}/${latestUpdatePath} )
             local latestUpdateSite_onDisk="file:${UPDATE_NIGHTLY_HOME}/${latestUpdatePath}"
             LSDEBUG "Latest update site on disk is '${latestUpdateSite_onDisk}'"
             if [ -d "${latestPath}" ]; then
@@ -103,7 +60,7 @@
     local latestInStreamPath=$3
 
     local updateSiteURLToClean="${UPDATE_NIGHTLY_URL}/${updateSiteToClean}"
-    local relpath=$( relpath ${streamPath} ${UPDATE_NIGHTLY_HOME}/${updateSiteToClean} )
+    local relpath=$( relativize ${streamPath} ${UPDATE_NIGHTLY_HOME}/${updateSiteToClean} )
 
     LSINFO "Removing '${relpath}' from '${streamPath}'"
     composite-repository -location "${streamPath}" -remove "${relpath}"
@@ -125,7 +82,7 @@
                 LSCRITICAL "There are more than a single update site referenced in the repository ${latestInStreamPath}"
                 exit 1
             elif [ "${updateSiteURLToClean}" = "${latestUpdateSiteInStream[0]}" ]; then
-                relpath=$( relpath ${latestInStreamPath} ${UPDATE_NIGHTLY_HOME}/${updateSiteToClean} )
+                relpath=$( relativize ${latestInStreamPath} ${UPDATE_NIGHTLY_HOME}/${updateSiteToClean} )
                 LSINFO "Removing '${relpath}' from '${latestInStreamPath}'"
                 composite-repository -location "${latestInStreamPath}" -remove "${relpath}"
             fi
diff --git a/hudson-scripts/init/3_filesystem.sh b/hudson-scripts/init/3_filesystem.sh
new file mode 100644
index 0000000..5fa0f7a
--- /dev/null
+++ b/hudson-scripts/init/3_filesystem.sh
@@ -0,0 +1,60 @@
+#!/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
+# ====================================================================
+
+clean() {
+	local wd="${1}"
+
+	rm -rf "${wd}"
+}
+
+# retrieved from http://stackoverflow.com/a/12498485
+relativize() {
+    # both $1 and $2 are absolute paths beginning with /
+    # returns relative path to $2/$targetPath from $1/$sourcePath
+    local sourcePath=$1
+    local targetPath=$2
+
+    local common_part=$sourcePath # for now
+    local result="" # for now
+ 
+    while [[ "${targetPath#$common_part}" == "${targetPath}" ]]; do
+        # no match, means that candidate common part is not correct
+        # go up one level (reduce common part)
+
+        common_part="$(dirname $common_part)"
+        # and record that we went back, with correct / handling
+        if [[ -z $result ]]; then
+            result=".."
+        else
+            result="../$result"
+        fi
+    done
+
+    if [[ $common_part == "/" ]]; then
+        # special case for root (no common path)
+        result="$result/"
+    fi
+
+    # since we now have identified the common part,
+    # compute the non-common part
+    local forward_part="${targetPath#$common_part}"
+
+    # and now stick all parts together
+    if [[ -n $result ]] && [[ -n $forward_part ]]; then
+        result="$result$forward_part"
+    elif [[ -n $forward_part ]]; then
+        # extra slash removal
+        result="${forward_part:1}"
+    fi
+
+    echo $result
+}
diff --git a/hudson-scripts/init/3_update-site-publish.sh b/hudson-scripts/init/3_update-site-publish.sh
new file mode 100644
index 0000000..e144aa8
--- /dev/null
+++ b/hudson-scripts/init/3_update-site-publish.sh
@@ -0,0 +1,82 @@
+#!/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
+# ====================================================================
+
+_retrieveZippedArtifact() {
+	local artifactURL="${1}"
+	local localArtifact="${2}"
+	local unzipTo="${3}"
+
+	curl -s -k "${artifactURL}" > "${localArtifact}"
+
+	if [ -d "${unzipTo}" ]; then
+		rm -rf "${unzipTo}"
+	fi
+	unzip -qq "${localArtifact}" -d "${unzipTo}"
+}
+
+_publishUpdateSiteInStream() {
+	local projectName="${1}"
+	local category="${2}"
+	local home="${3}"
+	local qualifiedVersion="${4}"
+	local stream="${5}"
+
+	local repoLabelPrefix="${projectName}${stream:+ ${stream}.x}"
+
+	local streamPath="${home}${stream:+/${STREAMS_FOLDER}/${stream}.x}"
+	local relPathToUpdateSite=$( relativize "${streamPath}" "${home}/${qualifiedVersion}" )
+
+	LSDEBUG "Adding '${relPathToUpdateSite}' to composite repository '${streamPath}'"
+	composite-repository \
+		-location "${streamPath}" \
+		-add "${relPathToUpdateSite}" \
+		-repositoryName "${repoLabelPrefix} ${category} builds" \
+		-compressed
+		createP2Index "${streamPath}"
+
+	LSDEBUG "Updating latest of stream '${stream}' @ '${streamPath}'"
+	updateLatest "${streamPath}${streamPath:+/}${LATEST_FOLDER}" "${stream}" "${repoLabelPrefix} latest ${category} build"
+}
+
+publishUpdateSite() {
+	local wd="${1}"
+	local projectName="${2}"
+	local category="${3}"
+	local artifactURL="${4}"
+	local qualifiedVersion="${5}"
+	local home="${6}"
+
+	unqualifiedVersion="$(echo ${qualifiedVersion} | sed-regex 's/^([0-9]+\.[0-9]+\.[0-9]+)\..+$/\1/')"
+	LSDEBUG "unqualifiedVersion is '${unqualifiedVersion}'"
+	minorVersion="$(echo ${qualifiedVersion} | sed-regex 's/^([0-9]+\.[0-9]+)\.[0-9]+\..+$/\1/')"
+	LSDEBUG "Minor stream name is '${minorVersion}.x'"
+	majorVersion="$(echo ${qualifiedVersion} | sed-regex 's/^([0-9]+)\.[0-9]+\.[0-9]+\..+$/\1/')"
+	LSDEBUG "Major stream name is '${majorVersion}.x'"
+
+	# the update site
+	LSINFO "Downloading '${artifactURL}'"
+	_retrieveZippedArtifact "${artifactURL}" "${wd}/update-site-${qualifiedVersion}.zip" "${wd}/update-site-${qualifiedVersion}"
+
+	if [ ! -d "${home}/${qualifiedVersion}" ]; then
+		LSDEBUG "Creating folder '${home}/${qualifiedVersion}'"
+		mkdir -p "${home}/${qualifiedVersion}"
+	fi
+
+	LSINFO "Copying update site to '${home}/${qualifiedVersion}'"
+	cp -Rf "${wd}/update-site/"* "${home}/${qualifiedVersion}"
+
+	## streams update
+	_publishUpdateSiteInStream "${projectName}" "${category}" "${home}" "${qualifiedVersion}" "${unqualifiedVersion}"
+	_publishUpdateSiteInStream "${projectName}" "${category}" "${home}" "${qualifiedVersion}" "${minorVersion}"
+	_publishUpdateSiteInStream "${projectName}" "${category}" "${home}" "${qualifiedVersion}" "${majorVersion}"
+	_publishUpdateSiteInStream "${projectName}" "${category}" "${home}" "${qualifiedVersion}" ""
+}
diff --git a/hudson-scripts/publish-nightly.sh b/hudson-scripts/publish-nightly.sh
index c57af79..38c1204 100755
--- a/hudson-scripts/publish-nightly.sh
+++ b/hudson-scripts/publish-nightly.sh
@@ -27,65 +27,6 @@
 
 LSINFO "== Publishing nightly build '${PROJECT_NAME} ${qualifiedVersion}' == "
 
-unqualifiedVersion="$(echo ${qualifiedVersion} | sed-regex 's/^([0-9]+\.[0-9]+\.[0-9]+)\..+$/\1/')"
-LSDEBUG "unqualifiedVersion is '${unqualifiedVersion}'"
-minorVersion="$(echo ${qualifiedVersion} | sed-regex 's/^([0-9]+\.[0-9]+)\.[0-9]+\..+$/\1/')"
-LSDEBUG "Minor stream name is '${minorVersion}.x'"
-majorVersion="$(echo ${qualifiedVersion} | sed-regex 's/^([0-9]+)\.[0-9]+\.[0-9]+\..+$/\1/')"
-LSDEBUG "Major stream name is '${majorVersion}.x'"
-
-# the update site
-
-LSINFO "Downloading '${artifactURL}'"
-artifactName="update-site.zip"
-if [ -f "${WORKING_DIRECTORY}/${artifactName}" ]; then
-	rm -f "${WORKING_DIRECTORY}/${artifactName}"
-fi
-curl -s -k "${artifactURL}" > "${WORKING_DIRECTORY}/${artifactName}"
-
-LSINFO "Unziping '${artifactName}'"
-if [ -d "${WORKING_DIRECTORY}/update-site" ]; then
-	rm -rf "${WORKING_DIRECTORY}/update-site"
-fi
-unzip -qq "${WORKING_DIRECTORY}/${artifactName}" -d "${WORKING_DIRECTORY}/update-site"
-
-if [ ! -d "${UPDATE_NIGHTLY_HOME}/${qualifiedVersion}" ]; then
-	LSINFO "Creating folder '${UPDATE_NIGHTLY_HOME}'"
-	mkdir -p "${UPDATE_NIGHTLY_HOME}/${qualifiedVersion}"
-else
-	LSDEBUG "Folder '${WORKING_DIRECTORY}/${UPDATE_NIGHTLY_HOME}' already exists, do nothing"
-fi
-LSINFO "Copying update site to '${UPDATE_NIGHTLY_HOME}'"
-cp -rf "${WORKING_DIRECTORY}/update-site/"* "${UPDATE_NIGHTLY_HOME}/${qualifiedVersion}"
-
-## streams update
-
-updateStream() {
-	local pathToVersion="${1}"
-	local stream="${2}"
-
-	local streamPath="${stream:+streams/${stream}.x}"
-	local repoPrefix="${PROJECT_NAME}${stream:+ ${stream}.x}"
-
-	LSINFO "Adding '${pathToVersion}' to '${UPDATE_NIGHTLY_HOME}/${streamPath}'"
-
-	composite-repository \
-		-location "${UPDATE_NIGHTLY_HOME}/${streamPath}" \
-		-add "${pathToVersion}" \
-		-repositoryName "${repoPrefix} nightly builds" \
-		-compressed
-		createP2Index "${UPDATE_NIGHTLY_HOME}/${streamPath}"
-
-	updateLatest "${UPDATE_NIGHTLY_HOME}/${streamPath}${streamPath:+/}latest" "${stream}" "${repoPrefix} latest nightly build"
-}
-
-updateStream "../../${qualifiedVersion}" "${unqualifiedVersion}"
-updateStream "../../${qualifiedVersion}" "${minorVersion}"
-updateStream "../../${qualifiedVersion}" "${majorVersion}"
-updateStream "${qualifiedVersion}"       ""
+publishUpdateSite "${WORKING_DIRECTORY}" "${PROJECT_NAME}" "nightly" "${artifactURL}" "${qualifiedVersion}" "${UPDATE_NIGHTLY_HOME}"
 
 LSINFO "== '${PROJECT_NAME} ${qualifiedVersion}' has been published @ '${UPDATE_NIGHTLY_URL}/${qualifiedVersion}' == "
-
-# the javadoc
-
-# the documentation