felipepessoto commented on code in PR #13669:
URL: https://github.com/apache/gluten/pull/13669#discussion_r4648695899
##########
build/mvn:
##########
@@ -100,32 +130,56 @@ install_mvn() {
echo "Maven ${VERSION} not found locally. Downloading..." >&2
# Create download directory
- mkdir -p "${MVN_DOWNLOAD_DIR}"
+ mkdir -p "${MVN_DOWNLOAD_DIR}" || exit 1
local MVN_TAR="${MVN_DOWNLOAD_DIR}/apache-maven-${VERSION}-bin.tar.gz"
+ local MVN_SHA512="${MVN_TAR}.sha512"
+ local
DISTRIBUTION_PATH="maven/maven-${VERSION%%.*}/${VERSION}/binaries/apache-maven-${VERSION}-bin.tar.gz"
+ local SOURCE DOWNLOAD_URL CHECKSUM_URL VERIFIED=false
+ # A missing checksum is not a reason to discard a pre-existing archive.
+ local DOWNLOAD_FILES=("$MVN_SHA512")
+ if [ ! -f "$MVN_TAR" ]; then
+ DOWNLOAD_FILES+=("$MVN_TAR")
+ fi
- if [ ! -f "${MVN_TAR}" ]; then
- # Use Maven Central repository for download
- local
DOWNLOAD_URL="https://repo1.maven.org/maven2/org/apache/maven/apache-maven/${VERSION}/apache-maven-${VERSION}-bin.tar.gz"
+ for SOURCE in https://dlcdn.apache.org
https://archive.apache.org/dist; do
+ DOWNLOAD_URL="${SOURCE}/${DISTRIBUTION_PATH}"
+ CHECKSUM_URL="${DOWNLOAD_URL}.sha512"
+ if [ "$SOURCE" = https://dlcdn.apache.org ]; then
+
CHECKSUM_URL="https://downloads.apache.org/${DISTRIBUTION_PATH}.sha512"
+ fi
- echo "Downloading Maven ${VERSION} from Maven Central..." >&2
echo "URL: ${DOWNLOAD_URL}" >&2
+ if { [ -f "$MVN_TAR" ] || download_mvn "$DOWNLOAD_URL" "$MVN_TAR";
} &&
+ download_mvn "$CHECKSUM_URL" "$MVN_SHA512"; then
+ if ! verify_mvn "$MVN_TAR" "$MVN_SHA512"; then
+ rm -f "$MVN_TAR" "$MVN_SHA512"
+ exit 1
+ fi
+ VERIFIED=true
+ break
+ fi
- download_mvn "$DOWNLOAD_URL" "$MVN_TAR" || exit 1
+ rm -f "${DOWNLOAD_FILES[@]}"
+ if [ "$SOURCE" = https://dlcdn.apache.org ]; then
+ echo "WARNING: Maven distribution or checksum unavailable;
trying the Apache archive..." >&2
+ fi
+ done
- echo "Download completed successfully" >&2
+ if [ "$VERIFIED" != true ]; then
+ echo "ERROR: Failed to download Maven ${VERSION} and its SHA-512
checksum from Apache." >&2
+ exit 1
fi
- # Extract Maven
+ # GNU tar interprets backslash escapes in -C paths.
echo "Extracting Maven to ${MVN_DOWNLOAD_DIR}..." >&2
- if ! tar -xzf "${MVN_TAR}" -C "${MVN_DOWNLOAD_DIR}"; then
+ if ! (cd "${MVN_DOWNLOAD_DIR}" && tar -xzf "${MVN_TAR##*/}"); then
echo "ERROR: Failed to extract Maven" >&2
- rm -f "${MVN_TAR}"
+ rm -f "$MVN_TAR" "$MVN_SHA512"
exit 1
fi
- # Clean up tar file
- rm -f "${MVN_TAR}"
+ rm -f "$MVN_TAR" "$MVN_SHA512"
Review Comment:
The final cleanup uses the same absolute tarball and checksum paths as the
verification-failure cleanup above. There's no option-like operand here either,
so no change is needed.
##########
build/mvn:
##########
@@ -100,32 +130,56 @@ install_mvn() {
echo "Maven ${VERSION} not found locally. Downloading..." >&2
# Create download directory
- mkdir -p "${MVN_DOWNLOAD_DIR}"
+ mkdir -p "${MVN_DOWNLOAD_DIR}" || exit 1
local MVN_TAR="${MVN_DOWNLOAD_DIR}/apache-maven-${VERSION}-bin.tar.gz"
+ local MVN_SHA512="${MVN_TAR}.sha512"
+ local
DISTRIBUTION_PATH="maven/maven-${VERSION%%.*}/${VERSION}/binaries/apache-maven-${VERSION}-bin.tar.gz"
+ local SOURCE DOWNLOAD_URL CHECKSUM_URL VERIFIED=false
+ # A missing checksum is not a reason to discard a pre-existing archive.
+ local DOWNLOAD_FILES=("$MVN_SHA512")
+ if [ ! -f "$MVN_TAR" ]; then
+ DOWNLOAD_FILES+=("$MVN_TAR")
+ fi
- if [ ! -f "${MVN_TAR}" ]; then
- # Use Maven Central repository for download
- local
DOWNLOAD_URL="https://repo1.maven.org/maven2/org/apache/maven/apache-maven/${VERSION}/apache-maven-${VERSION}-bin.tar.gz"
+ for SOURCE in https://dlcdn.apache.org
https://archive.apache.org/dist; do
+ DOWNLOAD_URL="${SOURCE}/${DISTRIBUTION_PATH}"
+ CHECKSUM_URL="${DOWNLOAD_URL}.sha512"
+ if [ "$SOURCE" = https://dlcdn.apache.org ]; then
+
CHECKSUM_URL="https://downloads.apache.org/${DISTRIBUTION_PATH}.sha512"
+ fi
- echo "Downloading Maven ${VERSION} from Maven Central..." >&2
echo "URL: ${DOWNLOAD_URL}" >&2
+ if { [ -f "$MVN_TAR" ] || download_mvn "$DOWNLOAD_URL" "$MVN_TAR";
} &&
+ download_mvn "$CHECKSUM_URL" "$MVN_SHA512"; then
Review Comment:
Agreed that “Failed to download Maven” is imprecise when only the checksum
fetch fails. The error includes the `.sha512` URL, so the failed resource is
still identifiable. I'd use “Failed to download <URL>” next time we touch this
helper rather than open a follow-up just for the wording.
##########
build/mvn:
##########
@@ -100,32 +130,56 @@ install_mvn() {
echo "Maven ${VERSION} not found locally. Downloading..." >&2
# Create download directory
- mkdir -p "${MVN_DOWNLOAD_DIR}"
+ mkdir -p "${MVN_DOWNLOAD_DIR}" || exit 1
local MVN_TAR="${MVN_DOWNLOAD_DIR}/apache-maven-${VERSION}-bin.tar.gz"
+ local MVN_SHA512="${MVN_TAR}.sha512"
+ local
DISTRIBUTION_PATH="maven/maven-${VERSION%%.*}/${VERSION}/binaries/apache-maven-${VERSION}-bin.tar.gz"
+ local SOURCE DOWNLOAD_URL CHECKSUM_URL VERIFIED=false
+ # A missing checksum is not a reason to discard a pre-existing archive.
+ local DOWNLOAD_FILES=("$MVN_SHA512")
+ if [ ! -f "$MVN_TAR" ]; then
+ DOWNLOAD_FILES+=("$MVN_TAR")
+ fi
- if [ ! -f "${MVN_TAR}" ]; then
- # Use Maven Central repository for download
- local
DOWNLOAD_URL="https://repo1.maven.org/maven2/org/apache/maven/apache-maven/${VERSION}/apache-maven-${VERSION}-bin.tar.gz"
+ for SOURCE in https://dlcdn.apache.org
https://archive.apache.org/dist; do
+ DOWNLOAD_URL="${SOURCE}/${DISTRIBUTION_PATH}"
+ CHECKSUM_URL="${DOWNLOAD_URL}.sha512"
+ if [ "$SOURCE" = https://dlcdn.apache.org ]; then
+
CHECKSUM_URL="https://downloads.apache.org/${DISTRIBUTION_PATH}.sha512"
+ fi
- echo "Downloading Maven ${VERSION} from Maven Central..." >&2
echo "URL: ${DOWNLOAD_URL}" >&2
+ if { [ -f "$MVN_TAR" ] || download_mvn "$DOWNLOAD_URL" "$MVN_TAR";
} &&
+ download_mvn "$CHECKSUM_URL" "$MVN_SHA512"; then
+ if ! verify_mvn "$MVN_TAR" "$MVN_SHA512"; then
+ rm -f "$MVN_TAR" "$MVN_SHA512"
+ exit 1
+ fi
+ VERIFIED=true
+ break
+ fi
- download_mvn "$DOWNLOAD_URL" "$MVN_TAR" || exit 1
+ rm -f "${DOWNLOAD_FILES[@]}"
Review Comment:
`DOWNLOAD_FILES` contains only the absolute checksum path and, for a fresh
download, the absolute tarball path. The quoted array passes each as a separate
operand; neither can start with `-`.
##########
build/mvn:
##########
@@ -100,32 +130,56 @@ install_mvn() {
echo "Maven ${VERSION} not found locally. Downloading..." >&2
# Create download directory
- mkdir -p "${MVN_DOWNLOAD_DIR}"
+ mkdir -p "${MVN_DOWNLOAD_DIR}" || exit 1
local MVN_TAR="${MVN_DOWNLOAD_DIR}/apache-maven-${VERSION}-bin.tar.gz"
+ local MVN_SHA512="${MVN_TAR}.sha512"
+ local
DISTRIBUTION_PATH="maven/maven-${VERSION%%.*}/${VERSION}/binaries/apache-maven-${VERSION}-bin.tar.gz"
+ local SOURCE DOWNLOAD_URL CHECKSUM_URL VERIFIED=false
+ # A missing checksum is not a reason to discard a pre-existing archive.
+ local DOWNLOAD_FILES=("$MVN_SHA512")
+ if [ ! -f "$MVN_TAR" ]; then
+ DOWNLOAD_FILES+=("$MVN_TAR")
+ fi
- if [ ! -f "${MVN_TAR}" ]; then
- # Use Maven Central repository for download
- local
DOWNLOAD_URL="https://repo1.maven.org/maven2/org/apache/maven/apache-maven/${VERSION}/apache-maven-${VERSION}-bin.tar.gz"
+ for SOURCE in https://dlcdn.apache.org
https://archive.apache.org/dist; do
+ DOWNLOAD_URL="${SOURCE}/${DISTRIBUTION_PATH}"
+ CHECKSUM_URL="${DOWNLOAD_URL}.sha512"
+ if [ "$SOURCE" = https://dlcdn.apache.org ]; then
+
CHECKSUM_URL="https://downloads.apache.org/${DISTRIBUTION_PATH}.sha512"
+ fi
- echo "Downloading Maven ${VERSION} from Maven Central..." >&2
echo "URL: ${DOWNLOAD_URL}" >&2
+ if { [ -f "$MVN_TAR" ] || download_mvn "$DOWNLOAD_URL" "$MVN_TAR";
} &&
+ download_mvn "$CHECKSUM_URL" "$MVN_SHA512"; then
+ if ! verify_mvn "$MVN_TAR" "$MVN_SHA512"; then
+ rm -f "$MVN_TAR" "$MVN_SHA512"
+ exit 1
+ fi
+ VERIFIED=true
+ break
+ fi
- download_mvn "$DOWNLOAD_URL" "$MVN_TAR" || exit 1
+ rm -f "${DOWNLOAD_FILES[@]}"
+ if [ "$SOURCE" = https://dlcdn.apache.org ]; then
+ echo "WARNING: Maven distribution or checksum unavailable;
trying the Apache archive..." >&2
+ fi
+ done
- echo "Download completed successfully" >&2
+ if [ "$VERIFIED" != true ]; then
+ echo "ERROR: Failed to download Maven ${VERSION} and its SHA-512
checksum from Apache." >&2
+ exit 1
fi
- # Extract Maven
+ # GNU tar interprets backslash escapes in -C paths.
echo "Extracting Maven to ${MVN_DOWNLOAD_DIR}..." >&2
- if ! tar -xzf "${MVN_TAR}" -C "${MVN_DOWNLOAD_DIR}"; then
+ if ! (cd "${MVN_DOWNLOAD_DIR}" && tar -xzf "${MVN_TAR##*/}"); then
echo "ERROR: Failed to extract Maven" >&2
- rm -f "${MVN_TAR}"
+ rm -f "$MVN_TAR" "$MVN_SHA512"
Review Comment:
Here `-f` takes the next argument as the archive filename. I checked GNU
tar: inserting `--` immediately after `-xzf` makes it try to open an archive
named `--`. The existing command supplies the `apache-maven-…` basename
directly, and the cleanup below uses absolute paths.
##########
build/mvn:
##########
@@ -100,32 +130,56 @@ install_mvn() {
echo "Maven ${VERSION} not found locally. Downloading..." >&2
# Create download directory
- mkdir -p "${MVN_DOWNLOAD_DIR}"
+ mkdir -p "${MVN_DOWNLOAD_DIR}" || exit 1
local MVN_TAR="${MVN_DOWNLOAD_DIR}/apache-maven-${VERSION}-bin.tar.gz"
+ local MVN_SHA512="${MVN_TAR}.sha512"
+ local
DISTRIBUTION_PATH="maven/maven-${VERSION%%.*}/${VERSION}/binaries/apache-maven-${VERSION}-bin.tar.gz"
+ local SOURCE DOWNLOAD_URL CHECKSUM_URL VERIFIED=false
+ # A missing checksum is not a reason to discard a pre-existing archive.
+ local DOWNLOAD_FILES=("$MVN_SHA512")
+ if [ ! -f "$MVN_TAR" ]; then
+ DOWNLOAD_FILES+=("$MVN_TAR")
+ fi
- if [ ! -f "${MVN_TAR}" ]; then
- # Use Maven Central repository for download
- local
DOWNLOAD_URL="https://repo1.maven.org/maven2/org/apache/maven/apache-maven/${VERSION}/apache-maven-${VERSION}-bin.tar.gz"
+ for SOURCE in https://dlcdn.apache.org
https://archive.apache.org/dist; do
+ DOWNLOAD_URL="${SOURCE}/${DISTRIBUTION_PATH}"
+ CHECKSUM_URL="${DOWNLOAD_URL}.sha512"
+ if [ "$SOURCE" = https://dlcdn.apache.org ]; then
+
CHECKSUM_URL="https://downloads.apache.org/${DISTRIBUTION_PATH}.sha512"
+ fi
- echo "Downloading Maven ${VERSION} from Maven Central..." >&2
echo "URL: ${DOWNLOAD_URL}" >&2
+ if { [ -f "$MVN_TAR" ] || download_mvn "$DOWNLOAD_URL" "$MVN_TAR";
} &&
+ download_mvn "$CHECKSUM_URL" "$MVN_SHA512"; then
+ if ! verify_mvn "$MVN_TAR" "$MVN_SHA512"; then
+ rm -f "$MVN_TAR" "$MVN_SHA512"
Review Comment:
Both paths passed to `rm` here are built from the absolute
`MVN_DOWNLOAD_DIR`. Even if a checkout directory name starts with `-`, each
operand still starts with `/`, so neither is parsed as an option.
##########
build/mvn:
##########
@@ -67,6 +71,32 @@ download_mvn() {
return 1
}
+verify_mvn() {
+ local ARCHIVE="$1" CHECKSUM_FILE="$2" CHECKSUM
+ local SHA512
+ if command -v sha512sum > /dev/null 2>&1; then
+ SHA512=(sha512sum)
+ elif command -v shasum > /dev/null 2>&1; then
+ SHA512=(shasum -a 512)
+ else
+ echo "ERROR: Neither sha512sum nor shasum found. Install one to verify
the Maven distribution." >&2
+ return 1
+ fi
+
+ # Apache publishes a bare SHA-512 digest, not a checksum-tool manifest.
+ if ! CHECKSUM=$(tr -d '[:space:]' < "$CHECKSUM_FILE") ||
+ ! [[ "$CHECKSUM" =~ ^[0-9a-fA-F]{128}$ ]]; then
+ echo "ERROR: Invalid SHA-512 checksum in ${CHECKSUM_FILE}" >&2
+ return 1
+ fi
+ # Keep checkout paths out of the line-based checksum manifest.
+ if ! printf '%s %s\n' "$CHECKSUM" "${ARCHIVE##*/}" |
+ (cd "${ARCHIVE%/*}" && "${SHA512[@]}" -c -) >&2; then
Review Comment:
That expansion would fail for a bare filename. The only caller passes
`MVN_TAR`, an absolute path under `build/.mvn`, so it can't happen in the
wrapper today. I'd add bare-filename support if a caller actually needs it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]