robert.tomczyk | 5fe5de7 | 2019-07-22 20:48:58 +0100 | [diff] [blame] | 1 | #!/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 | |
| 19 | set -e |
| 20 | |
| 21 | BASE_DIR=$(pwd) |
| 22 | |
| 23 | SOURCE="${BASH_SOURCE[0]}" |
| 24 | while [ -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 |
| 28 | done |
| 29 | SCRIPTDIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" |
| 30 | |
| 31 | if [[ -z "${GRADLE_TASK}" ]]; then |
| 32 | echo "GRADLE_TASK must be set. exiting..." |
| 33 | exit 1 |
| 34 | fi |
| 35 | |
| 36 | REPODIR=$(cd geode; git rev-parse --show-toplevel) |
| 37 | |
| 38 | if [[ ${PARALLEL_GRADLE:-"true"} == "true" ]]; then |
| 39 | PARALLEL_GRADLE="--parallel" |
| 40 | else |
| 41 | PARALLEL_GRADLE="--no-parallel" |
| 42 | fi |
| 43 | DEFAULT_GRADLE_TASK_OPTIONS="${PARALLEL_GRADLE} --console=plain --no-daemon" |
| 44 | GRADLE_SKIP_TASK_OPTIONS="-x javadoc -x spotlessCheck -x rat" |
| 45 | |
| 46 | if [[ -n "${PARALLEL_DUNIT}" && "${PARALLEL_DUNIT}" == "true" ]]; then |
robert.tomczyk | 8e4e578 | 2022-10-20 14:45:43 +0100 | [diff] [blame] | 47 | PARALLEL_DUNIT="-PparallelDunit" |
robert.tomczyk | 5defccb | 2022-11-09 11:13:49 +0000 | [diff] [blame] | 48 | if [[ -n "${DUNIT_PARALLEL_FORKS}" && "${TEST_USING_DOCKER}" == "false" ]] ; then |
robert.tomczyk | 8e4e578 | 2022-10-20 14:45:43 +0100 | [diff] [blame] | 49 | DUNIT_PARALLEL_FORKS="--max-workers=${DUNIT_PARALLEL_FORKS} -PtestMaxParallelForks=${DUNIT_PARALLEL_FORKS} -PdunitParallelForks=${DUNIT_PARALLEL_FORKS}" |
robert.tomczyk | 5defccb | 2022-11-09 11:13:49 +0000 | [diff] [blame] | 50 | 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.tomczyk | 5fe5de7 | 2019-07-22 20:48:58 +0100 | [diff] [blame] | 53 | fi |
| 54 | else |
| 55 | PARALLEL_DUNIT="" |
| 56 | DUNIT_PARALLEL_FORKS="" |
robert.tomczyk | 5defccb | 2022-11-09 11:13:49 +0000 | [diff] [blame] | 57 | DOCKER_TESTING_OPTIONS="" |
robert.tomczyk | 5fe5de7 | 2019-07-22 20:48:58 +0100 | [diff] [blame] | 58 | fi |
| 59 | |
| 60 | case $ARTIFACT_SLUG in |
| 61 | windows*) |
robert.tomczyk | 8e4e578 | 2022-10-20 14:45:43 +0100 | [diff] [blame] | 62 | echo "Making environment adjustments for windows." |
robert.tomczyk | 5fe5de7 | 2019-07-22 20:48:58 +0100 | [diff] [blame] | 63 | JAVA_BUILD_PATH=C:/java${JAVA_BUILD_VERSION} |
| 64 | JAVA_TEST_PATH=C:/java${JAVA_TEST_VERSION} |
robert.tomczyk | 8e4e578 | 2022-10-20 14:45:43 +0100 | [diff] [blame] | 65 | 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.tomczyk | 5fe5de7 | 2019-07-22 20:48:58 +0100 | [diff] [blame] | 69 | SEP=";" |
robert.tomczyk | 8e4e578 | 2022-10-20 14:45:43 +0100 | [diff] [blame] | 70 | OPTIONAL_KILL_ALL_CMD="${SEP} \ |
| 71 | exit_code=\$? ${SEP} \ |
| 72 | (taskkill //F //IM java.exe //T) ${SEP} \ |
| 73 | exit \${exit_code} |
| 74 | " |
robert.tomczyk | 5fe5de7 | 2019-07-22 20:48:58 +0100 | [diff] [blame] | 75 | ;; |
| 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.tomczyk | 8e4e578 | 2022-10-20 14:45:43 +0100 | [diff] [blame] | 79 | 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.tomczyk | 5fe5de7 | 2019-07-22 20:48:58 +0100 | [diff] [blame] | 82 | SEP="&&" |
| 83 | ;; |
| 84 | esac |
| 85 | |
| 86 | GRADLE_ARGS=" \ |
| 87 | -PcompileJVM=${JAVA_BUILD_PATH} \ |
| 88 | -PcompileJVMVer=${JAVA_BUILD_VERSION} \ |
| 89 | -PtestJVM=${JAVA_TEST_PATH} \ |
| 90 | -PtestJVMVer=${JAVA_TEST_VERSION} \ |
robert.tomczyk | 8e4e578 | 2022-10-20 14:45:43 +0100 | [diff] [blame] | 91 | -PtestJava8Home=${TEST_JAVA_8_HOME} \ |
| 92 | -PtestJava11Home=${TEST_JAVA_11_HOME} \ |
| 93 | -PtestJava17Home=${TEST_JAVA_17_HOME} \ |
robert.tomczyk | 5fe5de7 | 2019-07-22 20:48:58 +0100 | [diff] [blame] | 94 | ${PARALLEL_DUNIT} \ |
| 95 | ${DUNIT_PARALLEL_FORKS} \ |
robert.tomczyk | 5defccb | 2022-11-09 11:13:49 +0000 | [diff] [blame] | 96 | ${DOCKER_TESTING_OPTIONS} \ |
robert.tomczyk | 5fe5de7 | 2019-07-22 20:48:58 +0100 | [diff] [blame] | 97 | ${DEFAULT_GRADLE_TASK_OPTIONS} \ |
| 98 | ${GRADLE_SKIP_TASK_OPTIONS} \ |
| 99 | ${GRADLE_TASK} \ |
| 100 | ${GRADLE_TASK_OPTIONS} \ |
| 101 | ${GRADLE_GLOBAL_ARGS}" |
| 102 | |
| 103 | EXEC_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.tomczyk | 8e4e578 | 2022-10-20 14:45:43 +0100 | [diff] [blame] | 110 | GRADLE_JVM=${JAVA_BUILD_PATH} JAVA_TEST_PATH=${JAVA_TEST_PATH} ./gradlewStrict ${GRADLE_ARGS}'" |
robert.tomczyk | 5fe5de7 | 2019-07-22 20:48:58 +0100 | [diff] [blame] | 111 | echo "${EXEC_COMMAND}" |
| 112 | eval "${EXEC_COMMAND}" |
robert.tomczyk | 5defccb | 2022-11-09 11:13:49 +0000 | [diff] [blame] | 113 | |
| 114 | # Cleanup |
| 115 | # Make sure all test containers are stopped and removed when tests are finished |
| 116 | DOCKER_CONTAINERS=$(sudo docker ps -a -q 2> /dev/null) |
| 117 | if [ -n "${DOCKER_CONTAINERS}" ]; then |
| 118 | docker stop ${DOCKER_CONTAINERS} > /dev/null |
| 119 | echo -e "Removing containers with ID:" |
| 120 | docker rm ${DOCKER_CONTAINERS} |
| 121 | fi |
| 122 | |