This is an automated email from the ASF dual-hosted git repository.

philo-he pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/gluten.git


The following commit(s) were added to refs/heads/main by this push:
     new 21f351b388 [MINOR] Use verified Apache Maven distributions (#13669)
21f351b388 is described below

commit 21f351b3888d314436271517674a6c0bda54ddaa
Author: Felipe Pessoto <[email protected]>
AuthorDate: Fri Nov 20 14:49:17 2026 -0800

    [MINOR] Use verified Apache Maven distributions (#13669)
---
 build/mvn | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 67 insertions(+), 13 deletions(-)

diff --git a/build/mvn b/build/mvn
index 8d3c78ad83..81a5a72748 100755
--- a/build/mvn
+++ b/build/mvn
@@ -15,7 +15,11 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-# This script downloads and installs Apache Maven if it's not already installed
+# Use the Maven version pinned in pom.xml, reusing a matching system 
installation
+# or the one under build/.mvn. Otherwise fetch from the Apache CDN with curl or
+# wget, falling back to the Apache archive if the tarball or checksum is 
unavailable.
+# Cached tarballs need only a fresh checksum. Verify SHA-512 with sha512sum or
+# shasum before extraction; a mismatch is an error, not a reason to try 
another source.
 # Usage: build/mvn <maven-args>
 #
 
@@ -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
+        echo "ERROR: SHA-512 checksum verification failed for ${ARCHIVE}" >&2
+        return 1
+    fi
+}
+
 # Read Maven version from pom.xml if not set
 install_mvn() {
     # Get Maven version from pom.xml using grep and sed
@@ -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"
 
         echo "Maven ${VERSION} installed successfully to 
${MVN_DOWNLOAD_DIR}/apache-maven-${VERSION}" >&2
     else


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to