Added new template for java release jobs.

Change-Id: I995dc629a24253cf4dfd97858462254db90ca684
Signed-off-by: Carsten Lund <lund@research.att.com>
diff --git a/jjb/dcae/dcae-controller-analytics.yaml b/jjb/dcae/dcae-controller-analytics.yaml
index 8b20f01..18f0cc0 100644
--- a/jjb/dcae/dcae-controller-analytics.yaml
+++ b/jjb/dcae/dcae-controller-analytics.yaml
@@ -9,7 +9,7 @@
     jobs:
       - '{project-name}-{stream}-{subproject}-verify-java'
       - '{project-name}-{stream}-{subproject}-merge-java'
-      - '{project-name}-{stream}-{subproject}-release-java-daily'
+      - '{project-name}-{stream}-{subproject}-release-version2-java-daily'
 
     project: 'dcae/controller/analytics'
     stream:
diff --git a/jjb/dcae/dcae-controller.yaml b/jjb/dcae/dcae-controller.yaml
index 176821b..bddf1ee 100644
--- a/jjb/dcae/dcae-controller.yaml
+++ b/jjb/dcae/dcae-controller.yaml
@@ -5,7 +5,7 @@
     jobs:
       - '{project-name}-{stream}-verify-java'
       - '{project-name}-{stream}-merge-java'
-      - '{project-name}-{stream}-release-java-daily'
+      - '{project-name}-{stream}-release-version2-java-daily'
 
     project: 'dcae/controller'
     stream:
diff --git a/jjb/dcae/dcae-operation-utils.yaml b/jjb/dcae/dcae-operation-utils.yaml
index 035ee4a..ffbd9ca 100644
--- a/jjb/dcae/dcae-operation-utils.yaml
+++ b/jjb/dcae/dcae-operation-utils.yaml
@@ -9,7 +9,7 @@
     jobs:
       - '{project-name}-{stream}-{subproject}-verify-java'
       - '{project-name}-{stream}-{subproject}-merge-java'
-      - '{project-name}-{stream}-{subproject}-release-java-daily'
+      - '{project-name}-{stream}-{subproject}-release-version2-java-daily'
 
     project: 'dcae/operation/utils'
     stream:
diff --git a/jjb/global-templates-java.yaml b/jjb/global-templates-java.yaml
index 7b173e9..3560ec4 100644
--- a/jjb/global-templates-java.yaml
+++ b/jjb/global-templates-java.yaml
@@ -709,3 +709,143 @@
             - docker.push.registry=nexus3.openecomp.org:10003
 
       - shell: !include-raw: include-docker-push.sh
