Skip to content

Commit

Permalink
Merge pull request #306 from mr-serjey/gretty-3.x
Browse files Browse the repository at this point in the history
Make Gretty aware of Gradle Java Toolchain
  • Loading branch information
boris-petrov authored Jun 3, 2024
2 parents accd514 + b98085e commit 5557fbf
Show file tree
Hide file tree
Showing 54 changed files with 865 additions and 272 deletions.
26 changes: 22 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
path: ${{ env.PRIVATE_REPO }}

test:
name: Gradle ${{ matrix.gradle }} on Java ${{ matrix.java }}
name: Gradle ${{ matrix.gradle }} on Java ${{ matrix.java }}${{ matrix.toolchainJavaVersion && format(' (Java {0} Container)', matrix.toolchainJavaVersion) || '' }}
runs-on: ubuntu-latest
needs: build

Expand All @@ -49,13 +49,29 @@ jobs:
gradle: '6.9.4'
container: "['jetty9.3','jetty9.4','tomcat85','tomcat9']"

- java: 8
gradle: '6.9.4'
container: "['jetty9.3','jetty9.4','tomcat85','tomcat9']"
toolchainJavaVersion: 17

- java: 11
gradle: '6.9.4'
container: "['jetty9.3','jetty9.4','jetty10','tomcat85','tomcat9']"


- java: 11
gradle: '6.9.4'
container: "['jetty9.3','jetty9.4','jetty10','tomcat85','tomcat9']"
toolchainJavaVersion: 17

- java: 17
gradle: '7.6.4'
container: "['jetty9.3','jetty9.4','jetty10','tomcat85','tomcat9']"
properties: '-Pspock_version=2.3-groovy-3.0 -PgebVersion=5.1'

- java: 17
gradle: '7.6.4'
container: "['jetty9.3','jetty9.4','jetty10','tomcat85','tomcat9']"
toolchainJavaVersion: 21
properties: '-Pspock_version=2.3-groovy-3.0 -PgebVersion=5.1'

# TODO: add a JDK-21 build but fix the following issue before that:
Expand All @@ -66,6 +82,8 @@ jobs:
TEST_ALL_CONTAINERS: ${{ matrix.container }}
GRADLE_VERSION: ${{ matrix.gradle }}
EXTRA_PROPERTIES: ${{ matrix.properties }}
TOOLCHAIN_JAVA_ARGS: "${{ matrix.toolchainJavaVersion && format('-PtoolchainJavaVersion={0}', matrix.toolchainJavaVersion) || '' }}"
GRADLE_TEST_TASK: "${{ matrix.toolchainJavaVersion && 'testAllJavaToolchain' || 'testAll' }}"

steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -101,8 +119,8 @@ jobs:
../gradlew --no-daemon \
--warning-mode all \
-PprivateRepoDir=$PRIVATE_REPO \
$EXTRA_PROPERTIES \
$EXTRA_PROPERTIES $TOOLCHAIN_JAVA_ARGS \
-PgeckoDriverPlatform=linux64 \
-PtestAllContainers=$TEST_ALL_CONTAINERS \
testAll
$GRADLE_TEST_TASK
working-directory: integrationTests
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ build
*.iws
bin/
.DS_Store
.docker-gradle/
45 changes: 45 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
FROM ubuntu as base
RUN apt-get update

FROM base as base-utils
ENV _BASH_UTILS_DIR=/root/.bashrc.d
COPY <<-EOF $_BASH_UTILS_DIR/0_on_bash_ready.bash
shopt -s expand_aliases
export _on_bash_ready_i=\$(find $_BASH_UTILS_DIR -type f | wc -l)
function on_bash_ready (){
((_on_bash_ready_i++))
local file="$_BASH_UTILS_DIR/\${_on_bash_ready_i}.bash"
echo "\$@" >> \$file && \
sed -i 's/\r\$//' \$file && \
source \$file
}
EOF
RUN sed -i 's/\r$//' $_BASH_UTILS_DIR/0_on_bash_ready.bash
RUN echo "while read -r FILE; do source \$FILE; done < <( find $_BASH_UTILS_DIR -name '*.bash' | sort)" >> ~/.profile
SHELL ["/bin/bash", "-l", "-c"]


FROM base-utils as firefox
RUN apt-get install -y wget
RUN install -d -m 0755 /etc/apt/keyrings
RUN wget -q https://packages.mozilla.org/apt/repo-signing-key.gpg -O- | tee /etc/apt/keyrings/packages.mozilla.org.asc > /dev/null
RUN echo 'deb [signed-by=/etc/apt/keyrings/packages.mozilla.org.asc] https://packages.mozilla.org/apt mozilla main' | tee -a /etc/apt/sources.list.d/mozilla.list > /dev/null
RUN apt-get update && apt-get install -y firefox-devedition-l10n-eu
RUN ln -s /usr/bin/firefox-devedition /usr/bin/firefox


FROM firefox as firefox-sdkman
RUN apt-get install -y curl unzip zip findutils
RUN curl -s "https://get.sdkman.io?rcupdate=false" | bash
RUN on_bash_ready source /root/.sdkman/bin/sdkman-init.sh

FROM firefox-sdkman as firefox-jdk
ARG JAVA_VERSIONS="8.0.412-amzn"
ENV JAVA_VERSIONS="$JAVA_VERSIONS"
RUN on_bash_ready 'alias install_jdk="sdk install java $1"'
RUN for version in ${JAVA_VERSIONS//,/ } ; do install_jdk $version ; done


FROM firefox-jdk as firefox-jdk-gradle
ARG GRADLE_VERSION="6.9.4"
RUN sdk install gradle $GRADLE_VERSION
60 changes: 60 additions & 0 deletions docker_gradlew.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/usr/bin/env bash
set -e

function build_docker_gradlew_image(){
docker build -t "docker_gradlew" . \
--build-arg JAVA_VERSIONS="$_javas" \
--build-arg GRADLE_VERSION="$_gradle"
}

function run_docker(){
build_docker_gradlew_image "$*"

local working_dir="-w //project/${_working_dir}"

local project_volume="-v //$(realpath .)://project"

local gradle_home_volume=""
if [ "$_gradle_home" ]; then
gradle_home_volume="-v //$(realpath $_gradle_home)://root/.gradle"
fi

local params="$DOCKER_ARGS $project_volume $working_dir $gradle_home_volume"


echo "RUNNING:" docker run --rm -it $params docker_gradlew "$@"
docker run --rm -it $params docker_gradlew "$@"
}

function run_docker_gradle() {
run_docker bash -lc "gradle $*"
}


JDK["8"]="8.0.412-amzn"
JDK["11"]="11.0.23-amzn"
JDK["17"]="17.0.11-amzn"
JDK["21"]="21.0.3-amzn"

GRADLE["6"]="6.9.4"
GRADLE["7"]="7.6.4"

POSITIONAL_ARGS=()
while [[ $# -gt 0 ]]; do
case "$1" in
-j|--java) export _javas+=",${JDK[$2]:=$2}" && shift 2 ;;
-g|--gradle) export _gradle=${GRADLE[$2]:=$2} && shift 2 ;;
-h|--gradle-home) export _gradle_home=$2 && shift 2 ;;
-w|--working-dir) export _working_dir=$2 && shift 2 ;;
-b|--bash) export _bash="Yes" && shift 1 ;;

*) POSITIONAL_ARGS+=("$1") && shift ;;
esac
done
set -- "${POSITIONAL_ARGS[@]}" # restore positional parameters

if [ "$_bash" ]; then
run_docker bash -l
else
run_docker_gradle "${@}"
fi
78 changes: 78 additions & 0 deletions docker_integration_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/usr/bin/env bash
set -e

export common_gradle_args="--console=plain --no-daemon -Porg.gradle.java.installations.auto-download=false -PgeckoDriverPlatform=linux64"

#ci.yml plugin build step
./docker_gradlew.sh \
--java 11 \
--gradle 6 \
--gradle-home .docker-gradle \
$common_gradle_args \
build

#ci.yml matrix case #1
./docker_gradlew.sh \
--java 8 \
--gradle 6 \
--gradle-home .docker-gradle \
--working-dir integrationTests \
$common_gradle_args \
-PtestAllContainers="\"['jetty9.3','jetty9.4','tomcat85','tomcat9']\"" \
testAll

