Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/java/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "java",
"version": "1.8.0",
"version": "1.8.1",
"name": "Java (via SDKMAN!)",
"documentationURL": "https://github.com/devcontainers/features/tree/main/src/java",
"description": "Installs Java, SDKMAN! (if not installed), and needed dependencies.",
Expand Down
28 changes: 26 additions & 2 deletions src/java/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,29 @@ updaterc() {
fi
}

run_with_retries() {
local max_attempts="$1"
local wait_seconds="$2"
local operation="$3"
local attempt=1
shift 3

until "$@"; do
if [ "${attempt}" -ge "${max_attempts}" ]; then
echo "(!) ${operation} failed after ${max_attempts} attempts."
return 1
fi

echo "(*) ${operation} failed on attempt ${attempt}. Retrying in ${wait_seconds}s..."
attempt=$((attempt + 1))
sleep "${wait_seconds}"
done
}

install_sdkman_cli() {
bash -o pipefail -c 'curl -fsSL "https://get.sdkman.io?rcupdate=false" | bash'
}

find_version_list() {
prefix="$1"
suffix="$2"
Expand Down Expand Up @@ -284,7 +307,8 @@ sdk_install() {
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"
run_with_retries 5 10 "Installing ${install_type} ${requested_version} via SDKMAN" \
su ${USERNAME} -c "umask 0002 && . ${SDKMAN_DIR}/bin/sdkman-init.sh && sdk install ${install_type} ${requested_version} && sdk flush archives && sdk flush temp"
}

export DEBIAN_FRONTEND=noninteractive
Expand Down Expand Up @@ -323,7 +347,7 @@ if [ ! -d "${SDKMAN_DIR}" ]; then
if [ "${ADJUSTED_ID}" = "rhel" ] && [ "${MAJOR_VERSION_ID}" = "8" ]; then
export SDKMAN_NATIVE_VERSION="false"
fi
curl -sSL "https://get.sdkman.io?rcupdate=false" | bash
run_with_retries 5 10 "Installing SDKMAN" install_sdkman_cli
# For RHEL 8 systems, also disable native CLI in config file and remove native binaries
if [ "${ADJUSTED_ID}" = "rhel" ] && [ "${MAJOR_VERSION_ID}" = "8" ]; then
# Disable native CLI in config to prevent future usage
Expand Down
4 changes: 2 additions & 2 deletions test/java/install_latest_version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ source dev-container-features-test-lib
echo 'public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World!"); } }' > HelloWorld.java
javac HelloWorld.java

check "hello world" /bin/bash -c "java HelloWorld | grep "Hello, World!""
check "java version latest installed" grep "25" <(java --version)
check "hello world" /bin/bash -c 'java HelloWorld | grep "Hello, World!"'
check "java version latest installed" grep "26" <(java --version)

# Report result
reportResults
Loading