From 8f95ee99b7bb9e92e58b71a6972954686120a650 Mon Sep 17 00:00:00 2001 From: Tamas Cservenak Date: Wed, 17 Apr 2024 20:21:07 +0200 Subject: [PATCH] [MWRAPPER-108] Emit clear error message when download fails on U*IX (#130) Script silently just failed. Reused changes from dead PR https://github.com/apache/maven-wrapper/pull/98 w/ help of @michael-o :+1: Thanks both! --- https://issues.apache.org/jira/browse/MWRAPPER-108 --- .../src/resources/only-mvnw | 10 +-- .../type_only-script-fail/invoker.properties | 18 +++++ .../it/projects/type_only-script-fail/pom.xml | 68 +++++++++++++++++++ .../type_only-script-fail/test.properties | 19 ++++++ .../type_only-script-fail/verify.groovy | 31 +++++++++ 5 files changed, 141 insertions(+), 5 deletions(-) create mode 100644 maven-wrapper-plugin/src/it/projects/type_only-script-fail/invoker.properties create mode 100644 maven-wrapper-plugin/src/it/projects/type_only-script-fail/pom.xml create mode 100644 maven-wrapper-plugin/src/it/projects/type_only-script-fail/test.properties create mode 100644 maven-wrapper-plugin/src/it/projects/type_only-script-fail/verify.groovy diff --git a/maven-wrapper-distribution/src/resources/only-mvnw b/maven-wrapper-distribution/src/resources/only-mvnw index 6620a5cb..60c16626 100755 --- a/maven-wrapper-distribution/src/resources/only-mvnw +++ b/maven-wrapper-distribution/src/resources/only-mvnw @@ -181,10 +181,10 @@ 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" + 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 verbose "Found curl ... using curl" - curl ${__MVNW_QUIET_CURL:+"$__MVNW_QUIET_CURL"} -f -L -o "$TMP_DOWNLOAD_DIR/$distributionUrlName" "$distributionUrl" + curl ${__MVNW_QUIET_CURL:+"$__MVNW_QUIET_CURL"} -f -L -o "$TMP_DOWNLOAD_DIR/$distributionUrlName" "$distributionUrl" || die "curl: Failed to fetch $distributionUrl" elif set_java_home; then verbose "Falling back to use Java to download" javaSource="$TMP_DOWNLOAD_DIR/Downloader.java" @@ -205,7 +205,7 @@ elif set_java_home; then END # For Cygwin/MinGW, switch paths to Windows format before running javac and java verbose " - Compiling Downloader.java ..." - "$(native_path "$JAVACCMD")" "$(native_path "$javaSource")" + "$(native_path "$JAVACCMD")" "$(native_path "$javaSource")" || die "Failed to compile Downloader.java" verbose " - Running Downloader.java ..." "$(native_path "$JAVACMD")" -cp "$(native_path "$TMP_DOWNLOAD_DIR")" Downloader "$distributionUrl" "$(native_path "$targetZip")" fi @@ -239,9 +239,9 @@ fi # unzip and move if command -v unzip >/dev/null; then - unzip ${__MVNW_QUIET_UNZIP:+"$__MVNW_QUIET_UNZIP"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -d "$TMP_DOWNLOAD_DIR" + unzip ${__MVNW_QUIET_UNZIP:+"$__MVNW_QUIET_UNZIP"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -d "$TMP_DOWNLOAD_DIR" || die "failed to unzip" else - tar xzf${__MVNW_QUIET_TAR:+"$__MVNW_QUIET_TAR"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -C "$TMP_DOWNLOAD_DIR" + tar xzf${__MVNW_QUIET_TAR:+"$__MVNW_QUIET_TAR"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -C "$TMP_DOWNLOAD_DIR" || die "failed to untar" fi printf %s\\n "$distributionUrl" >"$TMP_DOWNLOAD_DIR/$distributionUrlNameMain/mvnw.url" mv -- "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" "$MAVEN_HOME" || [ -d "$MAVEN_HOME" ] || die "fail to move MAVEN_HOME" diff --git a/maven-wrapper-plugin/src/it/projects/type_only-script-fail/invoker.properties b/maven-wrapper-plugin/src/it/projects/type_only-script-fail/invoker.properties new file mode 100644 index 00000000..e64d99e0 --- /dev/null +++ b/maven-wrapper-plugin/src/it/projects/type_only-script-fail/invoker.properties @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +invoker.buildResult = failure diff --git a/maven-wrapper-plugin/src/it/projects/type_only-script-fail/pom.xml b/maven-wrapper-plugin/src/it/projects/type_only-script-fail/pom.xml new file mode 100644 index 00000000..9cbffc72 --- /dev/null +++ b/maven-wrapper-plugin/src/it/projects/type_only-script-fail/pom.xml @@ -0,0 +1,68 @@ + + + + + + 4.0.0 + + org.apache.maven.plugins.it.wrapper + extension + 1.0.0-SNAPSHOT + pom + + + + + + + + + + org.codehaus.mojo + exec-maven-plugin + 3.0.0 + + mvnw${cmd} + + -v + + + true + ${project.build.directory} + ${project.build.directory} + + + + + + + + + + windows + + windows + + + .cmd + + + + diff --git a/maven-wrapper-plugin/src/it/projects/type_only-script-fail/test.properties b/maven-wrapper-plugin/src/it/projects/type_only-script-fail/test.properties new file mode 100644 index 00000000..725ecf89 --- /dev/null +++ b/maven-wrapper-plugin/src/it/projects/type_only-script-fail/test.properties @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +type=only-script +maven=0.0.0 \ No newline at end of file diff --git a/maven-wrapper-plugin/src/it/projects/type_only-script-fail/verify.groovy b/maven-wrapper-plugin/src/it/projects/type_only-script-fail/verify.groovy new file mode 100644 index 00000000..8bcdfbfa --- /dev/null +++ b/maven-wrapper-plugin/src/it/projects/type_only-script-fail/verify.groovy @@ -0,0 +1,31 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +log = new File(basedir, 'build.log').text +boolean isWindows = System.getProperty('os.name', 'unknown').startsWith('Windows') + +if (isWindows) { + // on Windows: just the fact it failed is enough + assert log.contains('Exception calling "DownloadFile"') +} else { + // on non-Windows: verify clear messages as well + // cover all methods: point is, there is no Maven version 0.0.0 + assert log.contains('wget: Failed to fetch') || log.contains('curl: Failed to fetch') || log.contains('- Error downloading:') +}