aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamruddhi Khandale <skhandale@microsoft.com>2022-09-24 00:25:58 +0300
committerGitHub <noreply@github.com>2022-09-24 00:25:58 +0300
commit3a28652790def9f3172561fa2907191bf5c0cab0 (patch)
tree24cd5a658ddb047f833a4a3a24a2683bb88fdf6e
parentceb4544cc38d4882a0294c79f4ef8123435cb027 (diff)
Java: add jdkDistro option (#172)
* add jdkDistro option * bump version
-rw-r--r--src/java/devcontainer-feature.json13
-rwxr-xr-xsrc/java/install.sh14
-rw-r--r--test/java/install_additional_java.sh2
-rw-r--r--test/java/install_from_non_default_distro.sh11
-rw-r--r--test/java/scenarios.json11
5 files changed, 42 insertions, 9 deletions
diff --git a/src/java/devcontainer-feature.json b/src/java/devcontainer-feature.json
index 4e7781b..3d8b8d8 100644
--- a/src/java/devcontainer-feature.json
+++ b/src/java/devcontainer-feature.json
@@ -1,6 +1,6 @@
{
"id": "java",
- "version": "1.0.8",
+ "version": "1.0.9",
"name": "Java (via SDKMAN!)",
"documentationURL": "https://github.com/devcontainers/features/tree/main/src/java",
"description": "Installs Java, SDKMAN! (if not installed), and needed dependencies.",
@@ -17,6 +17,17 @@
"default": "latest",
"description": "Select or enter a Java version to install"
},
+ "jdkDistro": {
+ "type": "string",
+ "proposals": [
+ "ms",
+ "open",
+ "oracle",
+ "tem"
+ ],
+ "default": "ms",
+ "description": "Select or enter a JDK distribution"
+ },
"installGradle": {
"type": "boolean",
"default": false,
diff --git a/src/java/install.sh b/src/java/install.sh
index 616a626..838f782 100755
--- a/src/java/install.sh
+++ b/src/java/install.sh
@@ -12,6 +12,7 @@
JAVA_VERSION=${VERSION:-"lts"}
INSTALL_GRADLE=${INSTALLGRADLE:-"false"}
INSTALL_MAVEN=${INSTALLMAVEN:-"false"}
+JDK_DISTRO=${JDKDISTRO}
export SDKMAN_DIR=${SDKMAN_DIR:-"/usr/local/sdkman"}
USERNAME=${USERNAME:-"automatic"}
@@ -76,12 +77,13 @@ check_packages() {
fi
}
-# Use Microsoft JDK for everything but JDK 8
-jdk_distro="ms"
+# Use Microsoft JDK for everything but JDK 8 and 18 (unless specified differently with jdkDistro option)
get_jdk_distro() {
VERSION="$1"
- if echo "${VERSION}" | grep -E '^8([\s\.]|$)' > /dev/null 2>&1; then
- jdk_distro="tem"
+ if [ "${JDK_DISTRO}" = "ms" ]; then
+ if echo "${VERSION}" | grep -E '^8([\s\.]|$)' > /dev/null 2>&1 || echo "${VERSION}" | grep -E '^18([\s\.]|$)' > /dev/null 2>&1; then
+ JDK_DISTRO="tem"
+ fi
fi
}
@@ -149,7 +151,7 @@ if [ ! -d "${SDKMAN_DIR}" ]; then
fi
get_jdk_distro ${JAVA_VERSION}
-sdk_install java ${JAVA_VERSION} "\\s*" "(\\.[a-z0-9]+)*-${jdk_distro}\\s*" ".*-[a-z]+$" "true"
+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
@@ -158,7 +160,7 @@ if [ ! -z "${ADDITIONAL_VERSIONS}" ]; then
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"
+ 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}"
diff --git a/test/java/install_additional_java.sh b/test/java/install_additional_java.sh
index a796fee..fcfd6bd 100644
--- a/test/java/install_additional_java.sh
+++ b/test/java/install_additional_java.sh
@@ -5,7 +5,7 @@ set -e
# Optional: Import test library
source dev-container-features-test-lib
-check "java version 17 installed as default" java --version | grep 17
+check "java version 18 installed as default" java --version | grep 18
check "java version 11 installed" ls /usr/local/sdkman/candidates/java | grep 11
check "java version 8 installed" ls /usr/local/sdkman/candidates/java | grep 8
diff --git a/test/java/install_from_non_default_distro.sh b/test/java/install_from_non_default_distro.sh
new file mode 100644
index 0000000..e45f9dd
--- /dev/null
+++ b/test/java/install_from_non_default_distro.sh
@@ -0,0 +1,11 @@
+#!/bin/bash
+
+set -e
+
+# Optional: Import test library
+source dev-container-features-test-lib
+
+check "java version 18 installed as default" java --version | grep 18
+
+# Report result
+reportResults
diff --git a/test/java/scenarios.json b/test/java/scenarios.json
index 82e0795..eec7ba5 100644
--- a/test/java/scenarios.json
+++ b/test/java/scenarios.json
@@ -1,9 +1,18 @@
{
+ "install_from_non_default_distro": {
+ "image": "ubuntu:focal",
+ "features": {
+ "java": {
+ "version": "18",
+ "jdkDistro": "open"
+ }
+ }
+ },
"install_additional_java": {
"image": "ubuntu:focal",
"features": {
"java": {
- "version": "17",
+ "version": "18",
"additionalVersions": "11,8"
}
}