+
+- job-template:
+    # Job template for Java daily release jobs
+    #
+    # The purpose of this job template is to run
+    #   - change version in all POM files to the release version specified
+    #     in version.properties. This is done using a script instread of
+    #     the mvn version plugin that assumes some specific parent structure.
+    #   - runs maven clean deploy sonar
+    #
+    # The POM files are required to use the Maven staging plugin so the deploy
+    # does not deploy directly to the release repo.
+    #
+    # Required Variables:
+    #     branch:    git branch (eg. stable/lithium or master)
+    name: '{project-name}-{stream}-release-version2-java-daily'
+
+    project-type: freestyle
+    node: '{build-node}'
+    maven-deploy-properties:
+    properties:
+      - ecomp-infra-properties:
+          build-days-to-keep: '{build-days-to-keep}'
+
+    parameters:
+      - ecomp-infra-parameters:
+          project: '{project}'
+          branch: '{branch}'
+          refspec: 'refs/heads/{branch}'
+          artifacts: '{archive-artifacts}'
+
+    scm:
+      - gerrit-trigger-scm:
+          refspec: ''
+          choosing-strategy: 'default'
+
+    wrappers:
+      - ecomp-infra-wrappers:
+          build-timeout: '{build-timeout}'
+
+    triggers:
+      # 11 AM UTC
+      - timed: 'H 11 * * *'
+      - gerrit-trigger-release-manually:
+          server: '{server-name}'
+          project: '{project}'
+          branch: '{branch}'
+
+    builders:
+      - provide-maven-settings:
+          global-settings-file: 'global-settings'
+          settings-file: '{mvn-settings}'
+
+      - inject:
+          properties-file: version.properties
+
+      - shell: !include-raw-escape: include-update-pom-versions.sh
+
+      - maven-target:
+          maven-version: 'mvn33'
+          goals: 'clean deploy sonar:sonar -Dsonar.host.url=https://sonar.openecomp.org'
+          properties:
+            - '{maven-deploy-properties}'
+          settings: '{mvn-settings}'
+          settings-type: cfp
+          global-settings: 'global-settings'
+          global-settings-type: cfp
+
+- job-template:
+    # Job template for Java daily release jobs
+    #
+    # The purpose of this job template is to run
+    #   - change version in all POM files to the release version specified
+    #     in version.properties. This is done using a script instread of
+    #     the mvn version plugin that assumes some specific parent structure.
+    #   - runs maven clean deploy sonar
+    #
+    # The POM files are required to use the Maven staging plugin so the deploy
+    # does not deploy directly to the release repo.
+    #
+    # Required Variables:
+    #     branch:    git branch (eg. stable/lithium or master)
+    #     pom:       name/location of the pom.xml file relative to the workspace
+    #     pattern:   ant file-path pattern relative to the workspace used to
+    #                trigger the job
+
+    name: '{project-name}-{stream}-{subproject}-release-version2-java-daily'
+
+    project-type: freestyle
+    node: '{build-node}'
+    maven-deploy-properties:
+    properties:
+      - ecomp-infra-properties:
+          build-days-to-keep: '{build-days-to-keep}'
+
+    parameters:
+      - ecomp-infra-parameters:
+          project: '{project}'
+          branch: '{branch}'
+          refspec: 'refs/heads/{branch}'
+          artifacts: '{archive-artifacts}'
+
+    scm:
+      - gerrit-trigger-scm:
+          refspec: ''
+          choosing-strategy: 'default'
+
+    wrappers:
+      - ecomp-infra-wrappers:
+          build-timeout: '{build-timeout}'
+
+    triggers:
+      # 11 AM UTC
+      - timed: 'H 11 * * *'
+      - gerrit-trigger-release-manually:
+          server: '{server-name}'
+          project: '{project}'
+          branch: '{branch}'
+          files: '{pattern}'
+
+    builders:
+      - provide-maven-settings:
+          global-settings-file: 'global-settings'
+          settings-file: '{mvn-settings}'
+
+      - inject:
+          properties-file: version.properties
+
+      - shell: !include-raw-escape: include-update-pom-versions.sh
+
+      - maven-target:
+          maven-version: 'mvn33'
+          pom: '{pom}'
+          goals: 'clean deploy sonar:sonar -Dsonar.host.url=https://sonar.openecomp.org'
+          properties:
+            - '{maven-deploy-properties}'
+          settings: '{mvn-settings}'
+          settings-type: cfp
+          global-settings: 'global-settings'
+          global-settings-type: cfp
diff --git a/jjb/include-update-pom-versions.sh b/jjb/include-update-pom-versions.sh
new file mode 100644
index 0000000..0e269a2
--- /dev/null
+++ b/jjb/include-update-pom-versions.sh
@@ -0,0 +1,28 @@
+#!/bin/bash
+
+## Will update POM in workspace with release version
+
+if [ ! -e version.properties ]; then
+    echo "Missing version.properties"
+    exit 1
+fi
+
+## will setup variable release_version
+source ./version.properties
+
+VERSION=$release_version
+
+## handle POM files with no parent
+for file in $(find . -name pom.xml); do
+    if [ "$(grep -c '<parent>' $file)" == "0" ]; then
+        (
+            cd $(dirname $file)
+            ${MVN} versions:set versions:commit \
+                -DnewVersion=$VERSION \
+                -DprocessDependencies=false
+        )
+    fi
+done
+
+find . -name pom.xml.versionsBackup -delete
+
diff --git a/jjb/ncomp/ncomp-cdap.yaml b/jjb/ncomp/ncomp-cdap.yaml
index 6b3f4f7..b3d0111 100644
--- a/jjb/ncomp/ncomp-cdap.yaml
+++ b/jjb/ncomp/ncomp-cdap.yaml
@@ -5,7 +5,7 @@
     jobs:
       - '{project-name}-{stream}-verify-java'
       - '{project-name}-{stream}-merge-java'
