This is an automated email from the ASF dual-hosted git repository.
sjaranowski pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-wrapper.git
The following commit(s) were added to refs/heads/master by this push:
new 8524c56 [MWRAPPER-80] support maven-mvnd (#65)
8524c56 is described below
commit 8524c56a8f254af23657bc00f1f509882af9c788
Author: James Z.M. Gao <[email protected]>
AuthorDate: Fri Feb 24 01:25:03 2023 +0800
[MWRAPPER-80] support maven-mvnd (#65)
---
maven-wrapper-distribution/src/resources/only-mvnw | 64 ++++++++++++++------
.../src/resources/only-mvnw.cmd | 41 ++++++++-----
.../src/it/projects/test_mvnd/pom.xml | 68 ++++++++++++++++++++++
.../src/it/projects/test_mvnd/test.properties | 19 ++++++
.../src/it/projects/test_mvnd/verify.groovy | 44 ++++++++++++++
.../apache/maven/plugins/wrapper/WrapperMojo.java | 19 ++++++
6 files changed, 223 insertions(+), 32 deletions(-)
diff --git a/maven-wrapper-distribution/src/resources/only-mvnw
b/maven-wrapper-distribution/src/resources/only-mvnw
index 7e173d6..cc90862 100755
--- a/maven-wrapper-distribution/src/resources/only-mvnw
+++ b/maven-wrapper-distribution/src/resources/only-mvnw
@@ -86,32 +86,55 @@ die() {
exit 1
}
-# calculate distributionUrl and get optional distributionSha256Sum, requires
.mvn/wrapper/maven-wrapper.properties
-distributionSha256Sum=""
+# parse distributionUrl and optional distributionSha256Sum, requires
.mvn/wrapper/maven-wrapper.properties
while IFS="=" read -r key value; do
- case "$key" in
- distributionUrl) distributionUrl="${value:-$distributionUrl}";;
- distributionSha256Sum)
distributionSha256Sum="${value:-distributionSha256Sum}";;
+ case "${key-}" in
+ distributionUrl) distributionUrl="${value-}" ;;
+ distributionSha256Sum) distributionSha256Sum="${value-}" ;;
esac
done < "${0%/*}/.mvn/wrapper/maven-wrapper.properties"
[ -n "${distributionUrl-}" ] || die "cannot read distributionUrl property in
${0%/*}/.mvn/wrapper/maven-wrapper.properties"
-[ -z "${MVNW_REPOURL-}" ] ||
distributionUrl="$MVNW_REPOURL/org/apache/maven/${distributionUrl#*/org/apache/maven/}"
-# calculate MAVEN_HOME, pattern
~/.m2/wrapper/dists/apache-maven-<version>/<hash>
+
+case "${distributionUrl##*/}" in
+(maven-mvnd-*bin.*)
+ MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/
+ case "${PROCESSOR_ARCHITECTURE-}${PROCESSOR_ARCHITEW6432-}:$(uname -a)" in
+ (*AMD64:CYGWIN*|*AMD64:MINGW*) distributionPlatform=windows-amd64 ;;
+ (:Darwin*x86_64) distributionPlatform=darwin-amd64 ;;
+ (:Darwin*arm64) distributionPlatform=darwin-aarch64 ;;
+ (:Linux*x86_64*) distributionPlatform=linux-amd64 ;;
+ (*) echo "Cannot detect native platform for mvnd on $(uname)-$(uname -m),
use pure java version" >&2
+ distributionPlatform=linux-amd64
+ ;;
+ esac
+ distributionUrl="${distributionUrl%-bin.*}-$distributionPlatform.zip"
+ ;;
+(maven-mvnd-*) MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ ;;
+(*) MVN_CMD="mvn${0##*/mvnw}" _MVNW_REPO_PATTERN=/org/apache/maven/ ;;
+esac
+
+# apply MVNW_REPOURL and calculate MAVEN_HOME
+# maven home pattern:
~/.m2/wrapper/dists/{apache-maven-<version>,maven-mvnd-<version>-<platform>}/<hash>
+[ -z "${MVNW_REPOURL-}" ] ||
distributionUrl="$MVNW_REPOURL$_MVNW_REPO_PATTERN${distributionUrl#*"$_MVNW_REPO_PATTERN"}"
distributionUrlName="${distributionUrl##*/}"
-distributionUrlNameMain="${distributionUrlName%-bin.*}"
+distributionUrlNameMain="${distributionUrlName%.*}"
+distributionUrlNameMain="${distributionUrlNameMain%-bin}"
MAVEN_HOME="$HOME/.m2/wrapper/dists/${distributionUrlNameMain-}/$(hash_string
"$distributionUrl")"
-MVN_CMD="mvn${0##*/mvnw}"
+
+exec_maven() {
+ unset MVNW_VERBOSE MVNW_USERNAME MVNW_PASSWORD MVNW_REPOURL || :
+ exec "$MAVEN_HOME/bin/$MVN_CMD" "$@" || die "cannot exec
$MAVEN_HOME/bin/$MVN_CMD"
+}
if [ -d "$MAVEN_HOME" ]; then
verbose "found existing MAVEN_HOME at $MAVEN_HOME"
- unset MVNW_VERBOSE MVNW_USERNAME MVNW_PASSWORD MVNW_REPOURL
- exec "$MAVEN_HOME/bin/$MVN_CMD" "$@" || die "MAVEN_HOME is not valid: cannot
exec $MAVEN_HOME/bin/mvn"
+ exec_maven "$@"
fi
case "${distributionUrl-}" in
-(*?-bin.zip) ;;
-(*) die "distributionUrl is not valid, must end with *-bin.zip, but found
'${distributionUrl-}'" ;;
+(*?-bin.zip|*?maven-mvnd-?*-?*.zip) ;;
+(*) die "distributionUrl is not valid, must match *-bin.zip or
maven-mvnd-*.zip, but found '${distributionUrl-}'" ;;
esac
# prepare tmp dir
@@ -177,9 +200,13 @@ elif set_java_home; then
fi
# If specified, validate the SHA-256 sum of the Maven distribution zip file
-if [ -n "$distributionSha256Sum" ]; then
+if [ -n "${distributionSha256Sum-}" ]; then
distributionSha256Result=false
- if command -v sha256sum > /dev/null; then
+ if [ "$MVN_CMD" = mvnd.sh ]; then
+ echo "Checksum validation is not supported for maven-mvnd." >&2
+ echo "Please disable validation by removing 'distributionSha256Sum' from
your maven-wrapper.properties." >&2
+ exit 1
+ elif command -v sha256sum > /dev/null; then
if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" |
sha256sum -c > /dev/null 2>&1; then
distributionSha256Result=true
fi
@@ -188,8 +215,8 @@ if [ -n "$distributionSha256Sum" ]; then
distributionSha256Result=true
fi
else
- echo "Checksum validation was requested but neither 'sha256sum' or
'shasum' are available."
- echo "Please install either command, or disable validation by removing
'distributionSha256Sum' from your maven-wrapper.properties."
+ echo "Checksum validation was requested but neither 'sha256sum' or
'shasum' are available." >&2
+ echo "Please install either command, or disable validation by removing
'distributionSha256Sum' from your maven-wrapper.properties." >&2
exit 1
fi
if [ $distributionSha256Result = false ]; then
@@ -209,5 +236,4 @@ printf %s\\n "$distributionUrl" >
"$TMP_DOWNLOAD_DIR/$distributionUrlNameMain/mv
mv -- "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" "$MAVEN_HOME" || [ -d
"$MAVEN_HOME" ] || die "fail to move MAVEN_HOME"
clean || :
-unset MVNW_VERBOSE MVNW_USERNAME MVNW_PASSWORD MVNW_REPOURL || :
-exec "$MAVEN_HOME/bin/$MVN_CMD" "$@"
+exec_maven "$@"
diff --git a/maven-wrapper-distribution/src/resources/only-mvnw.cmd
b/maven-wrapper-distribution/src/resources/only-mvnw.cmd
index 0bfafa5..9edc540 100644
--- a/maven-wrapper-distribution/src/resources/only-mvnw.cmd
+++ b/maven-wrapper-distribution/src/resources/only-mvnw.cmd
@@ -33,17 +33,15 @@
@SET __MVNW_PSMODULEP_SAVE=%PSModulePath%
@SET PSModulePath=
@FOR /F "usebackq tokens=1* delims==" %%A IN (`powershell -noprofile "&
{$scriptDir='%~dp0'; $script='%__MVNW_ARG0_NAME__%'; icm -ScriptBlock
([Scriptblock]::Create((Get-Content -Raw '%~f0'))) -NoNewScope}"`) DO @(
- IF "%%A"=="MVN_ERROR" (set __MVNW_ERROR__=%%B) ELSE IF "%%A"=="MVN_CMD" (set
__MVNW_CMD__=%%B) ELSE IF "%%B"=="" (echo %%A) ELSE (echo %%A=%%B)
-)
-@IF NOT "%__MVNW_ERROR__%"=="" (
- echo "%__MVNW_ERROR__%"
- EXIT /B 1
+ IF "%%A"=="MVN_CMD" (set __MVNW_CMD__=%%B) ELSE IF "%%B"=="" (echo %%A) ELSE
(echo %%A=%%B)
)
@SET PSModulePath=%__MVNW_PSMODULEP_SAVE%
@SET __MVNW_PSMODULEP_SAVE=
@SET __MVNW_ARG0_NAME__=
+@SET MVNW_USERNAME=
+@SET MVNW_PASSWORD=
@IF NOT "%__MVNW_CMD__%"=="" (%__MVNW_CMD__% %*)
-@echo Cannot start maven from wrapper >&2 && cmd /c exit /b 2
+@echo Cannot start maven from wrapper >&2 && exit /b 1
@GOTO :EOF
: end batch / begin powershell #>
@@ -57,17 +55,32 @@ $distributionUrl = (Get-Content -Raw
"$scriptDir/.mvn/wrapper/maven-wrapper.prop
if (!$distributionUrl) {
Write-Error "cannot read distributionUrl property in
$scriptDir/.mvn/wrapper/maven-wrapper.properties"
}
-if ($env:MVNW_REPOURL) {
- $distributionUrl = "$env:MVNW_REPOURL/org/apache/maven/$($distributionUrl
-replace '^.*/org/apache/maven/','')"
+
+switch -wildcard -casesensitive ( $($distributionUrl -replace '^.*/','') ) {
+ "maven-mvnd-*" {
+ $USE_MVND = $true
+ $distributionUrl = $distributionUrl -replace
'-bin\.[^.]*$',"-windows-amd64.zip"
+ $MVN_CMD = "mvnd.cmd"
+ break
+ }
+ default {
+ $USE_MVND = $false
+ $MVN_CMD = $script -replace '^mvnw','mvn'
+ break
+ }
}
-# calculate MAVEN_HOME, pattern
~/.m2/wrapper/dists/apache-maven-<version>/<hash>
+# apply MVNW_REPOURL and calculate MAVEN_HOME
+# maven home pattern:
~/.m2/wrapper/dists/{apache-maven-<version>,maven-mvnd-<version>-<platform>}/<hash>
+if ($env:MVNW_REPOURL) {
+ $MVNW_REPO_PATTERN = if ($USE_MVND) { "/org/apache/maven/" } else {
"/maven/mvnd/" }
+ $distributionUrl = "$env:MVNW_REPOURL$MVNW_REPO_PATTERN$($distributionUrl
-replace '^.*'+$MVNW_REPO_PATTERN,'')"
+}
$distributionUrlName = $distributionUrl -replace '^.*/',''
-$distributionUrlNameMain = $distributionUrlName -replace '-bin\.zip$',''
+$distributionUrlNameMain = $distributionUrlName -replace '\.[^.]*$',''
-replace '-bin$',''
$MAVEN_HOME_PARENT = "$HOME/.m2/wrapper/dists/$distributionUrlNameMain"
$MAVEN_HOME_NAME =
([System.Security.Cryptography.MD5]::Create().ComputeHash([byte[]][char[]]$distributionUrl)
| ForEach-Object {$_.ToString("x2")}) -join ''
$MAVEN_HOME = "$MAVEN_HOME_PARENT/$MAVEN_HOME_NAME"
-$MVN_CMD = $script -replace '^mvnw','mvn'
if (Test-Path -Path "$MAVEN_HOME" -PathType Container) {
Write-Verbose "found existing MAVEN_HOME at $MAVEN_HOME"
@@ -107,9 +120,11 @@ $webclient.DownloadFile($distributionUrl,
"$TMP_DOWNLOAD_DIR/$distributionUrlNam
# If specified, validate the SHA-256 sum of the Maven distribution zip file
$distributionSha256Sum = (Get-Content -Raw
"$scriptDir/.mvn/wrapper/maven-wrapper.properties" |
ConvertFrom-StringData).distributionSha256Sum
if ($distributionSha256Sum) {
+ if ($USE_MVND) {
+ Write-Error "Checksum validation is not supported for maven-mvnd. `nPlease
disable validation by removing 'distributionSha256Sum' from your
maven-wrapper.properties."
+ }
if ((Get-FileHash "$TMP_DOWNLOAD_DIR/$distributionUrlName" -Algorithm
SHA256).Hash.ToLower() -ne $distributionSha256Sum) {
- Write-Output "MVN_ERROR=Error: Failed to validate Maven distribution
SHA-256, your Maven distribution might be compromised. If you updated your
Maven version, you need to update the specified distributionSha256Sum property."
- exit
+ Write-Error "Error: Failed to validate Maven distribution SHA-256, your
Maven distribution might be compromised. If you updated your Maven version, you
need to update the specified distributionSha256Sum property."
}
}
diff --git a/maven-wrapper-plugin/src/it/projects/test_mvnd/pom.xml
b/maven-wrapper-plugin/src/it/projects/test_mvnd/pom.xml
new file mode 100644
index 0000000..854e2eb
--- /dev/null
+++ b/maven-wrapper-plugin/src/it/projects/test_mvnd/pom.xml
@@ -0,0 +1,68 @@
+<?xml version='1.0' encoding='UTF-8'?>
+
+<!--
+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.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.apache.maven.plugins.it.wrapper</groupId>
+ <artifactId>mvnd</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <packaging>pom</packaging>
+
+ <properties>
+ <cmd></cmd>
+ </properties>
+
+ <build>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>exec-maven-plugin</artifactId>
+ <version>3.0.0</version>
+ <configuration>
+ <executable>mvnw${cmd}</executable>
+ <arguments>
+ <argument>--status</argument>
+ </arguments>
+ <environmentVariables>
+ <MVNW_VERBOSE>true</MVNW_VERBOSE>
+ <HOME>${project.build.directory}</HOME>
+ <USERPROFILE>${project.build.directory}</USERPROFILE>
+ </environmentVariables>
+ </configuration>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ </build>
+
+ <profiles>
+ <profile>
+ <id>windows</id>
+ <activation>
+ <os><family>windows</family></os>
+ </activation>
+ <properties>
+ <cmd>.cmd</cmd>
+ </properties>
+ </profile>
+ </profiles>
+</project>
diff --git a/maven-wrapper-plugin/src/it/projects/test_mvnd/test.properties
b/maven-wrapper-plugin/src/it/projects/test_mvnd/test.properties
new file mode 100644
index 0000000..2f2c56a
--- /dev/null
+++ b/maven-wrapper-plugin/src/it/projects/test_mvnd/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
+mvnd=0.9.0
diff --git a/maven-wrapper-plugin/src/it/projects/test_mvnd/verify.groovy
b/maven-wrapper-plugin/src/it/projects/test_mvnd/verify.groovy
new file mode 100644
index 0000000..0cbd8f2
--- /dev/null
+++ b/maven-wrapper-plugin/src/it/projects/test_mvnd/verify.groovy
@@ -0,0 +1,44 @@
+/*
+ * 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.
+ */
+
+assert new File(basedir,'mvnw').exists()
+assert new File(basedir,'mvnw.cmd').exists()
+assert !(new File(basedir,'mvnwDebug').exists())
+assert !(new File(basedir,'mvnwDebug.cmd').exists())
+
+def propertiesFile = new File(basedir,'.mvn/wrapper/maven-wrapper.properties')
+assert propertiesFile.exists()
+
+def props = new Properties()
+propertiesFile.withInputStream {
+ props.load(it)
+}
+
+assert
props.distributionUrl.equals('https://archive.apache.org/dist/maven/mvnd/0.9.0/maven-mvnd-0.9.0-bin.zip')
+
+log = new File(basedir, 'build.log').text
+
+// check "mvn wrapper:wrapper" output
+// works only on 'only-script' type
+assert log.contains('[INFO] Unpacked only-script type wrapper distribution
org.apache.maven.wrapper:maven-wrapper-distribution:zip:only-script:')
+
+// check "mvnw --status" output
+assert log.contains("Status")
+assert log.contains("RSS")
+assert log.contains("Java home")
diff --git
a/maven-wrapper-plugin/src/main/java/org/apache/maven/plugins/wrapper/WrapperMojo.java
b/maven-wrapper-plugin/src/main/java/org/apache/maven/plugins/wrapper/WrapperMojo.java
index ba1a4d5..f6afa05 100644
---
a/maven-wrapper-plugin/src/main/java/org/apache/maven/plugins/wrapper/WrapperMojo.java
+++
b/maven-wrapper-plugin/src/main/java/org/apache/maven/plugins/wrapper/WrapperMojo.java
@@ -72,6 +72,12 @@ public class WrapperMojo extends AbstractMojo {
@Parameter(property = "maven")
private String mavenVersion;
+ /**
+ * The version of Maven Daemon to require.
+ */
+ @Parameter(property = "mvnd")
+ private String mvndVersion;
+
/**
* Options are:
* <dl>
@@ -81,6 +87,8 @@ public class WrapperMojo extends AbstractMojo {
* <dd>precompiled and packaged code</dd>
* <dt>source</dt>
* <dd>Java source code, will be compiled on the fly</dd>
+ * <dt>only-script</dt>
+ * <dd>the new lite implementation of mvnw/mvnw.cmd scripts downloads
the maven directly and skips maven-wrapper.jar</dd>
* </dl>
*
* Value will be used as classifier of the downloaded file
@@ -152,6 +160,11 @@ public class WrapperMojo extends AbstractMojo {
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
+ if (mvndVersion != null && mvndVersion.length() > 0 &&
!"only-script".equals(distributionType)) {
+ throw new MojoExecutionException("maven-wrapper with type=" +
distributionType
+ + " cannot work with mvnd, please set type to
'only-script'.");
+ }
+
mavenVersion = getVersion(mavenVersion, Maven.class,
"org.apache.maven/maven-core");
String wrapperVersion = getVersion(null, this.getClass(),
"org.apache.maven.plugins/maven-wrapper-plugin");
@@ -243,6 +256,12 @@ public class WrapperMojo extends AbstractMojo {
String wrapperUrl = repoUrl +
"/org/apache/maven/wrapper/maven-wrapper/" + wrapperVersion + "/maven-wrapper-"
+ wrapperVersion + ".jar";
+ if (mvndVersion != null && mvndVersion.length() > 0) {
+ // now maven-mvnd is not published to the central repo.
+ distributionUrl = "https://archive.apache.org/dist/maven/mvnd/" +
mvndVersion + "/maven-mvnd-" + mvndVersion
+ + "-bin.zip";
+ }
+
Path wrapperPropertiesFile =
targetFolder.resolve("maven-wrapper.properties");
getLog().info("Configuring .mvn/wrapper/maven-wrapper.properties to
use "