diff options
author | Samruddhi Khandale <skhandale@microsoft.com> | 2022-07-14 22:16:55 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-14 22:16:55 +0300 |
commit | 27e63203fa96543d287128b91fa02766fe687069 (patch) | |
tree | adfcf051b7d82ba7f77943c8162c2c130566cbef /src/java | |
parent | 330429ebb3b858e73f458dea9f43b6f89065826b (diff) |
Java: Install additional versions (#62)
* Java: Install additional versions
* nit
* tweak: to unblock git merge
* nit
Diffstat (limited to 'src/java')
-rw-r--r-- | src/java/devcontainer-feature.json | 6 | ||||
-rw-r--r-- | src/java/install.sh | 44 |
2 files changed, 35 insertions, 15 deletions
diff --git a/src/java/devcontainer-feature.json b/src/java/devcontainer-feature.json index 20cae3d..11566ae 100644 --- a/src/java/devcontainer-feature.json +++ b/src/java/devcontainer-feature.json @@ -27,9 +27,5 @@ }, "settings": { "java.import.gradle.java.home": "/usr/local/sdkman/candidates/java/current" - }, - "install": { - "app": "", - "file": "install.sh" } -}
\ No newline at end of file +} diff --git a/src/java/install.sh b/src/java/install.sh index 468d838..64646fa 100644 --- a/src/java/install.sh +++ b/src/java/install.sh @@ -15,6 +15,10 @@ export SDKMAN_DIR=${SDKMAN_DIR:-"/usr/local/sdkman"} USERNAME=${USERNAME:-"automatic"} UPDATE_RC=${UPDATE_RC:-"true"} +# Comma-separated list of java versions to be installed +# alongside JAVA_VERSION, but not set as default. +ADDITIONAL_VERSIONS=${ADDITIONAL_VERSIONS:-""} + set -e if [ "$(id -u)" -ne 0 ]; then @@ -75,6 +79,15 @@ check_packages() { fi } +# Use Microsoft JDK for everything but JDK 8 +jdk_distro="ms" +get_jdk_distro() { + VERSION="$1" + if echo "${VERSION}" | grep -E '^8([\s\.]|$)' > /dev/null 2>&1; then + jdk_distro="tem" + fi +} + # Use SDKMAN to install something using a partial version match sdk_install() { local install_type=$1 @@ -82,6 +95,7 @@ sdk_install() { local prefix=$3 local suffix="${4:-"\\s*"}" local full_version_check=${5:-".*-[a-z]+"} + local set_as_default=${6:-"true"} if [ "${requested_version}" = "none" ]; then return; fi # Blank will install latest stable version SDKMAN has if [ "${requested_version}" = "lts" ] || [ "${requested_version}" = "default" ]; then @@ -90,7 +104,7 @@ sdk_install() { echo "${requested_version}" else local regex="${prefix}\\K[0-9]+\\.[0-9]+\\.[0-9]+${suffix}" - local version_list="$(. ${SDKMAN_DIR}/bin/sdkman-init.sh && sdk list ${install_type} 2>&1 | grep -oP "${regex}" | tr -d ' ' | sort -rV)" + local version_list=$(su ${USERNAME} -c ". \${SDKMAN_DIR}/bin/sdkman-init.sh && sdk list ${install_type} 2>&1 | grep -oP \"${regex}\" | tr -d ' ' | sort -rV") if [ "${requested_version}" = "latest" ] || [ "${requested_version}" = "current" ]; then requested_version="$(echo "${version_list}" | head -n 1)" else @@ -103,6 +117,10 @@ sdk_install() { exit 1 fi fi + if [ "${set_as_default}" = "true" ]; then + JAVA_VERSION=${requested_version} + fi + su ${USERNAME} -c "umask 0002 && . ${SDKMAN_DIR}/bin/sdkman-init.sh && sdk install ${install_type} ${requested_version} && sdk flush archives && sdk flush temp" } @@ -133,14 +151,20 @@ if [ ! -d "${SDKMAN_DIR}" ]; then updaterc "export SDKMAN_DIR=${SDKMAN_DIR}\n. \${SDKMAN_DIR}/bin/sdkman-init.sh" fi -# Use Microsoft JDK for everything but JDK 8 -jdk_distro="ms" -if echo "${JAVA_VERSION}" | grep -E '^8([\s\.]|$)' > /dev/null 2>&1; then - jdk_distro="tem" -fi -if [ "${JAVA_VERSION}" = "lts" ]; then - JAVA_VERSION="17" +get_jdk_distro ${JAVA_VERSION} +sdk_install java ${JAVA_VERSION} "\\s*" "(\\.[a-z0-9]+)*-${jdk_distro}\\s*" ".*-[a-z]+$" "true" + +# Additional java versions to be installed but not be set as default. +if [ ! -z "${ADDITIONAL_VERSIONS}" ]; then + OLDIFS=$IFS + IFS="," + read -a additional_versions <<< "$ADDITIONAL_VERSIONS" + for version in "${additional_versions[@]}"; do + get_jdk_distro ${version} + sdk_install java ${version} "\\s*" "(\\.[a-z0-9]+)*-${jdk_distro}\\s*" ".*-[a-z]+$" "false" + done + IFS=$OLDIFS + su ${USERNAME} -c ". ${SDKMAN_DIR}/bin/sdkman-init.sh && sdk default java ${JAVA_VERSION}" fi -sdk_install java ${JAVA_VERSION} "\\s*" "(\\.[a-z0-9]+)*-${jdk_distro}\\s*" ".*-[a-z]+$" -echo "Done!"
\ No newline at end of file +echo "Done!" |