From d0dfa0d8f0214f1673e1f93a88ee0d9c67b41c47 Mon Sep 17 00:00:00 2001 From: wangshun <96341168+xixi-box@users.noreply.github.com> Date: Mon, 30 Nov 2026 20:18:20 +0800 Subject: [PATCH] fix(java): fall back to curl when Maven Wrapper wget fails (#5231) Fixes #5224 The Java beta release job stopped before Maven started. The job log shows that the wrapper cache was empty and wget failed to fetch the Maven distribution. The wrapper exited immediately even when curl was available. [Issue #5224](https://github.com/lancedb/lancedb/issues/5224) Use the existing curl download path when wget fails and curl is installed. Keep wget as the first choice and continue using the same distribution URL, archive validation, and cache. The wrapper still exits with an error if it cannot download the archive. Tests: `python3 -m unittest discover -s ci/tests -p test_maven_wrapper.py -v`. Result: Base: python3 -m unittest discover -s ci/tests -p test_maven_wrapper.py -v exited 1. The fallback regression reproduced the terminal wget error, and the successful-wget case passed. Result: Patched: python3 -m unittest discover -s ci/tests -p test_maven_wrapper.py -v exited 0. Both wrapper tests passed, including the cached invocation in the fallback test. Result: Patched: python3 -m unittest discover -s ci/tests -v exited 0 with Ran 40 tests and OK. Result: Base: (cd java && JAVA_HOME=/usr/lib/jvm/temurin-17-jdk-amd64 ./mvnw --batch-mode test -pl lancedb-core) exited 0 with 37 tests, 0 failures, 0 errors, and 0 skipped. Result: Patched: (cd java && JAVA_HOME=/usr/lib/jvm/temurin-17-jdk-amd64 ./mvnw --batch-mode -Dspotless.skip=true clean test -pl lancedb-core) exited 0 with 37 tests, 0 failures, 0 errors, and 0 skipped. Surefire XML reports are in java/lancedb-core/target/surefire-reports/. Result: Patched: The Temurin 8 cold-cache deployment command in setup_steps exited 0 and reported BUILD SUCCESS for lancedb-parent and lancedb-core after logging 'wget download failed, trying curl'. Both POMs and all three JARs were present in the file repository. Result: Patched: uvx ruff format --check ci/tests/test_maven_wrapper.py, uvx ruff check ci/tests/test_maven_wrapper.py, sh -n java/mvnw, shellcheck java/mvnw, and git diff --check passed. Regression coverage: `ci/tests/test_maven_wrapper.py`. Signed-off-by: wangshun <96341168+xixi-box@users.noreply.github.com> --- ci/tests/test_maven_wrapper.py | 94 ++++++++++++++++++++++++++++++++++ java/mvnw | 16 ++++-- 2 files changed, 106 insertions(+), 4 deletions(-) create mode 100644 ci/tests/test_maven_wrapper.py diff --git a/ci/tests/test_maven_wrapper.py b/ci/tests/test_maven_wrapper.py new file mode 100644 index 000000000..c3cb19f12 --- /dev/null +++ b/ci/tests/test_maven_wrapper.py @@ -0,0 +1,94 @@ +import os +import subprocess +import tempfile +import unittest +import zipfile +from pathlib import Path + +JAVA_DIR = Path(__file__).resolve().parents[2] / "java" +PUBLISH_ARGS = [ + "--batch-mode", + "-DskipTests", + "deploy", + "-pl", + "lancedb-core", + "-am", + "-P", + "deploy-to-fury", +] + + +class MavenWrapperTest(unittest.TestCase): + def setUp(self): + tmp = tempfile.TemporaryDirectory() + self.addCleanup(tmp.cleanup) + workdir = Path(tmp.name) + bin_dir = workdir / "bin" + bin_dir.mkdir() + self.wget = bin_dir / "wget" + self.download_log = workdir / "downloads" + properties = JAVA_DIR / ".mvn/wrapper/maven-wrapper.properties" + url = next( + line.partition("=")[2] + for line in properties.read_text().splitlines() + if line.startswith("distributionUrl=") + ) + artifact_path = url.split("/org/apache/maven/", 1)[1] + mirror = workdir / "mirror" + self.archive = mirror / "org/apache/maven" / artifact_path + self.archive.parent.mkdir(parents=True) + maven_home = self.archive.name.removesuffix("-bin.zip") + launcher = zipfile.ZipInfo(f"{maven_home}/bin/mvn") + launcher.create_system = 3 + launcher.external_attr = 0o100755 << 16 + with zipfile.ZipFile(self.archive, "w") as distribution: + distribution.writestr(launcher, '#!/bin/sh\nprintf "%s\\n" "$@"\n') + self.env = dict( + os.environ, + PATH=f"{bin_dir}{os.pathsep}{os.environ['PATH']}", + MAVEN_USER_HOME=str(workdir / "m2"), + MVNW_REPOURL=mirror.as_uri(), + MVNW_USERNAME="", + MVNW_PASSWORD="", + MVNW_VERBOSE="", + TEST_ARCHIVE=str(self.archive), + TEST_DOWNLOAD_LOG=str(self.download_log), + ) + + def run_wrapper(self, wget_result): + self.wget.write_text( + '#!/bin/sh\necho wget >> "$TEST_DOWNLOAD_LOG"\n' + 'while [ "$1" != -O ]; do shift; done\n' + wget_result + "\n" + ) + self.wget.chmod(0o755) + return subprocess.run( + ["./mvnw", *PUBLISH_ARGS], + check=False, + cwd=JAVA_DIR, + env=self.env, + capture_output=True, + text=True, + timeout=20, + ) + + def test_cold_cache_falls_back_to_curl_after_wget_failure(self): + result = self.run_wrapper('printf partial > "$2"\nexit 8') + self.assertEqual(result.returncode, 0, result.stderr) + self.assertEqual(result.stdout.splitlines(), PUBLISH_ARGS) + self.assertEqual(self.download_log.read_text().splitlines(), ["wget"]) + + self.archive.unlink() + cached = self.run_wrapper("exit 8") + self.assertEqual(cached.returncode, 0, cached.stderr) + self.assertEqual(cached.stdout.splitlines(), PUBLISH_ARGS) + self.assertEqual(self.download_log.read_text().splitlines(), ["wget"]) + + def test_cold_cache_uses_a_successful_wget_download(self): + result = self.run_wrapper('mv "$TEST_ARCHIVE" "$2"') + self.assertEqual(result.returncode, 0, result.stderr) + self.assertEqual(result.stdout.splitlines(), PUBLISH_ARGS) + self.assertEqual(self.download_log.read_text().splitlines(), ["wget"]) + + +if __name__ == "__main__": + unittest.main() diff --git a/java/mvnw b/java/mvnw index 19529ddf8..86ab042d9 100755 --- a/java/mvnw +++ b/java/mvnw @@ -188,12 +188,20 @@ case "${MVNW_PASSWORD:+has-password}" in has-password) [ -n "${MVNW_USERNAME-}" ] || MVNW_USERNAME='' MVNW_PASSWORD='' ;; esac -if [ -z "${MVNW_USERNAME-}" ] && command -v wget >/dev/null; then - verbose "Found wget ... using wget" - wget ${__MVNW_QUIET_WGET:+"$__MVNW_QUIET_WGET"} "$distributionUrl" -O "$TMP_DOWNLOAD_DIR/$distributionUrlName" || die "wget: Failed to fetch $distributionUrl" -elif [ -z "${MVNW_USERNAME-}" ] && command -v curl >/dev/null; then +download_with_curl() { verbose "Found curl ... using curl" curl ${__MVNW_QUIET_CURL:+"$__MVNW_QUIET_CURL"} -f -L -o "$TMP_DOWNLOAD_DIR/$distributionUrlName" "$distributionUrl" || die "curl: Failed to fetch $distributionUrl" +} + +if [ -z "${MVNW_USERNAME-}" ] && command -v wget >/dev/null; then + verbose "Found wget ... using wget" + if ! wget ${__MVNW_QUIET_WGET:+"$__MVNW_QUIET_WGET"} "$distributionUrl" -O "$TMP_DOWNLOAD_DIR/$distributionUrlName"; then + command -v curl >/dev/null || die "wget: Failed to fetch $distributionUrl" + verbose "wget download failed, trying curl" + download_with_curl + fi +elif [ -z "${MVNW_USERNAME-}" ] && command -v curl >/dev/null; then + download_with_curl elif set_java_home; then verbose "Falling back to use Java to download" javaSource="$TMP_DOWNLOAD_DIR/Downloader.java"