diff options
author | etienne-chrp <66628513+etienne-chrp@users.noreply.github.com> | 2022-11-17 03:46:30 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-17 03:46:30 +0300 |
commit | be4f0498e4ad7948804d4be70093c1da8722d222 (patch) | |
tree | a50ac3ee2038a5b4130b7bdfcace59b4140efc5b | |
parent | bff31788373499fdc903bad8f1b300d579c42d39 (diff) |
Add Gradle and Maven version parameters to Java (#263)
* Refactor java feature tests grep syntax
The grep with pipe syntax was creating problems with the check helper
Change them in favour of process substitution syntax
* Fix java feature tests about java version
Java 18 is not available anymore in SDKMAN
Some tests asserts were generating false positives
* Add Gradle and Maven version parameters to Java
-rw-r--r-- | src/java/README.md | 2 | ||||
-rw-r--r-- | src/java/devcontainer-feature.json | 24 | ||||
-rwxr-xr-x | src/java/install.sh | 6 | ||||
-rw-r--r-- | test/java/install_additional_java.sh | 6 | ||||
-rw-r--r-- | test/java/install_from_non_default_distro.sh | 2 | ||||
-rw-r--r-- | test/java/install_gradle_and_maven.sh | 6 | ||||
-rw-r--r-- | test/java/install_gradle_and_maven_for_user.sh | 6 | ||||
-rw-r--r-- | test/java/install_gradle_and_maven_with_specific_version.sh | 21 | ||||
-rw-r--r-- | test/java/scenarios.json | 18 |
9 files changed, 75 insertions, 16 deletions
diff --git a/src/java/README.md b/src/java/README.md index c409b34..a9ef433 100644 --- a/src/java/README.md +++ b/src/java/README.md @@ -18,7 +18,9 @@ Installs Java, SDKMAN! (if not installed), and needed dependencies. | 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 | ## License diff --git a/src/java/devcontainer-feature.json b/src/java/devcontainer-feature.json index 19d6c13..c400fb6 100644 --- a/src/java/devcontainer-feature.json +++ b/src/java/devcontainer-feature.json @@ -1,6 +1,6 @@ { "id": "java", - "version": "1.0.11", + "version": "1.1.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.", @@ -33,10 +33,32 @@ "default": false, "description": "Install Gradle, a build automation tool for multi-language software development" }, + "gradleVersion": { + "type": "string", + "proposals": [ + "latest", + "7.5.1", + "6.9.3", + "5.6.4" + ], + "default": "latest", + "description": "Select or enter a Gradle version" + }, "installMaven": { "type": "boolean", "default": false, "description": "Install Maven, a management tool for Java" + }, + "mavenVersion": { + "type": "string", + "proposals": [ + "latest", + "3.8.6", + "3.6.3", + "3.5.4" + ], + "default": "latest", + "description": "Select or enter a Maven version" } }, "buildArg": "_VSC_INSTALL_JAVA", diff --git a/src/java/install.sh b/src/java/install.sh index d2f735d..5928478 100755 --- a/src/java/install.sh +++ b/src/java/install.sh @@ -11,7 +11,9 @@ JAVA_VERSION=${VERSION:-"lts"} INSTALL_GRADLE=${INSTALLGRADLE:-"false"} +GRADLE_VERSION=${GRADLEVERSION:-"latest"} INSTALL_MAVEN=${INSTALLMAVEN:-"false"} +MAVEN_VERSION=${MAVENVERSION:-"latest"} JDK_DISTRO=${JDKDISTRO} export SDKMAN_DIR=${SDKMAN_DIR:-"/usr/local/sdkman"} @@ -173,12 +175,12 @@ fi # Install Gradle if [[ "${INSTALL_GRADLE}" = "true" ]] && ! gradle --version > /dev/null; then - sdk_install gradle latest + sdk_install gradle ${GRADLE_VERSION} fi # Install Maven if [[ "${INSTALL_MAVEN}" = "true" ]] && ! mvn --version > /dev/null; then - sdk_install maven latest + sdk_install maven ${MAVEN_VERSION} fi # Clean up diff --git a/test/java/install_additional_java.sh b/test/java/install_additional_java.sh index fcfd6bd..882c49d 100644 --- a/test/java/install_additional_java.sh +++ b/test/java/install_additional_java.sh @@ -5,9 +5,9 @@ set -e # Optional: Import test library source dev-container-features-test-lib -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 +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_from_non_default_distro.sh b/test/java/install_from_non_default_distro.sh index e45f9dd..d4f5381 100644 --- a/test/java/install_from_non_default_distro.sh +++ b/test/java/install_from_non_default_distro.sh @@ -5,7 +5,7 @@ set -e # Optional: Import test library source dev-container-features-test-lib -check "java version 18 installed as default" java --version | grep 18 +check "java version openjdk 11 installed" grep "openjdk 11." <(java --version) # Report result reportResults diff --git a/test/java/install_gradle_and_maven.sh b/test/java/install_gradle_and_maven.sh index c6aa3e5..636fd92 100644 --- a/test/java/install_gradle_and_maven.sh +++ b/test/java/install_gradle_and_maven.sh @@ -5,17 +5,17 @@ set -e # Optional: Import test library source dev-container-features-test-lib -check "user is root" whoami | grep root +check "user is root" grep root <(whoami) check "java" java --version check "gradle" gradle --version cd /tmp && gradle init --type basic --dsl groovy --incubating --project-name test -check "GRADLE_USER_HOME exists" ls -la /root | grep ".gradle" +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" ls -la /root | grep ".m2" +check "m2 exists" grep ".m2" <(ls -la /root) # Report result reportResults diff --git a/test/java/install_gradle_and_maven_for_user.sh b/test/java/install_gradle_and_maven_for_user.sh index c724092..b6ea426 100644 --- a/test/java/install_gradle_and_maven_for_user.sh +++ b/test/java/install_gradle_and_maven_for_user.sh @@ -5,17 +5,17 @@ set -e # Optional: Import test library source dev-container-features-test-lib -check "user is vscode" whoami | grep vscode +check "user is vscode" grep vscode <(whoami) check "java" java --version check "gradle" gradle --version cd /tmp && gradle init --type basic --dsl groovy --incubating --project-name test -check "GRADLE_USER_HOME exists" ls -la /home/vscode | grep ".gradle" +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" ls -la /home/vscode | grep ".m2" +check "m2 exists" grep ".m2" <(ls -la /home/vscode) # Report result reportResults diff --git a/test/java/install_gradle_and_maven_with_specific_version.sh b/test/java/install_gradle_and_maven_with_specific_version.sh new file mode 100644 index 0000000..c6ae6160 --- /dev/null +++ b/test/java/install_gradle_and_maven_with_specific_version.sh @@ -0,0 +1,21 @@ +#!/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 "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) + +# Report result +reportResults diff --git a/test/java/scenarios.json b/test/java/scenarios.json index eec7ba5..c33a0a7 100644 --- a/test/java/scenarios.json +++ b/test/java/scenarios.json @@ -3,7 +3,7 @@ "image": "ubuntu:focal", "features": { "java": { - "version": "18", + "version": "11", "jdkDistro": "open" } } @@ -12,8 +12,8 @@ "image": "ubuntu:focal", "features": { "java": { - "version": "18", - "additionalVersions": "11,8" + "version": "11", + "additionalVersions": "17,8" } } }, @@ -40,5 +40,17 @@ "installMaven": true } } + }, + "install_gradle_and_maven_with_specific_version": { + "image": "ubuntu:focal", + "features": { + "java": { + "version": "latest", + "installGradle": "true", + "gradleVersion": "6.8.3", + "installMaven": "true", + "mavenVersion": "3.6.3" + } + } } } |