From 56b86f64b5d0fb913214c22a487a7c15060aab2e Mon Sep 17 00:00:00 2001 From: Jeff Putsch Date: Wed, 13 Dec 2023 14:33:36 -0800 Subject: [PATCH 1/7] Initial rhel update --- src/java/install.sh | 120 ++++++++++++++++++++++++++++++++------- test/java/centos-7.sh | 11 ++++ test/java/scenarios.json | 8 ++- 3 files changed, 118 insertions(+), 21 deletions(-) create mode 100644 test/java/centos-7.sh diff --git a/src/java/install.sh b/src/java/install.sh index 2decc31b5..529f1334a 100644 --- a/src/java/install.sh +++ b/src/java/install.sh @@ -9,6 +9,8 @@ # # Syntax: ./java-debian.sh [JDK version] [SDKMAN_DIR] [non-root user] [Add to rc files flag] +set -x + JAVA_VERSION="${VERSION:-"lts"}" INSTALL_GRADLE="${INSTALLGRADLE:-"false"}" GRADLE_VERSION="${GRADLEVERSION:-"latest"}" @@ -28,14 +30,61 @@ ADDITIONAL_VERSIONS="${ADDITIONALVERSIONS:-""}" set -e -# Clean up -rm -rf /var/lib/apt/lists/* - if [ "$(id -u)" -ne 0 ]; then echo -e 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.' exit 1 fi +# Bring in ID, ID_LIKE, VERSION_ID, VERSION_CODENAME +. /etc/os-release +# Get an adjusted ID independent of distro variants +MAJOR_VERSION_ID=$(echo ${VERSION_ID} | cut -d . -f 1) +if [ "${ID}" = "debian" ] || [ "${ID_LIKE}" = "debian" ]; then + ADJUSTED_ID="debian" +elif [[ "${ID}" = "rhel" || "${ID}" = "fedora" || "${ID}" = "mariner" || "${ID_LIKE}" = *"rhel"* || "${ID_LIKE}" = *"fedora"* || "${ID_LIKE}" = *"mariner"* ]]; then + ADJUSTED_ID="rhel" + if [[ "${ID}" = "rhel" ]] || [[ "${ID}" = *"alma"* ]] || [[ "${ID}" = *"rocky"* ]]; then + VERSION_CODENAME="rhel${MAJOR_VERSION_ID}" + else + VERSION_CODENAME="${ID}${MAJOR_VERSION_ID}" + fi +else + echo "Linux distro ${ID} not supported." + exit 1 +fi + +# Setup INSTALL_CMD & PKG_MGR_CMD +if type apt-get > /dev/null 2>&1; then + PKG_MGR_CMD=apt-get + INSTALL_CMD="${PKG_MGR_CMD} -y install --no-install-recommends" +elif type dnf > /dev/null 2>&1; then + PKG_MGR_CMD=dnf + INSTALL_CMD="${PKG_MGR_CMD} -y install" +elif type microdnf > /dev/null 2>&1; then + PKG_MGR_CMD=microdnf + INSTALL_CMD="${PKG_MGR_CMD} -y install --refresh --best --nodocs --noplugins --setopt=install_weak_deps=0" +else + PKG_MGR_CMD=yum + INSTALL_CMD="${PKG_MGR_CMD} -y install" +fi + +# Clean up +clean_up() { + case ${ADJUSTED_ID} in + debian) + rm -rf /var/lib/apt/lists/* + ;; + rhel) + set +e + ${PKG_MGR_CMD} -y remove epel-release epel-release-latest packages-microsoft-prod + set -e + rm -rf /var/cache/dnf/* /var/cache/yum/* + rm -f /etc/yum.repos.d/docker-ce.repo + ;; + esac +} +clean_up + # Ensure that login shells get the correct path if the user updated the PATH using ENV. rm -f /etc/profile.d/00-restore-env.sh echo "export PATH=${PATH//$(sh -lc 'echo $PATH')/\$PATH}" > /etc/profile.d/00-restore-env.sh @@ -59,31 +108,64 @@ elif [ "${USERNAME}" = "none" ] || ! id -u ${USERNAME} > /dev/null 2>&1; then fi updaterc() { + local _bashrc + local _zshrc if [ "${UPDATE_RC}" = "true" ]; then - echo "Updating /etc/bash.bashrc and /etc/zsh/zshrc..." - if [[ "$(cat /etc/bash.bashrc)" != *"$1"* ]]; then - echo -e "$1" >> /etc/bash.bashrc + case $ADJUSTED_ID in + debian) + _bashrc=/etc/bash.bashrc + _zshrc=/etc/zsh/zshrc + ;; + rhel) + _bashrc=/etc/bashrc + _zshrc=/etc/zshrc + ;; + esac + echo "Updating ${_bashrc} and ${_zshrc}..." + if [[ "$(cat ${_bashrc})" != *"$1"* ]]; then + echo -e "$1" >> "${_bashrc}" fi - if [ -f "/etc/zsh/zshrc" ] && [[ "$(cat /etc/zsh/zshrc)" != *"$1"* ]]; then - echo -e "$1" >> /etc/zsh/zshrc + if [ -f "${_zshrc}" ] && [[ "$(cat ${_zshrc})" != *"$1"* ]]; then + echo -e "$1" >> "${_zshrc}" fi fi } -apt_get_update() -{ - if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then - echo "Running apt-get update..." - apt-get update -y - fi + +pkg_mgr_update() { + case $ADJUSTED_ID in + debian) + if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then + echo "Running apt-get update..." + apt-get update -y + fi + ;; + rhel) + if [ "$(find /var/cache/${INSTALL_CMD}/* | wc -l)" = "0" ]; then + echo "Running ${INSTALL_CMD} check-update ..." + ${INSTALL_CMD} check-update + fi + ;; + esac } # Checks if packages are installed and installs them if not check_packages() { - if ! dpkg -s "$@" > /dev/null 2>&1; then - apt_get_update - apt-get -y install --no-install-recommends "$@" - fi + case ${ADJUSTED_ID} in + debian) + if ! dpkg -s "$@" > /dev/null 2>&1; then + pkg_mgr_update + apt-get -y install --no-install-recommends "$@" + fi + ;; + rhel) _num_pkgs=$(echo "$@" | tr ' ' \\012 | wc -l) + _num_installed=$(${INSTALL_CMD} -C list installed "$@" | sed '1,/^Installed/d' | wc -l) + if [ ${_num_pkgs} != ${_num_installed} ]; then + pkg_mgr_update + ${INSTALL_CMD} -y install "$@" + fi + ;; + esac } # Use Microsoft JDK for everything but JDK 8 and 18 (unless specified differently with jdkDistro option) @@ -191,6 +273,6 @@ if [[ "${INSTALL_MAVEN}" = "true" ]] && ! mvn --version > /dev/null; then fi # Clean up -rm -rf /var/lib/apt/lists/* +clean_up echo "Done!" diff --git a/test/java/centos-7.sh b/test/java/centos-7.sh new file mode 100644 index 000000000..021a72a21 --- /dev/null +++ b/test/java/centos-7.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +set -e + +# Optional: Import test library +source dev-container-features-test-lib + +check "java version openjdk 19 installed" grep "openjdk 19." <(java --version) + +# Report result +reportResults diff --git a/test/java/scenarios.json b/test/java/scenarios.json index 5d7e684ba..9c1668875 100644 --- a/test/java/scenarios.json +++ b/test/java/scenarios.json @@ -59,11 +59,15 @@ }, "install_non_conventional_version": { "image": "ubuntu:focal", - "features":{ + "features": { "java": { "version": "21", "jdkDistro": "graalce" } } + }, + "centos-7": { + "image": "centos:centos7", + "features": {} } -} +} \ No newline at end of file From cf73b17b85c6921aaefa2a694956d6e893e9a09c Mon Sep 17 00:00:00 2001 From: Jeff Putsch Date: Wed, 13 Dec 2023 17:30:09 -0800 Subject: [PATCH 2/7] RHEL support added. --- src/java/NOTES.md | 2 +- src/java/README.md | 22 ++++++++--------- src/java/install.sh | 48 +++++++++++++++++++++++++++---------- test/java/alma-8-minimal.sh | 15 ++++++++++++ test/java/alma-8.sh | 15 ++++++++++++ test/java/alma-9-minimal.sh | 15 ++++++++++++ test/java/alma-9.sh | 15 ++++++++++++ test/java/centos-7.sh | 6 ++++- test/java/scenarios.json | 28 +++++++++++++++++++++- 9 files changed, 139 insertions(+), 27 deletions(-) create mode 100644 test/java/alma-8-minimal.sh create mode 100644 test/java/alma-8.sh create mode 100644 test/java/alma-9-minimal.sh create mode 100644 test/java/alma-9.sh diff --git a/src/java/NOTES.md b/src/java/NOTES.md index 63622afaf..d77072e66 100644 --- a/src/java/NOTES.md +++ b/src/java/NOTES.md @@ -5,6 +5,6 @@ For the Java Feature from this repository, see [NOTICE.txt](https://github.com/d ## OS Support -This Feature should work on recent versions of Debian/Ubuntu-based distributions with the `apt` package manager installed. + Debian/Ubuntu, RedHat Enterprise Linux, Fedora, Alma, and RockyLinux distributions with the apt, yum, dnf, or microdnf package manager installed. `bash` is required to execute the `install.sh` script. diff --git a/src/java/README.md b/src/java/README.md index 1ffd6188b..7c2b401d6 100644 --- a/src/java/README.md +++ b/src/java/README.md @@ -13,16 +13,16 @@ Installs Java, SDKMAN! (if not installed), and needed dependencies. ## Options -| Options Id | Description | Type | Default Value | -|-----|-----|-----|-----| -| version | Select or enter a Java version to install | string | latest | -| jdkDistro | Select or enter a JDK distribution | string | ms | -| installGradle | Install Gradle, a build automation tool for multi-language software development | boolean | false | -| gradleVersion | Select or enter a Gradle version | string | latest | -| installMaven | Install Maven, a management tool for Java | boolean | false | -| mavenVersion | Select or enter a Maven version | string | latest | -| installAnt | Install Ant, a software tool for automating software build processes | boolean | false | -| antVersion | Select or enter an Ant version | string | latest | +| Options Id | Description | Type | Default Value | +| ------------- | ------------------------------------------------------------------------------- | ------- | ------------- | +| version | Select or enter a Java version to install | string | latest | +| jdkDistro | Select or enter a JDK distribution | string | ms | +| installGradle | Install Gradle, a build automation tool for multi-language software development | boolean | false | +| gradleVersion | Select or enter a Gradle version | string | latest | +| installMaven | Install Maven, a management tool for Java | boolean | false | +| mavenVersion | Select or enter a Maven version | string | latest | +| installAnt | Install Ant, a software tool for automating software build processes | boolean | false | +| antVersion | Select or enter an Ant version | string | latest | ## Customizations @@ -37,7 +37,7 @@ For the Java Feature from this repository, see [NOTICE.txt](https://github.com/d ## OS Support -This Feature should work on recent versions of Debian/Ubuntu-based distributions with the `apt` package manager installed. + Debian/Ubuntu, RedHat Enterprise Linux, Fedora, Alma, and RockyLinux distributions with the apt, yum, dnf, or microdnf package manager installed. `bash` is required to execute the `install.sh` script. diff --git a/src/java/install.sh b/src/java/install.sh index 529f1334a..6f5841c4a 100644 --- a/src/java/install.sh +++ b/src/java/install.sh @@ -9,8 +9,6 @@ # # Syntax: ./java-debian.sh [JDK version] [SDKMAN_DIR] [non-root user] [Add to rc files flag] -set -x - JAVA_VERSION="${VERSION:-"lts"}" INSTALL_GRADLE="${INSTALLGRADLE:-"false"}" GRADLE_VERSION="${GRADLEVERSION:-"latest"}" @@ -137,13 +135,27 @@ pkg_mgr_update() { debian) if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then echo "Running apt-get update..." - apt-get update -y + ${PKG_MGR_CMD} update -y fi ;; rhel) - if [ "$(find /var/cache/${INSTALL_CMD}/* | wc -l)" = "0" ]; then - echo "Running ${INSTALL_CMD} check-update ..." - ${INSTALL_CMD} check-update + if [ ${PKG_MGR_CMD} = "microdnf" ]; then + if [ "$(ls /var/cache/yum/* 2>/dev/null | wc -l)" = 0 ]; then + echo "Running ${PKG_MGR_CMD} makecache ..." + ${PKG_MGR_CMD} makecache + fi + else + if [ "$(ls /var/cache/${PKG_MGR_CMD}/* 2>/dev/null | wc -l)" = 0 ]; then + echo "Running ${PKG_MGR_CMD} check-update ..." + set +e + ${PKG_MGR_CMD} check-update + rc=$? + # centos 7 sometimes returns a status of 100 when it apears to work. + if [ $rc != 0 ] && [ $rc != 100 ]; then + exit 1 + fi + set -e + fi fi ;; esac @@ -155,14 +167,13 @@ check_packages() { debian) if ! dpkg -s "$@" > /dev/null 2>&1; then pkg_mgr_update - apt-get -y install --no-install-recommends "$@" + ${INSTALL_CMD} "$@" fi ;; - rhel) _num_pkgs=$(echo "$@" | tr ' ' \\012 | wc -l) - _num_installed=$(${INSTALL_CMD} -C list installed "$@" | sed '1,/^Installed/d' | wc -l) - if [ ${_num_pkgs} != ${_num_installed} ]; then + rhel) + if ! rpm -q "$@" > /dev/null 2>&1; then pkg_mgr_update - ${INSTALL_CMD} -y install "$@" + ${INSTALL_CMD} "$@" fi ;; esac @@ -222,8 +233,19 @@ if [ "${architecture}" != "amd64" ] && [ "${architecture}" != "x86_64" ] && [ "$ exit 1 fi -# Install dependencies -check_packages curl ca-certificates zip unzip sed +# Install dependencies, +check_packages ca-certificates zip unzip sed findutils util-linux tar +# Make sure passwd (Debian) and shadow-utils RHEL family is installed +if [ ${ADJUSTED_ID} = "debian" ]; then + check_packages passwd +elif [ ${ADJUSTED_ID} = "rhel" ]; then + check_packages shadow-utils +fi +# minimal RHEL installs may not include curl, or includes curl-minimal instead. +# Install curl if the "curl" command is not present. +if ! type curl > /dev/null 2>&1; then + check_packages curl +fi # Install sdkman if not installed if [ ! -d "${SDKMAN_DIR}" ]; then diff --git a/test/java/alma-8-minimal.sh b/test/java/alma-8-minimal.sh new file mode 100644 index 000000000..40f48562c --- /dev/null +++ b/test/java/alma-8-minimal.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +set -e + +# Optional: Import test library +source dev-container-features-test-lib + +# Definition specific tests +check "version" java --version + +# Check env +check "JAVA_HOME is set correctly" echo $JAVA_HOME | grep "/usr/local/sdkman/candidates/java/current" + +# Report result +reportResults diff --git a/test/java/alma-8.sh b/test/java/alma-8.sh new file mode 100644 index 000000000..40f48562c --- /dev/null +++ b/test/java/alma-8.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +set -e + +# Optional: Import test library +source dev-container-features-test-lib + +# Definition specific tests +check "version" java --version + +# Check env +check "JAVA_HOME is set correctly" echo $JAVA_HOME | grep "/usr/local/sdkman/candidates/java/current" + +# Report result +reportResults diff --git a/test/java/alma-9-minimal.sh b/test/java/alma-9-minimal.sh new file mode 100644 index 000000000..40f48562c --- /dev/null +++ b/test/java/alma-9-minimal.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +set -e + +# Optional: Import test library +source dev-container-features-test-lib + +# Definition specific tests +check "version" java --version + +# Check env +check "JAVA_HOME is set correctly" echo $JAVA_HOME | grep "/usr/local/sdkman/candidates/java/current" + +# Report result +reportResults diff --git a/test/java/alma-9.sh b/test/java/alma-9.sh new file mode 100644 index 000000000..40f48562c --- /dev/null +++ b/test/java/alma-9.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +set -e + +# Optional: Import test library +source dev-container-features-test-lib + +# Definition specific tests +check "version" java --version + +# Check env +check "JAVA_HOME is set correctly" echo $JAVA_HOME | grep "/usr/local/sdkman/candidates/java/current" + +# Report result +reportResults diff --git a/test/java/centos-7.sh b/test/java/centos-7.sh index 021a72a21..40f48562c 100644 --- a/test/java/centos-7.sh +++ b/test/java/centos-7.sh @@ -5,7 +5,11 @@ set -e # Optional: Import test library source dev-container-features-test-lib -check "java version openjdk 19 installed" grep "openjdk 19." <(java --version) +# Definition specific tests +check "version" java --version + +# Check env +check "JAVA_HOME is set correctly" echo $JAVA_HOME | grep "/usr/local/sdkman/candidates/java/current" # Report result reportResults diff --git a/test/java/scenarios.json b/test/java/scenarios.json index 9c1668875..fcd149303 100644 --- a/test/java/scenarios.json +++ b/test/java/scenarios.json @@ -68,6 +68,32 @@ }, "centos-7": { "image": "centos:centos7", - "features": {} + "features": { + "java": {} + } + }, + "alma-8": { + "image": "almalinux:8", + "features": { + "java": {} + } + }, + "alma-8-minimal": { + "image": "almalinux:8-minimal", + "features": { + "java": {} + } + }, + "alma-9": { + "image": "almalinux:9", + "features": { + "java": {} + } + }, + "alma-9-minimal": { + "image": "almalinux:9-minimal", + "features": { + "java": {} + } } } \ No newline at end of file From 5436055a7e1c6e76caf5a09a48dba7aba8ccbe4d Mon Sep 17 00:00:00 2001 From: Jeff Putsch Date: Mon, 29 Jan 2024 14:59:03 -0800 Subject: [PATCH 3/7] Add tests --- src/java/devcontainer-feature.json | 4 +- src/java/install.sh | 18 +-- test/java/fedora.sh | 15 +++ .../install_additional_java_rhel_family.sh | 13 +++ ...d_maven_and_groovy_for_user_rhel_family.sh | 34 ++++++ ...gradle_and_maven_and_groovy_rhel_family.sh | 34 ++++++ ...roovy_with_specific_version_rhel_family.sh | 30 +++++ ...all_from_non_default_distro_rhel_family.sh | 11 ++ ...ll_non_conventional_version_rhel_family.sh | 11 ++ test/java/mariner.sh | 15 +++ test/java/rocky-8-minimal.sh | 15 +++ test/java/rocky-8.sh | 15 +++ test/java/rocky-9-minimal.sh | 15 +++ test/java/rocky-9.sh | 15 +++ test/java/scenarios.json | 107 ++++++++++++++++++ 15 files changed, 343 insertions(+), 9 deletions(-) create mode 100644 test/java/fedora.sh create mode 100644 test/java/install_additional_java_rhel_family.sh create mode 100644 test/java/install_ant_and_gradle_and_maven_and_groovy_for_user_rhel_family.sh create mode 100644 test/java/install_ant_and_gradle_and_maven_and_groovy_rhel_family.sh create mode 100644 test/java/install_ant_and_gradle_and_maven_and_groovy_with_specific_version_rhel_family.sh create mode 100644 test/java/install_from_non_default_distro_rhel_family.sh create mode 100644 test/java/install_non_conventional_version_rhel_family.sh create mode 100644 test/java/mariner.sh create mode 100644 test/java/rocky-8-minimal.sh create mode 100644 test/java/rocky-8.sh create mode 100644 test/java/rocky-9-minimal.sh create mode 100644 test/java/rocky-9.sh diff --git a/src/java/devcontainer-feature.json b/src/java/devcontainer-feature.json index 64a4ca932..f65a8f360 100644 --- a/src/java/devcontainer-feature.json +++ b/src/java/devcontainer-feature.json @@ -1,6 +1,6 @@ { "id": "java", - "version": "1.3.0", + "version": "1.4.0", "name": "Java (via SDKMAN!)", "documentationURL": "https://github.com/devcontainers/features/tree/main/src/java", "description": "Installs Java, SDKMAN! (if not installed), and needed dependencies.", @@ -111,4 +111,4 @@ "installsAfter": [ "ghcr.io/devcontainers/features/common-utils" ] -} +} \ No newline at end of file diff --git a/src/java/install.sh b/src/java/install.sh index 5f991a904..d76263a20 100644 --- a/src/java/install.sh +++ b/src/java/install.sh @@ -57,27 +57,31 @@ fi if type apt-get > /dev/null 2>&1; then PKG_MGR_CMD=apt-get INSTALL_CMD="${PKG_MGR_CMD} -y install --no-install-recommends" -elif type dnf > /dev/null 2>&1; then - PKG_MGR_CMD=dnf - INSTALL_CMD="${PKG_MGR_CMD} -y install" elif type microdnf > /dev/null 2>&1; then PKG_MGR_CMD=microdnf INSTALL_CMD="${PKG_MGR_CMD} -y install --refresh --best --nodocs --noplugins --setopt=install_weak_deps=0" -else +elif type dnf > /dev/null 2>&1; then + PKG_MGR_CMD=dnf + INSTALL_CMD="${PKG_MGR_CMD} -y install" +elif type yum > /dev/null 2>&1; then PKG_MGR_CMD=yum INSTALL_CMD="${PKG_MGR_CMD} -y install" +else + echo "(Error) Unable to find a supported package manager." + exit 1 fi # Clean up clean_up() { + local pkg case ${ADJUSTED_ID} in debian) rm -rf /var/lib/apt/lists/* ;; rhel) - set +e - ${PKG_MGR_CMD} -y remove epel-release epel-release-latest packages-microsoft-prod - set -e + for pkg in epel-release epel-release-latest packages-microsoft-prod; do + ${PKG_MGR_CMD} -y remove $pkg 2>/dev/null || /bin/true + done rm -rf /var/cache/dnf/* /var/cache/yum/* rm -f /etc/yum.repos.d/docker-ce.repo ;; diff --git a/test/java/fedora.sh b/test/java/fedora.sh new file mode 100644 index 000000000..40f48562c --- /dev/null +++ b/test/java/fedora.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +set -e + +# Optional: Import test library +source dev-container-features-test-lib + +# Definition specific tests +check "version" java --version + +# Check env +check "JAVA_HOME is set correctly" echo $JAVA_HOME | grep "/usr/local/sdkman/candidates/java/current" + +# Report result +reportResults diff --git a/test/java/install_additional_java_rhel_family.sh b/test/java/install_additional_java_rhel_family.sh new file mode 100644 index 000000000..882c49d1c --- /dev/null +++ b/test/java/install_additional_java_rhel_family.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +set -e + +# Optional: Import test library +source dev-container-features-test-lib + +check "java version 11 installed as default" grep "11\." <(java --version) +check "java version 17 installed" grep "^17\." <(ls /usr/local/sdkman/candidates/java) +check "java version 8 installed" grep "^8\." <(ls /usr/local/sdkman/candidates/java) + +# Report result +reportResults diff --git a/test/java/install_ant_and_gradle_and_maven_and_groovy_for_user_rhel_family.sh b/test/java/install_ant_and_gradle_and_maven_and_groovy_for_user_rhel_family.sh new file mode 100644 index 000000000..8d9f293e9 --- /dev/null +++ b/test/java/install_ant_and_gradle_and_maven_and_groovy_for_user_rhel_family.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +set -e + +# Optional: Import test library +source dev-container-features-test-lib + +check "user is vscode" grep vscode <(whoami) + +check "java" java --version + +check "ant" ant -version +cat << EOF > /tmp/build.xml + +EOF +cd /tmp && ant init +check "ant-src exists" grep "ant-src" <(ls -la /tmp) + +check "gradle" gradle --version +cd /tmp && gradle init --type basic --dsl groovy --incubating --project-name test +check "GRADLE_USER_HOME exists" grep ".gradle" <(ls -la /home/vscode) + +check "maven" mvn --version +cd /tmp && mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.4 -DinteractiveMode=false +check "m2 exists" grep ".m2" <(ls -la /home/vscode) + +check "groovy" groovy --version +cat << EOF > /tmp/test.groovy +println("verify") +EOF +check "groovy works" test "$(groovy /tmp/test.groovy)" = "verify" + +# Report result +reportResults diff --git a/test/java/install_ant_and_gradle_and_maven_and_groovy_rhel_family.sh b/test/java/install_ant_and_gradle_and_maven_and_groovy_rhel_family.sh new file mode 100644 index 000000000..e171f5be5 --- /dev/null +++ b/test/java/install_ant_and_gradle_and_maven_and_groovy_rhel_family.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +set -e + +# Optional: Import test library +source dev-container-features-test-lib + +check "user is root" grep root <(whoami) + +check "java" java --version + +check "ant" ant -version +cat << EOF > /tmp/build.xml + +EOF +cd /tmp && ant init +check "ant-src exists" grep "ant-src" <(ls -la /tmp) + +check "gradle" gradle --version +cd /tmp && gradle init --type basic --dsl groovy --incubating --project-name test +check "GRADLE_USER_HOME exists" grep ".gradle" <(ls -la /root) + +check "maven" mvn --version +cd /tmp && mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.4 -DinteractiveMode=false +check "m2 exists" grep ".m2" <(ls -la /root) + +check "groovy" groovy --version +cat << EOF > /tmp/test.groovy +println("verify") +EOF +check "groovy works" test "$(groovy /tmp/test.groovy)" = "verify" + +# Report result +reportResults diff --git a/test/java/install_ant_and_gradle_and_maven_and_groovy_with_specific_version_rhel_family.sh b/test/java/install_ant_and_gradle_and_maven_and_groovy_with_specific_version_rhel_family.sh new file mode 100644 index 000000000..54e13e0cf --- /dev/null +++ b/test/java/install_ant_and_gradle_and_maven_and_groovy_with_specific_version_rhel_family.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +set -e + +# Optional: Import test library +source dev-container-features-test-lib + +check "user is root" grep root <(whoami) + +check "java" java --version + +check "ant version" grep "Ant(TM) version 1.10.12" <(ant -version) +cat << EOF > /tmp/build.xml + +EOF +cd /tmp && ant init +check "ant-src exists" grep "ant-src" <(ls -la /tmp) + +check "gradle version" grep "Gradle 6.8.3" <(gradle --version) +cd /tmp && gradle init --type basic --dsl groovy --project-name test +check "GRADLE_USER_HOME exists" grep ".gradle" <(ls -la /root) + +check "maven version" grep "Apache Maven 3.6.3" <(mvn --version) +cd /tmp && mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.4 -DinteractiveMode=false +check "m2 exists" grep ".m2" <(ls -la /root) + +check "groovy version" grep "Groovy Version: 2.5.22" <(groovy --version) + +# Report result +reportResults diff --git a/test/java/install_from_non_default_distro_rhel_family.sh b/test/java/install_from_non_default_distro_rhel_family.sh new file mode 100644 index 000000000..3ab648cab --- /dev/null +++ b/test/java/install_from_non_default_distro_rhel_family.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +set -e + +# Optional: Import test library +source dev-container-features-test-lib + +check "java version openjdk 21 installed" grep "openjdk 21." <(java --version) + +# Report result +reportResults diff --git a/test/java/install_non_conventional_version_rhel_family.sh b/test/java/install_non_conventional_version_rhel_family.sh new file mode 100644 index 000000000..3ab648cab --- /dev/null +++ b/test/java/install_non_conventional_version_rhel_family.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +set -e + +# Optional: Import test library +source dev-container-features-test-lib + +check "java version openjdk 21 installed" grep "openjdk 21." <(java --version) + +# Report result +reportResults diff --git a/test/java/mariner.sh b/test/java/mariner.sh new file mode 100644 index 000000000..40f48562c --- /dev/null +++ b/test/java/mariner.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +set -e + +# Optional: Import test library +source dev-container-features-test-lib + +# Definition specific tests +check "version" java --version + +# Check env +check "JAVA_HOME is set correctly" echo $JAVA_HOME | grep "/usr/local/sdkman/candidates/java/current" + +# Report result +reportResults diff --git a/test/java/rocky-8-minimal.sh b/test/java/rocky-8-minimal.sh new file mode 100644 index 000000000..40f48562c --- /dev/null +++ b/test/java/rocky-8-minimal.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +set -e + +# Optional: Import test library +source dev-container-features-test-lib + +# Definition specific tests +check "version" java --version + +# Check env +check "JAVA_HOME is set correctly" echo $JAVA_HOME | grep "/usr/local/sdkman/candidates/java/current" + +# Report result +reportResults diff --git a/test/java/rocky-8.sh b/test/java/rocky-8.sh new file mode 100644 index 000000000..40f48562c --- /dev/null +++ b/test/java/rocky-8.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +set -e + +# Optional: Import test library +source dev-container-features-test-lib + +# Definition specific tests +check "version" java --version + +# Check env +check "JAVA_HOME is set correctly" echo $JAVA_HOME | grep "/usr/local/sdkman/candidates/java/current" + +# Report result +reportResults diff --git a/test/java/rocky-9-minimal.sh b/test/java/rocky-9-minimal.sh new file mode 100644 index 000000000..40f48562c --- /dev/null +++ b/test/java/rocky-9-minimal.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +set -e + +# Optional: Import test library +source dev-container-features-test-lib + +# Definition specific tests +check "version" java --version + +# Check env +check "JAVA_HOME is set correctly" echo $JAVA_HOME | grep "/usr/local/sdkman/candidates/java/current" + +# Report result +reportResults diff --git a/test/java/rocky-9.sh b/test/java/rocky-9.sh new file mode 100644 index 000000000..40f48562c --- /dev/null +++ b/test/java/rocky-9.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +set -e + +# Optional: Import test library +source dev-container-features-test-lib + +# Definition specific tests +check "version" java --version + +# Check env +check "JAVA_HOME is set correctly" echo $JAVA_HOME | grep "/usr/local/sdkman/candidates/java/current" + +# Report result +reportResults diff --git a/test/java/scenarios.json b/test/java/scenarios.json index 1ed0588df..6e6426969 100644 --- a/test/java/scenarios.json +++ b/test/java/scenarios.json @@ -70,6 +70,77 @@ } } }, + "install_from_non_default_distro_rhel_family": { + "image": "almalinux:8", + "features": { + "java": { + "version": "21", + "jdkDistro": "open" + } + } + }, + "install_additional_java_rhel_family": { + "image": "almalinux:8", + "features": { + "java": { + "version": "11", + "additionalVersions": "17,8" + } + } + }, + "install_ant_and_gradle_and_maven_and_groovy_for_user_rhel_family": { + "image": "almalinux:8", + "remoteUser": "vscode", + "features": { + "common-utils": { + "username": "vscode" + }, + "java": { + "version": "latest", + "installAnt": true, + "installGradle": true, + "installMaven": true, + "installGroovy": true + } + } + }, + "install_ant_and_gradle_and_maven_and_groovy_rhel_family": { + "image": "almalinux:8", + "features": { + "java": { + "version": "latest", + "installAnt": true, + "installGradle": true, + "installMaven": true, + "installGroovy": true + } + } + }, + "install_ant_and_gradle_and_maven_and_groovy_with_specific_version_rhel_family": { + "image": "almalinux:8", + "features": { + "java": { + "version": "latest", + "installAnt": "true", + "antVersion": "1.10.12", + "installGradle": "true", + "gradleVersion": "6.8.3", + "installMaven": "true", + "mavenVersion": "3.6.3", + "installGroovy": "true", + "groovyVersion": "2.5.22" + } + } + }, + "install_non_conventional_version_rhel_family": { + "image": "almalinux:8", + "features": { + "java": { + "version": "21", + "jdkDistro": "graalce" + } + } + }, "centos-7": { "image": "centos:centos7", "features": { @@ -99,5 +170,41 @@ "features": { "java": {} } + }, + "rocky-8": { + "image": "rockylinux:8", + "features": { + "java": {} + } + }, + "rocky-8-minimal": { + "image": "rockylinux:8-minimal", + "features": { + "java": {} + } + }, + "rocky-9": { + "image": "rockylinux:9", + "features": { + "java": {} + } + }, + "rocky-9-minimal": { + "image": "rockylinux:9-minimal", + "features": { + "java": {} + } + }, + "mariner": { + "image": "mcr.microsoft.com/cbl-mariner/base/core:2.0", + "features": { + "java": {} + } + }, + "fedora": { + "image": "fedora", + "features": { + "java": {} + } } } \ No newline at end of file From ba65daf6e6f961170a2c4a352381a7c8bd45fd4c Mon Sep 17 00:00:00 2001 From: Jeff Putsch Date: Mon, 29 Jan 2024 15:25:16 -0800 Subject: [PATCH 4/7] quiet down test for ant/gradle/maven/groovy when they are not yet installed. --- src/java/install.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/java/install.sh b/src/java/install.sh index d76263a20..23e338072 100644 --- a/src/java/install.sh +++ b/src/java/install.sh @@ -286,22 +286,22 @@ if [ ! -z "${ADDITIONAL_VERSIONS}" ]; then fi # Install Ant -if [[ "${INSTALL_ANT}" = "true" ]] && ! ant -version > /dev/null; then +if [[ "${INSTALL_ANT}" = "true" ]] && ! ant -version > /dev/null 2>&1; then sdk_install ant ${ANT_VERSION} fi # Install Gradle -if [[ "${INSTALL_GRADLE}" = "true" ]] && ! gradle --version > /dev/null; then +if [[ "${INSTALL_GRADLE}" = "true" ]] && ! gradle --version > /dev/null 2>&1; then sdk_install gradle ${GRADLE_VERSION} fi # Install Maven -if [[ "${INSTALL_MAVEN}" = "true" ]] && ! mvn --version > /dev/null; then +if [[ "${INSTALL_MAVEN}" = "true" ]] && ! mvn --version > /dev/null 2>&1; then sdk_install maven ${MAVEN_VERSION} fi # Install Groovy -if [[ "${INSTALL_GROOVY}" = "true" ]] && ! groovy --version > /dev/null; then +if [[ "${INSTALL_GROOVY}" = "true" ]] && ! groovy --version > /dev/null 2>&1; then sdk_install groovy "${GROOVY_VERSION}" fi From bff1fbf54ce2ea623259dada4989b1a4d485dec8 Mon Sep 17 00:00:00 2001 From: Jeff Putsch Date: Tue, 30 Jan 2024 10:10:21 -0800 Subject: [PATCH 5/7] revert README -- it is autobuilt --- src/java/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/java/README.md b/src/java/README.md index df66826eb..4699eb517 100644 --- a/src/java/README.md +++ b/src/java/README.md @@ -39,7 +39,7 @@ For the Java Feature from this repository, see [NOTICE.txt](https://github.com/d ## OS Support - Debian/Ubuntu, RedHat Enterprise Linux, Fedora, Alma, and RockyLinux distributions with the apt, yum, dnf, or microdnf package manager installed. +This Feature should work on recent versions of Debian/Ubuntu-based distributions with the `apt` package manager installed. `bash` is required to execute the `install.sh` script. From 94352713c37a82d0381e78361d6c5f6e6336a640 Mon Sep 17 00:00:00 2001 From: Jeff Putsch <150963136+jdputschadi@users.noreply.github.com> Date: Tue, 30 Jan 2024 12:27:12 -0800 Subject: [PATCH 6/7] Update src/java/NOTES.md add "`" around package manager names. Co-authored-by: Samruddhi Khandale --- src/java/NOTES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/java/NOTES.md b/src/java/NOTES.md index d77072e66..edc310e23 100644 --- a/src/java/NOTES.md +++ b/src/java/NOTES.md @@ -5,6 +5,6 @@ For the Java Feature from this repository, see [NOTICE.txt](https://github.com/d ## OS Support - Debian/Ubuntu, RedHat Enterprise Linux, Fedora, Alma, and RockyLinux distributions with the apt, yum, dnf, or microdnf package manager installed. +Debian/Ubuntu, RedHat Enterprise Linux, Fedora, Alma, and RockyLinux distributions with the `apt`, `yum`, `dnf`, or `microdnf` package manager installed. `bash` is required to execute the `install.sh` script. From 85101db309e6bdbbd96dadf2484c3bde95a38006 Mon Sep 17 00:00:00 2001 From: Jeff Putsch Date: Tue, 30 Jan 2024 13:03:39 -0800 Subject: [PATCH 7/7] address PR feedback --- src/java/install.sh | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/java/install.sh b/src/java/install.sh index 23e338072..37cb9e52b 100644 --- a/src/java/install.sh +++ b/src/java/install.sh @@ -136,7 +136,7 @@ updaterc() { } -pkg_mgr_update() { +pkg_manager_update() { case $ADJUSTED_ID in debian) if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then @@ -154,12 +154,14 @@ pkg_mgr_update() { if [ "$(ls /var/cache/${PKG_MGR_CMD}/* 2>/dev/null | wc -l)" = 0 ]; then echo "Running ${PKG_MGR_CMD} check-update ..." set +e - ${PKG_MGR_CMD} check-update - rc=$? - # centos 7 sometimes returns a status of 100 when it apears to work. - if [ $rc != 0 ] && [ $rc != 100 ]; then - exit 1 - fi + stderr_messages=$(${PKG_MGR_CMD} -q check-update 2>&1) + rc=$? + # centos 7 sometimes returns a status of 100 when it apears to work. + if [ $rc != 0 ] && [ $rc != 100 ]; then + echo "(Error) ${PKG_MGR_CMD} check-update produced the following error message(s):" + echo "${stderr_messages}" + exit 1 + fi set -e fi fi @@ -172,13 +174,13 @@ check_packages() { case ${ADJUSTED_ID} in debian) if ! dpkg -s "$@" > /dev/null 2>&1; then - pkg_mgr_update + pkg_manager_update ${INSTALL_CMD} "$@" fi ;; rhel) if ! rpm -q "$@" > /dev/null 2>&1; then - pkg_mgr_update + pkg_manager_update ${INSTALL_CMD} "$@" fi ;;