-      - '{project-name}-{stream}-release-java-daily'
+      - '{project-name}-{stream}-release-version2-java-daily'
 
     project: 'ncomp/cdap'
     stream:
diff --git a/jjb/ncomp/ncomp-core.yaml b/jjb/ncomp/ncomp-core.yaml
index 675e7ad..b218dfe 100644
--- a/jjb/ncomp/ncomp-core.yaml
+++ b/jjb/ncomp/ncomp-core.yaml
@@ -5,7 +5,7 @@
     jobs:
       - '{project-name}-{stream}-verify-java'
       - '{project-name}-{stream}-merge-java'
-      - '{project-name}-{stream}-release-java-daily'
+      - '{project-name}-{stream}-release-version2-java-daily'
 
     project: 'ncomp/core'
     stream:
diff --git a/jjb/ncomp/ncomp-docker.yaml b/jjb/ncomp/ncomp-docker.yaml
index 6603b16..9859c09 100644
--- a/jjb/ncomp/ncomp-docker.yaml
+++ b/jjb/ncomp/ncomp-docker.yaml
@@ -5,7 +5,7 @@
     jobs:
       - '{project-name}-{stream}-verify-java'
       - '{project-name}-{stream}-merge-java'
-      - '{project-name}-{stream}-release-java-daily'
+      - '{project-name}-{stream}-release-version2-java-daily'
 
     project: 'ncomp/docker'
     stream:
diff --git a/jjb/ncomp/ncomp-maven.yaml b/jjb/ncomp/ncomp-maven.yaml
index 2bc55d4..7600d65 100644
--- a/jjb/ncomp/ncomp-maven.yaml
+++ b/jjb/ncomp/ncomp-maven.yaml
@@ -5,7 +5,7 @@
     jobs:
       - '{project-name}-{stream}-verify-java'
       - '{project-name}-{stream}-merge-java'
-      - '{project-name}-{stream}-release-java-daily'
+      - '{project-name}-{stream}-release-version2-java-daily'
 
     project: 'ncomp/maven'
     stream:
diff --git a/jjb/ncomp/ncomp-openstack.yaml b/jjb/ncomp/ncomp-openstack.yaml
index e2a0207..e7da948 100644
--- a/jjb/ncomp/ncomp-openstack.yaml
+++ b/jjb/ncomp/ncomp-openstack.yaml
@@ -5,7 +5,7 @@
     jobs:
       - '{project-name}-{stream}-verify-java'
       - '{project-name}-{stream}-merge-java'
-      - '{project-name}-{stream}-release-java-daily'
+      - '{project-name}-{stream}-release-version2-java-daily'
 
     project: 'ncomp/openstack'
     stream:
diff --git a/jjb/ncomp/ncomp-sirius-manager.yaml b/jjb/ncomp/ncomp-sirius-manager.yaml
index f33fa95..ec95646 100644
--- a/jjb/ncomp/ncomp-sirius-manager.yaml
+++ b/jjb/ncomp/ncomp-sirius-manager.yaml
@@ -5,7 +5,7 @@
     jobs:
       - '{project-name}-{stream}-verify-java'
       - '{project-name}-{stream}-merge-java'
-      - '{project-name}-{stream}-release-java-daily'
+      - '{project-name}-{stream}-release-version2-java-daily'
 
     project: 'ncomp/sirius/manager'
     stream:
diff --git a/jjb/ncomp/ncomp-utils.yaml b/jjb/ncomp/ncomp-utils.yaml
index 0efcb1f..9bfc4ca 100644
--- a/jjb/ncomp/ncomp-utils.yaml
+++ b/jjb/ncomp/ncomp-utils.yaml
@@ -4,9 +4,8 @@
     project-name: 'ncomp-utils'
     jobs:
       - '{project-name}-{stream}-verify-java'
-      - '{project-name}-{stream}-downstream-merge-java':
-          dependencies: 'ncomp-master-merge-java'
-      - '{project-name}-{stream}-release-java-daily'
+      - '{project-name}-{stream}-merge-java':
+      - '{project-name}-{stream}-release-version2-java-daily'
 
     project: 'ncomp/utils'
     stream: