blob: 27578b20caf743053be52eec4a0ad1bbc7e2d0d5 [file] [log] [blame]
robert.tomczyk5fe5de72019-07-22 20:48:58 +01001#!/usr/bin/env bash
2#
3# Licensed to the Apache Software Foundation (ASF) under one
4# or more contributor license agreements. See the NOTICE file
5# distributed with this work for additional information
6# regarding copyright ownership. The ASF licenses this file
7# to you under the Apache License, Version 2.0 (the
8# "License"); you may not use this file except in compliance
9# with the License. You may obtain a copy of the License at
10#
11# http://www.apache.org/licenses/LICENSE-2.0
12#
13# Unless required by applicable law or agreed to in writing, software
14# distributed under the License is distributed on an "AS IS" BASIS,
15# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16# See the License for the specific language governing permissions and
17# limitations under the License.
18
19set -e
20
21BASE_DIR=$(pwd)
22
23SOURCE="${BASH_SOURCE[0]}"
24while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
25 SCRIPTDIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
26 SOURCE="$(readlink "$SOURCE")"
27 [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
28done
29SCRIPTDIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
30
31if [[ -z "${GRADLE_TASK}" ]]; then
32 echo "GRADLE_TASK must be set. exiting..."
33 exit 1
34fi
35
36REPODIR=$(cd geode; git rev-parse --show-toplevel)
37
38if [[ ${PARALLEL_GRADLE:-"true"} == "true" ]]; then
39 PARALLEL_GRADLE="--parallel"
40else
41 PARALLEL_GRADLE="--no-parallel"
42fi
43DEFAULT_GRADLE_TASK_OPTIONS="${PARALLEL_GRADLE} --console=plain --no-daemon"
44GRADLE_SKIP_TASK_OPTIONS="-x javadoc -x spotlessCheck -x rat"
45
46if [[ -n "${PARALLEL_DUNIT}" && "${PARALLEL_DUNIT}" == "true" ]]; then
robert.tomczyk8e4e5782022-10-20 14:45:43 +010047 PARALLEL_DUNIT="-PparallelDunit"
robert.tomczyk5defccb2022-11-09 11:13:49 +000048 if [[ -n "${DUNIT_PARALLEL_FORKS}" && "${TEST_USING_DOCKER}" == "false" ]] ; then
robert.tomczyk8e4e5782022-10-20 14:45:43 +010049 DUNIT_PARALLEL_FORKS="--max-workers=${DUNIT_PARALLEL_FORKS} -PtestMaxParallelForks=${DUNIT_PARALLEL_FORKS} -PdunitParallelForks=${DUNIT_PARALLEL_FORKS}"
robert.tomczyk5defccb2022-11-09 11:13:49 +000050 elif [[ -n "${DUNIT_PARALLEL_FORKS}" && "${TEST_USING_DOCKER}" == "true" ]] ; then
51 DUNIT_PARALLEL_FORKS="-PdunitParallelForks=${DUNIT_PARALLEL_FORKS}"
52 DOCKER_TESTING_OPTIONS="-PdunitDockerUser=geode -PdunitDockerImage=\$(docker images --format '{{.Repository}}:{{.Tag}}' | grep test-container)"
robert.tomczyk5fe5de72019-07-22 20:48:58 +010053 fi
54else
55 PARALLEL_DUNIT=""
56 DUNIT_PARALLEL_FORKS=""
robert.tomczyk5defccb2022-11-09 11:13:49 +000057 DOCKER_TESTING_OPTIONS=""
robert.tomczyk5fe5de72019-07-22 20:48:58 +010058fi
59
60case $ARTIFACT_SLUG in
61 windows*)
robert.tomczyk8e4e5782022-10-20 14:45:43 +010062 echo "Making environment adjustments for windows."
robert.tomczyk5fe5de72019-07-22 20:48:58 +010063 JAVA_BUILD_PATH=C:/java${JAVA_BUILD_VERSION}
64 JAVA_TEST_PATH=C:/java${JAVA_TEST_VERSION}
robert.tomczyk8e4e5782022-10-20 14:45:43 +010065 TEST_JAVA_8_HOME=C:/java8
66 TEST_JAVA_11_HOME=C:/java11
67 TEST_JAVA_17_HOME=C:/java17
68 GRADLE_SKIP_TASK_OPTIONS="${GRADLE_SKIP_TASK_OPTIONS} -x docker"
robert.tomczyk5fe5de72019-07-22 20:48:58 +010069 SEP=";"
robert.tomczyk8e4e5782022-10-20 14:45:43 +010070 OPTIONAL_KILL_ALL_CMD="${SEP} \
71 exit_code=\$? ${SEP} \
72 (taskkill //F //IM java.exe //T) ${SEP} \
73 exit \${exit_code}
74 "
robert.tomczyk5fe5de72019-07-22 20:48:58 +010075 ;;
76 *)
77 JAVA_BUILD_PATH=/usr/lib/jvm/java-${JAVA_BUILD_VERSION}-openjdk-amd64
78 JAVA_TEST_PATH=/usr/lib/jvm/java-${JAVA_TEST_VERSION}-openjdk-amd64
robert.tomczyk8e4e5782022-10-20 14:45:43 +010079 TEST_JAVA_8_HOME=/usr/lib/jvm/java-8-openjdk-amd64
80 TEST_JAVA_11_HOME=/usr/lib/jvm/java-11-openjdk-amd64/
81 TEST_JAVA_17_HOME=/usr/lib/jvm/java-17-openjdk-amd64/
robert.tomczyk5fe5de72019-07-22 20:48:58 +010082 SEP="&&"
83 ;;
84esac
85
86GRADLE_ARGS=" \
87 -PcompileJVM=${JAVA_BUILD_PATH} \
88 -PcompileJVMVer=${JAVA_BUILD_VERSION} \
89 -PtestJVM=${JAVA_TEST_PATH} \
90 -PtestJVMVer=${JAVA_TEST_VERSION} \
robert.tomczyk8e4e5782022-10-20 14:45:43 +010091 -PtestJava8Home=${TEST_JAVA_8_HOME} \
92 -PtestJava11Home=${TEST_JAVA_11_HOME} \
93 -PtestJava17Home=${TEST_JAVA_17_HOME} \
robert.tomczyk5fe5de72019-07-22 20:48:58 +010094 ${PARALLEL_DUNIT} \
95 ${DUNIT_PARALLEL_FORKS} \
robert.tomczyk5defccb2022-11-09 11:13:49 +000096 ${DOCKER_TESTING_OPTIONS} \
robert.tomczyk5fe5de72019-07-22 20:48:58 +010097 ${DEFAULT_GRADLE_TASK_OPTIONS} \
98 ${GRADLE_SKIP_TASK_OPTIONS} \
99 ${GRADLE_TASK} \
100 ${GRADLE_TASK_OPTIONS} \
101 ${GRADLE_GLOBAL_ARGS}"
102
103EXEC_COMMAND="bash -c 'echo Building with: $SEP \
104 ${JAVA_BUILD_PATH}/bin/java -version $SEP \
105 echo Testing with: $SEP \
106 ${JAVA_TEST_PATH}/bin/java -version $SEP \
107 cd geode $SEP \
108 cp gradlew gradlewStrict $SEP \
109 sed -e 's/JAVA_HOME/GRADLE_JVM/g' -i.bak gradlewStrict $SEP \
robert.tomczyk8e4e5782022-10-20 14:45:43 +0100110 GRADLE_JVM=${JAVA_BUILD_PATH} JAVA_TEST_PATH=${JAVA_TEST_PATH} ./gradlewStrict ${GRADLE_ARGS}'"
robert.tomczyk5fe5de72019-07-22 20:48:58 +0100111echo "${EXEC_COMMAND}"
112eval "${EXEC_COMMAND}"
robert.tomczyk5defccb2022-11-09 11:13:49 +0000113
114# Cleanup
115# Make sure all test containers are stopped and removed when tests are finished
116DOCKER_CONTAINERS=$(sudo docker ps -a -q 2> /dev/null)
117if [ -n "${DOCKER_CONTAINERS}" ]; then
118 docker stop ${DOCKER_CONTAINERS} > /dev/null
119 echo -e "Removing containers with ID:"
120 docker rm ${DOCKER_CONTAINERS}
121fi
122