#ci.yml matrix case #2
./docker_gradlew.sh \
--java 11 \
--gradle 6 \
--gradle-home .docker-gradle \
--working-dir integrationTests \
$common_gradle_args \
-PtestAllContainers="\"['jetty9.3','jetty9.4','jetty10','tomcat85','tomcat9']\"" \
testAll

#ci.yml matrix case #3
./docker_gradlew.sh \
--java 17 \
--gradle 7 \
--gradle-home .docker-gradle \
--working-dir integrationTests \
$common_gradle_args \
-PtestAllContainers="\"['jetty9.3','jetty9.4','jetty10','tomcat85','tomcat9']\"" \
-Pspock_version=2.3-groovy-3.0 -PgebVersion=5.1 \
testAll

#ci.yml matrix case #1 + toolchain java v21
./docker_gradlew.sh \
--java 17 --java 8 \
--gradle 6 \
--gradle-home .docker-gradle \
--working-dir integrationTests \
$common_gradle_args \
-PtestAllContainers="\"['jetty9.3','jetty9.4','tomcat85','tomcat9']\"" \
-PtoolchainJavaVersion=17 \
testAllJavaToolchain

#ci.yml matrix case #2 + toolchain java v17
./docker_gradlew.sh \
--java 17 --java 11 \
--gradle 6 \
--gradle-home .docker-gradle \
--working-dir integrationTests \
$common_gradle_args \
-PtestAllContainers="\"['jetty9.3','jetty9.4','jetty10','tomcat85','tomcat9']\"" \
-PtoolchainJavaVersion=17 \
testAllJavaToolchain


#ci.yml matrix case #3 + toolchain java v21
./docker_gradlew.sh \
--java 21 --java 17 \
--gradle 7 \
--gradle-home .docker-gradle \
--working-dir integrationTests \
$common_gradle_args \
-PtestAllContainers="\"['jetty9.3','jetty9.4','jetty10','tomcat85','tomcat9']\"" \
-Pspock_version=2.3-groovy-3.0 -PgebVersion=5.1 \
-PtoolchainJavaVersion=21 \
testAllJavaToolchain
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package org.akhikhl.gretty.internal.integrationTests;

import java.util.Objects;

public class AnyJavaVersion implements Comparable<AnyJavaVersion> {
private int majorVersion;

private AnyJavaVersion(int majorVersion) {
this.majorVersion = majorVersion;
}

public int getMajorVersion() {
return majorVersion;
}

public boolean isJava9Compatible() {
return majorVersion >= 9;
}

public boolean isJava10Compatible() {
return majorVersion >= 10;
}

@Override
public int compareTo(AnyJavaVersion o) {
return Integer.compare(this.majorVersion, o.majorVersion);
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
AnyJavaVersion that = (AnyJavaVersion) o;
return majorVersion == that.majorVersion;
}

@Override
public int hashCode() {
return Objects.hashCode(majorVersion);
}

public static AnyJavaVersion of(Integer integer) {
return new AnyJavaVersion(Objects.requireNonNull(integer));
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.akhikhl.gretty.internal.integrationTests

import org.akhikhl.gretty.ServletContainerConfig
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.publish.maven.MavenPublication
Expand All @@ -27,7 +26,9 @@ class BasePlugin implements Plugin<Project> {
}

protected void configureExtensions(Project project) {
// does nothing by default
if (!project.extensions.findByName('javaVersion')) {
project.extensions.add(AnyJavaVersion, 'javaVersion', JavaToolchainIntegrationTestPlugin.getToolchainJavaVersion(project))
}
}

protected void configurePublications(Project project) {
Expand Down Expand Up @@ -98,6 +99,9 @@ class BasePlugin implements Plugin<Project> {
if(!project.rootProject.tasks.findByName('testAll'))
project.rootProject.task 'testAll'

if(!project.rootProject.tasks.findByName('testAllJavaToolchain'))
project.rootProject.task 'testAllJavaToolchain'

project.tasks.withType(Test).configureEach {
if (GradleVersion.current().baseVersion.version.startsWith("7.")) {
useJUnitPlatform()
Expand Down
Loading

0 comments on commit 5557fbf

Please sign in to comment.