Refactor: future-proof Java version selector 08/69808/3
authorRobert Varga <nite@hq.sk>
Mon, 7 Mar 2022 07:01:55 +0000 (08:01 +0100)
committerRobert Varga <nite@hq.sk>
Mon, 7 Mar 2022 12:33:25 +0000 (13:33 +0100)
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 <nite@hq.sk>
shell/update-java-alternatives.sh

index 39f4699..0bed1ec 100644 (file)
@@ -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