|
| 1 | +# |
| 2 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 3 | +# or more contributor license agreements. See the NOTICE file |
| 4 | +# distributed with this work for additional information |
| 5 | +# regarding copyright ownership. The ASF licenses this file |
| 6 | +# to you under the Apache License, Version 2.0 (the |
| 7 | +# "License"); you may not use this file except in compliance |
| 8 | +# with the License. You may obtain a copy of the License at |
| 9 | +# |
| 10 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +# |
| 12 | +# Unless required by applicable law or agreed to in writing, |
| 13 | +# software distributed under the License is distributed on an |
| 14 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | +# KIND, either express or implied. See the License for the |
| 16 | +# specific language governing permissions and limitations |
| 17 | +# under the License. |
| 18 | + |
| 19 | +# Downloads the gradle-wrapper.jar if necessary and verifies its integrity. |
| 20 | +# Included from /.gradlew |
| 21 | + |
| 22 | +# Extract the Gradle version from gradle-wrapper.properties. |
| 23 | +GRADLE_DIST_VERSION="$(grep distributionUrl= "$APP_HOME/gradle/wrapper/gradle-wrapper.properties" | sed 's/^.*gradle-\([0-9.]*\)-[a-z]*.zip$/\1/')" |
| 24 | +GRADLE_WRAPPER_SHA256="$APP_HOME/gradle/wrapper/gradle-wrapper-${GRADLE_DIST_VERSION}.jar.sha256" |
| 25 | +GRADLE_WRAPPER_JAR="$APP_HOME/gradle/wrapper/gradle-wrapper.jar" |
| 26 | +if [ -x "$(command -v sha256sum)" ] ; then |
| 27 | + SHASUM="sha256sum" |
| 28 | +else |
| 29 | + if [ -x "$(command -v shasum)" ] ; then |
| 30 | + SHASUM="shasum -a 256" |
| 31 | + else |
| 32 | + echo "Neither sha256sum nor shasum are available, install either." > /dev/stderr |
| 33 | + exit 1 |
| 34 | + fi |
| 35 | +fi |
| 36 | +if [ ! -e "${GRADLE_WRAPPER_SHA256}" ]; then |
| 37 | + # Delete the wrapper jar, if the checksum file does not exist. |
| 38 | + rm -f "${GRADLE_WRAPPER_JAR}" |
| 39 | +fi |
| 40 | +if [ -e "${GRADLE_WRAPPER_JAR}" ]; then |
| 41 | + # Verify the wrapper jar, if it exists, delete wrapper jar and checksum file, if the checksums |
| 42 | + # do not match. |
| 43 | + JAR_CHECKSUM="$(${SHASUM} "${GRADLE_WRAPPER_JAR}" | cut -d\ -f1)" |
| 44 | + EXPECTED="$(cat "${GRADLE_WRAPPER_SHA256}")" |
| 45 | + if [ "${JAR_CHECKSUM}" != "${EXPECTED}" ]; then |
| 46 | + rm -f "${GRADLE_WRAPPER_JAR}" "${GRADLE_WRAPPER_SHA256}" |
| 47 | + fi |
| 48 | +fi |
| 49 | +if [ ! -e "${GRADLE_WRAPPER_SHA256}" ]; then |
| 50 | + curl --location --output "${GRADLE_WRAPPER_SHA256}" https://services.gradle.org/distributions/gradle-${GRADLE_DIST_VERSION}-wrapper.jar.sha256 || exit 1 |
| 51 | +fi |
| 52 | +if [ ! -e "${GRADLE_WRAPPER_JAR}" ]; then |
| 53 | + # The Gradle version extracted from the `distributionUrl` property does not contain ".0" patch |
| 54 | + # versions. Need to append a ".0" in that case to download the wrapper jar. |
| 55 | + GRADLE_VERSION="$(echo "$GRADLE_DIST_VERSION" | sed 's/^\([0-9]*[.][0-9]*\)$/\1.0/')" |
| 56 | + curl --location --output "${GRADLE_WRAPPER_JAR}" https://raw.githubusercontent.com/gradle/gradle/v${GRADLE_VERSION}/gradle/wrapper/gradle-wrapper.jar || exit 1 |
| 57 | + JAR_CHECKSUM="$(${SHASUM} "${GRADLE_WRAPPER_JAR}" | cut -d\ -f1)" |
| 58 | + EXPECTED="$(cat "${GRADLE_WRAPPER_SHA256}")" |
| 59 | + if [ "${JAR_CHECKSUM}" != "${EXPECTED}" ]; then |
| 60 | + # If the (just downloaded) checksum and the downloaded wrapper jar do not match, something |
| 61 | + # really bad is going on. |
| 62 | + echo "Expected sha256 of the downloaded gradle-wrapper.jar does not match the downloaded sha256!" > /dev/stderr |
| 63 | + exit 1 |
| 64 | + fi |
| 65 | +fi |
0 commit comments