From: Jessica Wagantall Date: Wed, 24 Jan 2018 00:31:47 +0000 (-0800) Subject: Add script to update Java alternatives X-Git-Tag: v0.16.0~17 X-Git-Url: https://gerrit.linuxfoundation.org/infra/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F93%2F8493%2F15;p=releng%2Fglobal-jjb.git Add script to update Java alternatives Use ${java-version} to set the correct java, javac and java_sdk_openjdk alternative for lf-maven-jobs. Issue-ID: RELENG-752 Change-Id: Iff0c2e7d92c4cc802925ae67cdda1f4247db52be Signed-off-by: Jessica Wagantall --- diff --git a/jjb/lf-maven-jobs.yaml b/jjb/lf-maven-jobs.yaml index 988eebd2..cc711a66 100644 --- a/jjb/lf-maven-jobs.yaml +++ b/jjb/lf-maven-jobs.yaml @@ -59,6 +59,15 @@ - ../shell/common-variables.sh - ../shell/maven-deploy.sh +- builder: + name: lf-update-java-alternatives + builders: + - inject: + properties-content: 'SET_JDK_VERSION={java-version}' + - shell: !include-raw-escape: ../shell/update-java-alternatives.sh + - inject: + properties-file: '/tmp/java.env' + #################### # COMMON FUNCTIONS # #################### @@ -170,6 +179,8 @@ builders: - lf-maven-install: mvn-version: '{mvn-version}' + - lf-update-java-alternatives: + java-version: '{java-version}' - lf-provide-maven-settings: global-settings-file: '{mvn-global-settings}' settings-file: '{mvn-settings}' @@ -266,6 +277,8 @@ builders: - lf-maven-install: mvn-version: '{mvn-version}' + - lf-update-java-alternatives: + java-version: '{java-version}' - lf-provide-maven-settings: global-settings-file: '{mvn-global-settings}' settings-file: '{mvn-settings}' @@ -385,6 +398,8 @@ builders: - lf-maven-install: mvn-version: '{mvn-version}' + - lf-update-java-alternatives: + java-version: '{java-version}' - lf-provide-maven-settings: global-settings-file: '{mvn-global-settings}' settings-file: '{mvn-settings}' @@ -498,6 +513,8 @@ - lf-jacoco-nojava-workaround - lf-maven-install: mvn-version: '{mvn-version}' + - lf-update-java-alternatives: + java-version: '{java-version}' - lf-provide-maven-settings: global-settings-file: '{mvn-global-settings}' settings-file: '{mvn-settings}' @@ -619,6 +636,8 @@ - lf-jacoco-nojava-workaround - lf-maven-install: mvn-version: '{mvn-version}' + - lf-update-java-alternatives: + java-version: '{java-version}' - lf-provide-maven-settings: global-settings-file: '{mvn-global-settings}' settings-file: '{mvn-settings}' @@ -771,6 +790,7 @@ builders: - lf-infra-maven-sonar: + java-version: '{java-version}' mvn-settings: '{mvn-settings}' mvn-version: '{mvn-version}' @@ -785,6 +805,8 @@ builders: - lf-maven-install: mvn-version: '{mvn-version}' + - lf-update-java-alternatives: + java-version: '{java-version}' - inject: # Switch this to the sonar wrapper when JJB 2.0 is available properties-content: SONAR_HOST_URL=$SONAR_URL @@ -891,6 +913,8 @@ - lf-jacoco-nojava-workaround - lf-maven-install: mvn-version: '{mvn-version}' + - lf-update-java-alternatives: + java-version: '{java-version}' - lf-provide-maven-settings: global-settings-file: '{mvn-global-settings}' settings-file: '{mvn-settings}' @@ -1007,6 +1031,8 @@ - lf-jacoco-nojava-workaround - lf-maven-install: mvn-version: '{mvn-version}' + - lf-update-java-alternatives: + java-version: '{java-version}' - lf-provide-maven-settings: global-settings-file: '{mvn-global-settings}' settings-file: '{mvn-settings}' diff --git a/shell/update-java-alternatives.sh b/shell/update-java-alternatives.sh new file mode 100644 index 00000000..29f6d38d --- /dev/null +++ b/shell/update-java-alternatives.sh @@ -0,0 +1,53 @@ +#!/bin/bash +# SPDX-License-Identifier: EPL-1.0 +############################################################################## +# Copyright (c) 2018 The Linux Foundation and others. +# +# 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 +############################################################################## + +# This script takes the java-version variable to set the proper alternative +# for java, javac and java_sdk_openjdk for ubuntu or centos/fedora/redhat distros + +JAVA_ENV_FILE="/tmp/java.env" + +update-java-redhat() { + export JAVA_HOME="/usr/lib/jvm/java-1.${SET_JDK_VERSION: -1}.0-openjdk" + sudo /usr/sbin/alternatives --install /usr/bin/java java "${JAVA_HOME}/bin/java" 1 + sudo /usr/sbin/alternatives --install /usr/bin/javac javac "${JAVA_HOME}/bin/javac" 1 + sudo /usr/sbin/alternatives --install /usr/lib/jvm/java-openjdk java_sdk_openjdk "${JAVA_HOME}" 1 + sudo /usr/sbin/alternatives --set java "${JAVA_HOME}/bin/java" + sudo /usr/sbin/alternatives --set javac "${JAVA_HOME}/bin/javac" + sudo /usr/sbin/alternatives --set java_sdk_openjdk "${JAVA_HOME}" + echo JAVA_HOME="$JAVA_HOME" > "$JAVA_ENV_FILE" +} + +update-java-ubuntu() { + export JAVA_HOME="/usr/lib/jvm/java-${SET_JDK_VERSION: -1}-openjdk-amd64" + sudo /usr/bin/update-alternatives --install /usr/bin/java java "${JAVA_HOME}/bin/java" 1 + sudo /usr/bin/update-alternatives --install /usr/bin/javac javac "${JAVA_HOME}/bin/javac" 1 + sudo /usr/bin/update-alternatives --install /usr/lib/jvm/java-openjdk java_sdk_openjdk "${JAVA_HOME}" 1 + sudo /usr/bin/update-alternatives --set java "${JAVA_HOME}/bin/java" + sudo /usr/bin/update-alternatives --set javac "${JAVA_HOME}/bin/javac" + sudo /usr/bin/update-alternatives --set java_sdk_openjdk "${JAVA_HOME}" + echo JAVA_HOME="$JAVA_HOME" > "$JAVA_ENV_FILE" +} + +echo "---> Updating Java version" +OS=$(facter operatingsystem | tr '[:upper:]' '[:lower:]') + +case "${OS}" in + fedora|centos|redhat) + echo "---> RedHat type system detected" + update-java-redhat + ;; + ubuntu) + echo "---> Ubuntu system detected" + update-java-ubuntu + ;; +esac +java -version +echo JAVA_HOME="${JAVA_HOME}"