Unverified Commit dd0266fe authored by Gaurav Saini's avatar Gaurav Saini Committed by GitHub

[Java] - features issue #1101 - installs -tem instead -ms for lts installation (#1021)

* [Java] - features issue #1101 - installs -tem instead -ms for lts installation

* misc change

* misc change, by mistake needs correction

* leave a line change

* remove spaces

* bump patch version..

* changes for pr reviewed

* changes

* Update src/java/devcontainer-feature.json
Co-authored-by: 's avatarSamruddhi Khandale <samruddhikhandale@github.com>

* [java] - corrected lts version finding logic in install.sh

* small change

* changes as requested..

* changes as requested

* changes as suggested - centos-7, mirrorlist no longer exists - changed to vault

* corrected condition for specific version installations..

* misc change

* corrected condition

* small change

* corrections

* change

* changes in test cases - removing /tmp before test specific test runs..

* few changes to test cases again..

* small change

* addition of --overwrite option to gradle init command

* changes as suggested on pr comments

* misc. change for correcting logic

---------
Co-authored-by: 's avatarSamruddhi Khandale <samruddhikhandale@github.com>
parent f5f489f6
{ {
"id": "java", "id": "java",
"version": "1.5.0", "version": "1.6.0",
"name": "Java (via SDKMAN!)", "name": "Java (via SDKMAN!)",
"documentationURL": "https://github.com/devcontainers/features/tree/main/src/java", "documentationURL": "https://github.com/devcontainers/features/tree/main/src/java",
"description": "Installs Java, SDKMAN! (if not installed), and needed dependencies.", "description": "Installs Java, SDKMAN! (if not installed), and needed dependencies.",
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
# #
# Syntax: ./java-debian.sh [JDK version] [SDKMAN_DIR] [non-root user] [Add to rc files flag] # Syntax: ./java-debian.sh [JDK version] [SDKMAN_DIR] [non-root user] [Add to rc files flag]
JAVA_VERSION="${VERSION:-"lts"}" JAVA_VERSION="${VERSION:-"latest"}"
INSTALL_GRADLE="${INSTALLGRADLE:-"false"}" INSTALL_GRADLE="${INSTALLGRADLE:-"false"}"
GRADLE_VERSION="${GRADLEVERSION:-"latest"}" GRADLE_VERSION="${GRADLEVERSION:-"latest"}"
INSTALL_MAVEN="${INSTALLMAVEN:-"false"}" INSTALL_MAVEN="${INSTALLMAVEN:-"false"}"
...@@ -53,6 +53,14 @@ else ...@@ -53,6 +53,14 @@ else
exit 1 exit 1
fi fi
if [ "${ADJUSTED_ID}" = "rhel" ] && [ "${VERSION_CODENAME-}" = "centos7" ]; then
# As of 1 July 2024, mirrorlist.centos.org no longer exists.
# Update the repo files to reference vault.centos.org.
sed -i s/mirror.centos.org/vault.centos.org/g /etc/yum.repos.d/*.repo
sed -i s/^#.*baseurl=http/baseurl=http/g /etc/yum.repos.d/*.repo
sed -i s/^mirrorlist=http/#mirrorlist=http/g /etc/yum.repos.d/*.repo
fi
# Setup INSTALL_CMD & PKG_MGR_CMD # Setup INSTALL_CMD & PKG_MGR_CMD
if type apt-get > /dev/null 2>&1; then if type apt-get > /dev/null 2>&1; then
PKG_MGR_CMD=apt-get PKG_MGR_CMD=apt-get
...@@ -197,6 +205,22 @@ get_jdk_distro() { ...@@ -197,6 +205,22 @@ get_jdk_distro() {
fi fi
} }
find_version_list() {
prefix="$1"
suffix="$2"
install_type=$3
ifLts="$4"
version_list=$5
if [ "${ifLts}" = "true" ]; then
all_lts_versions=$(curl -s https://api.adoptium.net/v3/info/available_releases)
major_version=$(echo "$all_lts_versions" | jq -r '.most_recent_lts')
regex="${prefix}\\K${major_version}\\.?[0-9]*\\.?[0-9]*${suffix}"
else
regex="${prefix}\\K[0-9]+\\.?[0-9]*\\.?[0-9]*${suffix}"
fi
declare -g ${version_list}="$(su ${USERNAME} -c ". \${SDKMAN_DIR}/bin/sdkman-init.sh && sdk list ${install_type} 2>&1 | grep -oP \"${regex}\" | tr -d ' ' | sort -rV")"
}
# Use SDKMAN to install something using a partial version match # Use SDKMAN to install something using a partial version match
sdk_install() { sdk_install() {
local install_type=$1 local install_type=$1
...@@ -205,15 +229,21 @@ sdk_install() { ...@@ -205,15 +229,21 @@ sdk_install() {
local suffix="${4:-"\\s*"}" local suffix="${4:-"\\s*"}"
local full_version_check=${5:-".*-[a-z]+"} local full_version_check=${5:-".*-[a-z]+"}
local set_as_default=${6:-"true"} local set_as_default=${6:-"true"}
pkgs=("maven" "gradle" "ant" "groovy")
pkg_vals="${pkgs[@]}"
if [ "${requested_version}" = "none" ]; then return; fi if [ "${requested_version}" = "none" ]; then return; fi
# Blank will install latest stable version SDKMAN has if [ "${requested_version}" = "default" ]; then
if [ "${requested_version}" = "latest" ] || [ "${requested_version}" = "lts" ] || [ "${requested_version}" = "default" ]; then
requested_version="" requested_version=""
elif [[ "${pkg_vals}" =~ "${install_type}" ]] && [ "${requested_version}" = "latest" ]; then
requested_version=""
elif [ "${requested_version}" = "lts" ]; then
check_packages jq
find_version_list "$prefix" "$suffix" "$install_type" "true" version_list
requested_version="$(echo "${version_list}" | head -n 1)"
elif echo "${requested_version}" | grep -oE "${full_version_check}" > /dev/null 2>&1; then elif echo "${requested_version}" | grep -oE "${full_version_check}" > /dev/null 2>&1; then
echo "${requested_version}" echo "${requested_version}"
else else
local regex="${prefix}\\K[0-9]+\\.?[0-9]*\\.?[0-9]*${suffix}" find_version_list "$prefix" "$suffix" "$install_type" "false" version_list
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 if [ "${requested_version}" = "latest" ] || [ "${requested_version}" = "current" ]; then
requested_version="$(echo "${version_list}" | head -n 1)" requested_version="$(echo "${version_list}" | head -n 1)"
else else
......
...@@ -17,7 +17,7 @@ cd /tmp && ant init ...@@ -17,7 +17,7 @@ cd /tmp && ant init
check "ant-src exists" grep "ant-src" <(ls -la /tmp) check "ant-src exists" grep "ant-src" <(ls -la /tmp)
check "gradle" gradle --version check "gradle" gradle --version
cd /tmp && gradle init --type basic --dsl groovy --incubating --project-name test cd /tmp && gradle init --type basic --dsl groovy --overwrite --incubating --project-name test
check "GRADLE_USER_HOME exists" grep ".gradle" <(ls -la /root) check "GRADLE_USER_HOME exists" grep ".gradle" <(ls -la /root)
check "maven" mvn --version check "maven" mvn --version
......
...@@ -10,6 +10,7 @@ check "user is vscode" grep vscode <(whoami) ...@@ -10,6 +10,7 @@ check "user is vscode" grep vscode <(whoami)
check "java" java --version check "java" java --version
check "ant" ant -version check "ant" ant -version
cat << EOF > /tmp/build.xml cat << EOF > /tmp/build.xml
<project><target name="init"><mkdir dir="ant-src"/></target></project> <project><target name="init"><mkdir dir="ant-src"/></target></project>
EOF EOF
...@@ -17,7 +18,7 @@ cd /tmp && ant init ...@@ -17,7 +18,7 @@ cd /tmp && ant init
check "ant-src exists" grep "ant-src" <(ls -la /tmp) check "ant-src exists" grep "ant-src" <(ls -la /tmp)
check "gradle" gradle --version check "gradle" gradle --version
cd /tmp && gradle init --type basic --dsl groovy --incubating --project-name test cd /tmp && gradle init --type basic --dsl groovy --overwrite --incubating --project-name test
check "GRADLE_USER_HOME exists" grep ".gradle" <(ls -la /home/vscode) check "GRADLE_USER_HOME exists" grep ".gradle" <(ls -la /home/vscode)
check "maven" mvn --version check "maven" mvn --version
......
...@@ -17,7 +17,7 @@ cd /tmp && ant init ...@@ -17,7 +17,7 @@ cd /tmp && ant init
check "ant-src exists" grep "ant-src" <(ls -la /tmp) check "ant-src exists" grep "ant-src" <(ls -la /tmp)
check "gradle" gradle --version check "gradle" gradle --version
cd /tmp && gradle init --type basic --dsl groovy --incubating --project-name test cd /tmp && gradle init --type basic --dsl groovy --overwrite --incubating --project-name test
check "GRADLE_USER_HOME exists" grep ".gradle" <(ls -la /home/vscode) check "GRADLE_USER_HOME exists" grep ".gradle" <(ls -la /home/vscode)
check "maven" mvn --version check "maven" mvn --version
......
...@@ -17,7 +17,7 @@ cd /tmp && ant init ...@@ -17,7 +17,7 @@ cd /tmp && ant init
check "ant-src exists" grep "ant-src" <(ls -la /tmp) check "ant-src exists" grep "ant-src" <(ls -la /tmp)
check "gradle" gradle --version check "gradle" gradle --version
cd /tmp && gradle init --type basic --dsl groovy --incubating --project-name test cd /tmp && gradle init --type basic --dsl groovy --overwrite --incubating --project-name test
check "GRADLE_USER_HOME exists" grep ".gradle" <(ls -la /root) check "GRADLE_USER_HOME exists" grep ".gradle" <(ls -la /root)
check "maven" mvn --version check "maven" mvn --version
......
#!/bin/bash
set -e
# Optional: Import test library
source dev-container-features-test-lib
check "java version LTS installed as default" grep "LTS" <(java --version)
# Report result
reportResults
...@@ -8,6 +8,14 @@ ...@@ -8,6 +8,14 @@
} }
} }
}, },
"install_lts_version": {
"image": "ubuntu:focal",
"features": {
"java": {
"version": "lts"
}
}
},
"install_additional_java": { "install_additional_java": {
"image": "ubuntu:focal", "image": "ubuntu:focal",
"features": { "features": {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment