Skip to content

Commit

Permalink
[java] Support groovy installations (#779)
Browse files Browse the repository at this point in the history
* [java] Support groovy installations

Fix java test failing with non existent 19 version of `open` distro

* fix: Typo

* feat: Implement code review comments

---------

Co-authored-by: Samruddhi Khandale <[email protected]>
  • Loading branch information
Ash258 and samruddhikhandale authored Jan 22, 2024
1 parent 65fb90b commit 76ffd41
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 12 deletions.
23 changes: 20 additions & 3 deletions src/java/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "java",
"version": "1.2.2",
"version": "1.3.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.",
Expand All @@ -23,7 +23,8 @@
"ms",
"open",
"oracle",
"tem"
"tem",
"amzn"
],
"default": "ms",
"description": "Select or enter a JDK distribution"
Expand Down Expand Up @@ -74,6 +75,22 @@
],
"default": "latest",
"description": "Select or enter an Ant version"
},
"installGroovy": {
"type": "boolean",
"default": false,
"description": "Install Groovy, powerful, optionally typed and dynamic language with static-typing and static compilation capabilities"
},
"groovyVersion": {
"type": "string",
"proposals": [
"latest",
"2.5.22",
"3.0.19",
"4.0.16"
],
"default": "latest",
"description": "Select or enter a Groovy version"
}
},
"customizations": {
Expand All @@ -92,6 +109,6 @@
"PATH": "/usr/local/sdkman/bin:/usr/local/sdkman/candidates/java/current/bin:/usr/local/sdkman/candidates/gradle/current/bin:/usr/local/sdkman/candidates/maven/current/bin:/usr/local/sdkman/candidates/ant/current/bin:${PATH}"
},
"installsAfter": [
"ghcr.io/devcontainers/features/common-utils"
"ghcr.io/devcontainers/features/common-utils"
]
}
7 changes: 7 additions & 0 deletions src/java/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ INSTALL_MAVEN="${INSTALLMAVEN:-"false"}"
MAVEN_VERSION="${MAVENVERSION:-"latest"}"
INSTALL_ANT="${INSTALLANT:-"false"}"
ANT_VERSION="${ANTVERSION:-"latest"}"
INSTALL_GROOVY="${INSTALLGROOVY:-"false"}"
GROOVY_VERSION="${GROOVYVERSION:-"latest"}"
JDK_DISTRO="${JDKDISTRO}"

export SDKMAN_DIR="${SDKMAN_DIR:-"/usr/local/sdkman"}"
Expand Down Expand Up @@ -190,6 +192,11 @@ if [[ "${INSTALL_MAVEN}" = "true" ]] && ! mvn --version > /dev/null; then
sdk_install maven ${MAVEN_VERSION}
fi

# Install Groovy
if [[ "${INSTALL_GROOVY}" = "true" ]] && ! groovy --version > /dev/null; then
sdk_install groovy "${GROOVY_VERSION}"
fi

# Clean up
rm -rf /var/lib/apt/lists/*

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,11 @@ 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
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,11 @@ 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
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,7 @@ 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
2 changes: 1 addition & 1 deletion test/java/install_from_non_default_distro.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -e
# Optional: Import test library
source dev-container-features-test-lib

check "java version openjdk 19 installed" grep "openjdk 19." <(java --version)
check "java version openjdk 21 installed" grep "openjdk 21." <(java --version)

# Report result
reportResults
20 changes: 12 additions & 8 deletions test/java/scenarios.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"image": "ubuntu:focal",
"features": {
"java": {
"version": "19",
"version": "21",
"jdkDistro": "open"
}
}
Expand All @@ -17,7 +17,7 @@
}
}
},
"install_ant_and_gradle_and_maven_for_user": {
"install_ant_and_gradle_and_maven_and_groovy_for_user": {
"image": "ubuntu:focal",
"remoteUser": "vscode",
"features": {
Expand All @@ -28,22 +28,24 @@
"version": "latest",
"installAnt": true,
"installGradle": true,
"installMaven": true
"installMaven": true,
"installGroovy": true
}
}
},
"install_ant_and_gradle_and_maven": {
"install_ant_and_gradle_and_maven_and_groovy": {
"image": "ubuntu:focal",
"features": {
"java": {
"version": "latest",
"installAnt": true,
"installGradle": true,
"installMaven": true
"installMaven": true,
"installGroovy": true
}
}
},
"install_ant_and_gradle_and_maven_with_specific_version": {
"install_ant_and_gradle_and_maven_and_groovy_with_specific_version": {
"image": "ubuntu:focal",
"features": {
"java": {
Expand All @@ -53,13 +55,15 @@
"installGradle": "true",
"gradleVersion": "6.8.3",
"installMaven": "true",
"mavenVersion": "3.6.3"
"mavenVersion": "3.6.3",
"installGroovy": "true",
"groovyVersion": "2.5.22"
}
}
},
"install_non_conventional_version": {
"image": "ubuntu:focal",
"features":{
"features": {
"java": {
"version": "21",
"jdkDistro": "graalce"
Expand Down

0 comments on commit 76ffd41

Please sign in to comment.