You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sj...@apache.org on 2023/02/23 19:02:31 UTC

[maven-wrapper] 01/01: [MWRAPPER-96] Require Maven 3.2.5

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

sjaranowski pushed a commit to branch MWRAPPER-96
in repository https://gitbox.apache.org/repos/asf/maven-wrapper.git

commit b291b82d9ede18b1341a52883b223fe07606caee
Author: Slawomir Jaranowski <s....@gmail.com>
AuthorDate: Thu Feb 23 20:02:17 2023 +0100

    [MWRAPPER-96] Require Maven 3.2.5
    
    - Use Resolver API
    - add missing since tag
---
 .../apache/maven/plugins/wrapper/WrapperMojo.java  | 65 ++++++++++++----------
 pom.xml                                            |  2 +-
 2 files changed, 37 insertions(+), 30 deletions(-)

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 f6afa05..6ac1988 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
@@ -33,21 +33,22 @@ import java.util.Map;
 import java.util.Properties;
 
 import org.apache.maven.Maven;
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.resolver.ArtifactResolutionRequest;
-import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
-import org.apache.maven.execution.MavenExecutionRequest;
 import org.apache.maven.execution.MavenSession;
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
 import org.apache.maven.plugins.annotations.Mojo;
 import org.apache.maven.plugins.annotations.Parameter;
-import org.apache.maven.repository.RepositorySystem;
 import org.apache.maven.settings.Mirror;
 import org.apache.maven.settings.Settings;
 import org.codehaus.plexus.archiver.UnArchiver;
 import org.codehaus.plexus.components.io.fileselectors.FileSelector;
+import org.eclipse.aether.RepositorySystem;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.artifact.DefaultArtifact;
+import org.eclipse.aether.resolution.ArtifactRequest;
+import org.eclipse.aether.resolution.ArtifactResolutionException;
+import org.eclipse.aether.resolution.ArtifactResult;
 
 import static org.apache.maven.shared.utils.logging.MessageUtils.buffer;
 
@@ -68,12 +69,16 @@ public class WrapperMojo extends AbstractMojo {
     /**
      * The version of Maven to require, default value is the Runtime version of Maven.
      * Can be any valid release above 2.0.9
+     *
+     * @since 3.0.0
      */
     @Parameter(property = "maven")
     private String mavenVersion;
 
     /**
      * The version of Maven Daemon to require.
+     *
+     * @since 3.2.0
      */
     @Parameter(property = "mvnd")
     private String mvndVersion;
@@ -88,16 +93,19 @@ public class WrapperMojo extends AbstractMojo {
      *   <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>
+     *   <dd>the new lite implementation of mvnw/mvnw.cmd scripts downloads the maven directly and skips maven-wrapper.jar - since 3.2.0</dd>
      * </dl>
-     *
      * Value will be used as classifier of the downloaded file
+     *
+     * @since 3.0.0
      */
     @Parameter(defaultValue = "bin", property = "type")
     private String distributionType;
 
     /**
      * Include <code>mvnwDebug*</code> scripts?
+     *
+     * @since 3.0.0
      */
     @Parameter(defaultValue = "false", property = "includeDebug")
     private boolean includeDebugScript;
@@ -105,6 +113,8 @@ public class WrapperMojo extends AbstractMojo {
     /**
      * The expected SHA-256 checksum of the <i>maven-wrapper.jar</i> that is
      * used to load the configured Maven distribution.
+     *
+     * @since 3.2.0
      */
     @Parameter(property = "wrapperSha256Sum")
     private String wrapperSha256Sum;
@@ -112,6 +122,8 @@ public class WrapperMojo extends AbstractMojo {
     /**
      * The expected SHA-256 checksum of the Maven distribution that is
      * executed by the installed wrapper.
+     *
+     * @since 3.2.0
      */
     @Parameter(property = "distributionSha256Sum")
     private String distributionSha256Sum;
@@ -119,6 +131,8 @@ public class WrapperMojo extends AbstractMojo {
     /**
      * Determines if the Maven distribution should be downloaded
      * on every execution of the Maven wrapper.
+     *
+     * @since 3.2.0
      */
     @Parameter(defaultValue = "false", property = "alwaysDownload")
     private boolean alwaysDownload;
@@ -126,6 +140,8 @@ public class WrapperMojo extends AbstractMojo {
     /**
      * Determines if the Maven distribution should be unpacked
      * on every execution of the Maven wrapper.
+     *
+     * @since 3.2.0
      */
     @Parameter(defaultValue = "false", property = "alwaysUnpack")
     private boolean alwaysUnpack;
@@ -198,34 +214,25 @@ public class WrapperMojo extends AbstractMojo {
     }
 
     private Artifact downloadWrapperDistribution(String wrapperVersion) throws MojoExecutionException {
-        Artifact artifact = repositorySystem.createArtifactWithClassifier(
+
+        Artifact artifact = new DefaultArtifact(
                 WRAPPER_DISTRIBUTION_GROUP_ID,
                 WRAPPER_DISTRIBUTION_ARTIFACT_ID,
-                wrapperVersion,
+                distributionType,
                 WRAPPER_DISTRIBUTION_EXTENSION,
-                distributionType);
+                wrapperVersion);
 
-        MavenExecutionRequest executionRequest = session.getRequest();
+        ArtifactRequest request = new ArtifactRequest();
+        request.setRepositories(session.getCurrentProject().getRemotePluginRepositories());
+        request.setArtifact(artifact);
 
-        ArtifactResolutionRequest resolutionRequest = new ArtifactResolutionRequest()
-                .setArtifact(artifact)
-                .setLocalRepository(session.getLocalRepository())
-                .setRemoteRepositories(session.getCurrentProject().getPluginArtifactRepositories())
-                .setOffline(executionRequest.isOffline())
-                .setForceUpdate(executionRequest.isUpdateSnapshots());
-
-        ArtifactResolutionResult resolveResult = repositorySystem.resolve(resolutionRequest);
+        try {
+            ArtifactResult artifactResult = repositorySystem.resolveArtifact(session.getRepositorySession(), request);
+            return artifactResult.getArtifact();
 
-        if (!resolveResult.isSuccess()) {
-            if (executionRequest.isShowErrors()) {
-                for (Exception e : resolveResult.getExceptions()) {
-                    getLog().error(e.getMessage(), e);
-                }
-            }
-            throw new MojoExecutionException("artifact: " + artifact + " not resolved.");
+        } catch (ArtifactResolutionException e) {
+            throw new MojoExecutionException("artifact: " + artifact + " not resolved.", e);
         }
-
-        return artifact;
     }
 
     private void unpack(Artifact artifact, Path targetFolder) {
@@ -245,7 +252,7 @@ public class WrapperMojo extends AbstractMojo {
      * No need to look for other properties, restore them, respecting comments, etc.
      *
      * @param wrapperVersion the wrapper version
-     * @param targetFolder the folder containing the wrapper.properties
+     * @param targetFolder   the folder containing the wrapper.properties
      * @throws MojoExecutionException if writing fails
      */
     private void replaceProperties(String wrapperVersion, Path targetFolder) throws MojoExecutionException {
diff --git a/pom.xml b/pom.xml
index 589c5bd..eabd67b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -63,7 +63,7 @@ under the License.
 
   <properties>
     <maven.site.path>wrapper-archives/wrapper-LATEST</maven.site.path>
-    <mavenVersion>3.1.0</mavenVersion>
+    <mavenVersion>3.2.5</mavenVersion>
     <javaVersion>8</javaVersion>
     <project.build.outputTimestamp>2022-05-08T09:15:34Z</project.build.outputTimestamp>
   </properties>