HusdonBuild: latest publish script updates.
diff --git a/cleanNightly.sh b/cleanNightly.sh
index 9aa15b1..877d048 100644
--- a/cleanNightly.sh
+++ b/cleanNightly.sh
@@ -1,7 +1,22 @@
 # !/bin/sh
 #set -x
 
-version=2.5.0
+version=$1
+
+unset usage
+usage() {
+    echo " "
+    echo "Usage: `basename $0` [version]"
+    echo "  version  Name of version for which old builds will be cleaned."
+}
+
+if [ \( -z "$version" \) -o \( "$version" = "" \) ] ; then
+    usage
+    exit
+else
+   echo "Purging old builds of '${version}'..."
+fi
+
 BaseDownloadNFSDir="/home/data/httpd/download.eclipse.org/rt/eclipselink"
 buildir=/shared/rt/eclipselink
 
diff --git a/cron.txt b/cron.txt
index 2efff89..adce4fe 100644
--- a/cron.txt
+++ b/cron.txt
@@ -1,10 +1,14 @@
-#Min Hour Month Day Day-of-week(0=Sunday) Command
-05 0    * * 0-6     nice -n 10 /shared/rt/eclipselink/bootstrap.sh nightly > /shared/rt/eclipselink/logs/nightly220.log 2>&1
-05 1    * * 0-6     nice -n 10 /shared/rt/eclipselink/bootstrap.sh nightly 2.1 > /shared/rt/eclipselink/logs/nightly211.log 2>&1
-05 3    * * 0,2,4,6 nice -n 10 /shared/rt/eclipselink/bootstrap.sh nightly 2.0 > /shared/rt/eclipselink/logs/nightly203.log 2>&1
-05 3    * * 1,3,5   nice -n 10 /shared/rt/eclipselink/bootstrap.sh nightly 1.2 > /shared/rt/eclipselink/logs/nightly120.log 2>&1
-0,20,40 * * * *     chmod 774 /shared/rt/eclipselink/trunk/buildsystem/*.sh 
-1,21,41 * * * *     /shared/rt/eclipselink/trunk/buildsystem/buildNightlyList-cron.sh > /shared/rt/eclipselink/logs/genNightlyResults.log 2>&1
-5,25,45 1-9 * * *   /shared/rt/eclipselink/trunk/buildsystem/publish.sh > /shared/rt/eclipselink/logs/processHandoff.log 2>&1
-10,30,50 6-20 * * * /shared/rt/eclipselink/trunk/buildsystem/buildFailureList.sh > /shared/rt/eclipselink/logs/genFailRes.log 2>&1
+#Min Hour Month Day Day-of-week(0&7=Sunday) Command
+# Cronn tasks to clean the test DBs before the nightly run
+50 11 * * * /shared/rt/eclipselink/eclipselink.releng/cleanDb.sh master > /shared/rt/eclipselink/logs/cleanDbMAster.log 2>&1
+53 11 * * * /shared/rt/eclipselink/eclipselink.releng/cleanDb.sh 2.4 > /shared/rt/eclipselink/logs/cleanDb24.log 2>&1
+56 11 * * * /shared/rt/eclipselink/eclipselink.releng/cleanDb.sh 2.3 > /shared/rt/eclipselink/logs/cleanDb23.log 2>&1
+# generic publishing and processing tasks
+0,20,40  *    * * *   chmod 774 /shared/rt/eclipselink/eclipselink.releng/*.sh
+5,25,45  1-18 * * *   /shared/rt/eclipselink/eclipselink.releng/publish.sh > /shared/rt/eclipselink/logs/processHandoff.log 2>&1
+11,31,51 1-18 * * *   /shared/rt/eclipselink/eclipselink.releng/buildNightlyList-cron.sh > /shared/rt/eclipselink/logs/genNightlyResults.log 2>&1
+# cron jobs to clean up old builds
+5  5 * * * /shared/rt/eclipselink/eclipselink.releng/cleanNightly.sh 2.5.0 > /shared/rt/eclipselink/logs/cleanBuild250.log 2>&1
+10 5 * * * /shared/rt/eclipselink/eclipselink.releng/cleanNightly.sh 2.4.1 > /shared/rt/eclipselink/logs/cleanBuild241.log 2>&1
+#15 5 * * * /shared/rt/eclipselink/eclipselink.releng/cleanNightly.sh 2.3.2 > /shared/rt/eclipselink/logs/cleanBuild232.log 2>&1
 
diff --git a/publish.sh b/publish.sh
index 272a4a8..bcd226c 100644
--- a/publish.sh
+++ b/publish.sh
@@ -31,12 +31,8 @@
 #Files
 ANT_BLDFILE=publishbuild.xml
 
-# Need to export after parsing:
-# BLD_DEPS_DIR
-# BRANCH
-# GITHASH
-# BLDDATE
-# handoff
+#Global Variables
+PUB_SCOPE_EXPECTED=0
 
 PATH=${JAVA_HOME}/bin:${ANT_HOME}/bin:/usr/bin:/usr/local/bin:${PATH}
 
@@ -184,12 +180,59 @@
     fi
 }
 
-## Set an expected variable "ProcExpected" and "ProcSuccessful"
-## compare at end and if match delete local build artifacts
-## and handoff file.
-# 100 - artifacts to pub
-#  10 - p2 to pub
-#   1 - maven to pub (should be set if 100 = true)
+unset establishPublishScope
+establishPublishScope() {
+    # Usage: establishPublishScope src
+    src=$1
+
+    ## To test success set variables "PUB_SCOPE_EXPECTED" and "PUB_SCOPE_COMPLETED"
+    ## compare at end and if match delete local build artifacts
+    ## and handoff file.
+    # 100 - artifacts to pub
+    #  10 - p2 to pub
+    #   1 - maven to pub (should be set if 100 = true, but only need eclipselink.jar and bundle.zip)
+
+    #reset PUB_SCOPE_EXPECTED for this handoff instance
+    PUB_SCOPE_EXPECTED=0
+
+    # search for zip files in src meaning need to publish artifacts
+    srcZipCount=`ls ${src} | grep -c [.]zip$`
+    if [ "${srcZipCount}" -gt 0 ] ; then
+        PUB_SCOPE_EXPECTED=`expr ${PUB_SCOPE_EXPECTED} + 100`
+        echo "Zip archives detected. Logging 'Archive publish' within scope."
+    else
+        echo "No zip archives detected. 'Archive publish' beyond scope."
+    fi
+
+    # search for p2repo dir, meaning need to publish P2
+    # search for zip files in src meaning need to publish artifacts
+    srcP2Count=`ls ${src} | grep -c p2repo`
+    if [ \( ! "${srcP2Count}" = "0" \) ] ; then
+        srcP2jarCount=`ls -r ${src}/p2repo/* | grep -c [.]jar$`
+        if [ "${srcP2jarCount}" -gt 0 ] ; then
+            PUB_SCOPE_EXPECTED=`expr ${PUB_SCOPE_EXPECTED} + 10`
+            echo "Viable p2repo found. Logging 'p2 publish' within scope"
+        else
+            echo "p2repo dir found, but it is empty to publish. 'P2 publish' beyond scope."
+        fi
+    else
+        echo "No p2repo found. 'P2 publish' beyond scope."
+    fi
+
+    # search for bundle zip and eclipselink.jar, meaning can/need to generate maven
+    srcELJarCount=`ls ${src} | grep -c eclipselink[.]jar$`
+    srcpluginZipCount=`ls ${src} | grep -c eclipselink-plugins`
+    if [ "${srcELJarCount}" -gt 0 ] ; then
+        if [ "${srcpluginZipCount}" -gt 0 ] ; then
+            PUB_SCOPE_EXPECTED=`expr ${PUB_SCOPE_EXPECTED} + 1`
+            echo "Basic components available for mavenpublish. Logging 'Maven publish' as within scope."
+        else
+            echo "No bundle archives detected. Maven publish beyond scope."
+        fi
+    else
+        echo "No eclipselink.jar detected. Maven publish beyond scope."
+    fi
+}
 
 unset publishBuildArtifacts
 publishBuildArtifacts() {
@@ -540,10 +583,18 @@
     # Do stuff
     parseHandoff ${handoff}
     if [ "$PROC" = "build" ] ; then
-       publishBuildArtifacts ${BUILD_ARCHIVE_LOC} ${DNLD_DIR} ${VERSION} ${BLDDATE} ${TIMESTAMP}
-       publishP2Repo ${BUILD_ARCHIVE_LOC} ${DNLD_DIR} ${VERSION} ${QUALIFIER}
-
+       establishPublishScope ${BUILD_ARCHIVE_LOC}
+       if [ "${PUB_SCOPE_EXPECTED}" -ge 100 ] ; then
+           publishBuildArtifacts ${BUILD_ARCHIVE_LOC} ${DNLD_DIR} ${VERSION} ${BLDDATE} ${TIMESTAMP}
+       fi
+       if [ "${PUB_SCOPE_EXPECTED}" -ge 10 ] ; then
+           publishP2Repo ${BUILD_ARCHIVE_LOC} ${DNLD_DIR} ${VERSION} ${QUALIFIER}
+       fi
+       if [ "${PUB_SCOPE_EXPECTED}" -ge 10 ] ; then
+           echo "Could call publishMavenRepo() if ready"
+       fi
     else
+       PUB_SCOPE_EXPECTED=0
        publishTestArtifacts ${BUILD_ARCHIVE_LOC} ${DNLD_DIR} ${VERSION} ${BLDDATE} ${HOST}
     fi
     #runAnt ${BRANCH} ${QUALIFIER} ${PROC} ${BUILD_ARCHIVE_LOC} ${HOST}
@@ -558,7 +609,12 @@
  # ${MAVEN_TAG}
  # ${VERSION}
  # ${TIMESTAMP}
-    if [ "${ERROR}" = "false" ] ; then
+    if [ "${PUB_SCOPE_EXPECTED}" = "${PUB_SCOPE_COMPLETED}" ] ; then
+       echo "Success: can now delete '${handoff}' and '${BUILD_ARCHIVE_LOC}'"
+    else
+       echo "Full processing failed: Cannot remove '${handoff}' and '${BUILD_ARCHIVE_LOC}'"
+    fi
+    if [ "${ERROR} " = "false" ] ; then
         echo "Processing of '${handoff}' complete."
         # remove handoff
         #rm ${handoff}
@@ -568,7 +624,7 @@
         #rm ${BUILD_ARCHIVE_LOC}/*  # Gets rid of the bulk of the artifacts, but will leave the dir heirarchy
         echo "   Removing '${BUILD_ARCHIVE_LOC}/*'. (not!)"
     else
-        # Repost error
+        # Report error
         echo "Error processing of '${handoff}'."
         echo "    Deletion aborted..."
     fi