[KYUUBI #4278] Use new Apache 'closer.lua' syntax to obtain Maven

### _Why are the changes needed?_

Use official download link and provide a way to fallback.

- Doc reference: https://infra.apache.org/release-download-pages.html#download-scripts

### _How was this patch tested?_
- [ ] Add some test cases that check the changes thoroughly including negative and positive cases if possible

- [ ] Add screenshots for manual tests if appropriate

- [x] [Run test](https://kyuubi.readthedocs.io/en/master/develop_tools/testing.html#running-tests) locally before make a pull request

```shell
build/mvn compile
exec: curl --progress-bar -L https://www.apache.org/dyn/closer.lua/maven/maven-3/3.8.7/binaries/apache-maven-3.8.7-bin.tar.gz?action=download
```

Closes #4704 from yaooqinn/4278.

Closes #4278

27a1fc284 [Kent Yao] [KYUUBI #4278] Use new Apache 'closer.lua' syntax to obtain Maven

Authored-by: Kent Yao <yao@apache.org>
Signed-off-by: Cheng Pan <chengpan@apache.org>
This commit is contained in:
Kent Yao 2023-04-13 23:26:15 +08:00 committed by Cheng Pan
parent 52251ddae2
commit 1603342de3
No known key found for this signature in database
GPG Key ID: 8001952629BCC75D

View File

@ -35,7 +35,7 @@ fi
## Arg2 - Tarball Name
## Arg3 - Checkable Binary
install_app() {
local remote_tarball="$1/$2"
local remote_tarball="$1/$2$4"
local local_tarball="${_DIR}/$2"
local binary="${_DIR}/$3"
@ -77,12 +77,25 @@ install_mvn() {
# See simple version normalization: http://stackoverflow.com/questions/16989598/bash-comparing-version-numbers
function version { echo "$@" | awk -F. '{ printf("%03d%03d%03d\n", $1,$2,$3); }'; }
if [ $(version $MVN_DETECTED_VERSION) -ne $(version $MVN_VERSION) ]; then
local APACHE_MIRROR=${APACHE_MIRROR:-'https://archive.apache.org/dist/'}
local APACHE_MIRROR=${APACHE_MIRROR:-'https://www.apache.org/dyn/closer.lua'}
local MIRROR_URL_QUERY="?action=download"
local MVN_TARBALL="apache-maven-${MVN_VERSION}-bin.tar.gz"
local FILE_PATH="maven/maven-3/${MVN_VERSION}/binaries"
if [ $(command -v curl) ]; then
if ! curl -L --output /dev/null --silent --head --fail "${APACHE_MIRROR}/${FILE_PATH}/${MVN_TARBALL}${MIRROR_URL_QUERY}" ; then
# Fall back to archive.apache.org for older Maven
echo "Falling back to archive.apache.org to download Maven"
APACHE_MIRROR="https://archive.apache.org/dist"
MIRROR_URL_QUERY=""
fi
fi
install_app \
"${APACHE_MIRROR}/maven/maven-3/${MVN_VERSION}/binaries" \
"apache-maven-${MVN_VERSION}-bin.tar.gz" \
"apache-maven-${MVN_VERSION}/bin/mvn"
"${APACHE_MIRROR}/${FILE_PATH}" \
"${MVN_TARBALL}" \
"apache-maven-${MVN_VERSION}/bin/mvn" \
"${MIRROR_URL_QUERY}"
MVN_BIN="${_DIR}/apache-maven-${MVN_VERSION}/bin/mvn"
fi