- ../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 #
####################
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}'
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}'
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}'
- 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}'
- 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}'
builders:
- lf-infra-maven-sonar:
+ java-version: '{java-version}'
mvn-settings: '{mvn-settings}'
mvn-version: '{mvn-version}'
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
- 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}'
- 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}'
--- /dev/null
+#!/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}"