felipepessoto commented on code in PR #13669:
URL: https://github.com/apache/gluten/pull/13669#discussion_r4647052550
##########
build/mvn:
##########
@@ -27,6 +27,56 @@ MVN_DOWNLOAD_DIR="${DOWNLOAD_DIR}/.mvn"
# Global variable for Maven binary path
MVN_BIN=""
+download_mvn() {
+ local URL="$1" DESTINATION="$2"
+ if command -v curl > /dev/null 2>&1; then
+ if curl -f -L --retry 3 --retry-delay 3 \
+ --connect-timeout 30 --max-time 600 \
+ -o "$DESTINATION" "$URL"; then
+ return 0
+ fi
+ elif command -v wget > /dev/null 2>&1; then
+ if wget --tries=3 --waitretry=3 \
+ --connect-timeout=30 --read-timeout=600 \
+ -O "$DESTINATION" "$URL"; then
+ return 0
+ fi
+ else
+ echo "ERROR: Neither curl nor wget found. Please install one of them
or install Maven manually." >&2
+ return 1
+ fi
+
+ echo "ERROR: Failed to download Maven from ${URL}" >&2
+ rm -f "$DESTINATION"
+ 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:
A filename without a slash would behave that way, but the wrapper never
passes one. `verify_mvn` has one caller, and it builds `MVN_TAR` under
`${GLUTEN_HOME}/build/.mvn` with `GLUTEN_HOME` set by `pwd`. There's no
relative-path input to handle here.
##########
build/mvn:
##########
@@ -27,6 +27,56 @@ MVN_DOWNLOAD_DIR="${DOWNLOAD_DIR}/.mvn"
# Global variable for Maven binary path
MVN_BIN=""
+download_mvn() {
+ local URL="$1" DESTINATION="$2"
+ if command -v curl > /dev/null 2>&1; then
+ if curl -f -L --retry 3 --retry-delay 3 \
+ --connect-timeout 30 --max-time 600 \
+ -o "$DESTINATION" "$URL"; then
+ return 0
+ fi
+ elif command -v wget > /dev/null 2>&1; then
+ if wget --tries=3 --waitretry=3 \
+ --connect-timeout=30 --read-timeout=600 \
+ -O "$DESTINATION" "$URL"; then
+ return 0
+ fi
+ else
+ echo "ERROR: Neither curl nor wget found. Please install one of them
or install Maven manually." >&2
+ return 1
+ fi
+
+ echo "ERROR: Failed to download Maven from ${URL}" >&2
+ rm -f "$DESTINATION"
+ 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
Review Comment:
Both official `.sha512` files for the pinned Maven 3.9.16 binary (release
and archive) return a bare 128-character digest. I'd keep the parser strict
rather than take the first digest from arbitrary text: in a manifest it could
belong to another file. If a future pinned release uses a manifest, we can
support that format by matching the exact archive name.
##########
build/mvn:
##########
@@ -60,51 +110,51 @@ 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
+
+ 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
- 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"
-
- echo "Downloading Maven ${VERSION} from Maven Central..." >&2
echo "URL: ${DOWNLOAD_URL}" >&2
-
- if command -v curl > /dev/null 2>&1; then
- curl -f -L --retry 3 --retry-delay 3 \
- --connect-timeout 30 --max-time 600 \
- -o "${MVN_TAR}" "${DOWNLOAD_URL}" || {
- echo "ERROR: Failed to download Maven from
${DOWNLOAD_URL}" >&2
- rm -f "${MVN_TAR}"
- exit 1
- }
- elif command -v wget > /dev/null 2>&1; then
- wget --tries=3 --waitretry=3 \
- --connect-timeout=30 --read-timeout=600 \
- -O "${MVN_TAR}" "${DOWNLOAD_URL}" || {
- echo "ERROR: Failed to download Maven from
${DOWNLOAD_URL}" >&2
- rm -f "${MVN_TAR}"
+ 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
- }
- else
- echo "ERROR: Neither curl nor wget found. Please install one
of them or install Maven manually." >&2
- exit 1
+ fi
+ VERIFIED=true
+ break
fi
- echo "Download completed successfully" >&2
+ rm -f "$MVN_TAR" "$MVN_SHA512"
Review Comment:
Fixed in 725a3378a. If the release checksum is unavailable, the wrapper
keeps a pre-existing tarball and requests only its checksum from the Apache
archive. If neither source has a checksum, Maven is not installed; if the
checksum is invalid or doesn't match, the tarball is rejected. The offline
regression now supplies only the fallback checksum and refuses any tarball
download.
--
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]