From: Robert Varga Date: Mon, 7 Mar 2022 07:01:55 +0000 (+0100) Subject: Refactor: future-proof Java version selector X-Git-Tag: v0.75.0~2 X-Git-Url: https://gerrit.linuxfoundation.org/infra/gitweb?a=commitdiff_plain;h=6ac0bf5299e266b27215e61c80a92f9057197779;p=releng%2Fglobal-jjb.git Refactor: future-proof Java version selector In terms of Java versioning we have version epoch transition: - Java 7 and Java 8 use 1.[7,8].0 as their version - Java 9 and later use plain {9,10,...} as their version Adjust the version matching machinery to cover not only Java 11/12, but all future versions -- assuming versioning schema does not change. Change-Id: I9b12223c39780353bd8921af4ce8ba1349fbcf13 Signed-off-by: Robert Varga --- diff --git a/shell/update-java-alternatives.sh b/shell/update-java-alternatives.sh index 39f46991..0bed1ec2 100644 --- a/shell/update-java-alternatives.sh +++ b/shell/update-java-alternatives.sh @@ -15,13 +15,12 @@ echo "---> update-java-alternatives.sh" JAVA_ENV_FILE="/tmp/java.env" update-java-redhat() { - if [[ "${SET_JDK_VERSION//[a-zA-Z]/}" = "11" ]]; then - export JAVA_HOME="/usr/lib/jvm/java-11-openjdk" - elif [[ "${SET_JDK_VERSION//[a-zA-Z]/}" = "12" ]]; then - export JAVA_HOME="/usr/lib/jvm/java-12-openjdk" - elif [[ "${SET_JDK_VERSION//[a-zA-Z]/}" = "17" ]]; then - export JAVA_HOME="/usr/lib/jvm/java-17-openjdk" + JAVA_RELEASE=${SET_JDK_VERSION//[a-zA-Z]/} + if [[ ${JAVA_RELEASE} -ge 9 ]]; then + # Java 9 or newer: new version format + export JAVA_HOME="/usr/lib/jvm/java-${JAVA_RELEASE}-openjdk" else + # Java 8 or older: old version format export JAVA_HOME="/usr/lib/jvm/java-1.${SET_JDK_VERSION//[a-zA-Z:-]/}.0-openjdk" fi sudo /usr/sbin/alternatives --install /usr/bin/java java "${JAVA_HOME}/bin/java" 1