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

hboutemy 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 17ebd0a  [MWRAPPER-31] Get rid of maven-artifact-transfer
17ebd0a is described below

commit 17ebd0aa6791e07f81e1cf5e53b634d1f199efdd
Author: Slawomir Jaranowski <[email protected]>
AuthorDate: Thu Dec 9 21:25:50 2021 +0100

    [MWRAPPER-31] Get rid of maven-artifact-transfer
---
 maven-wrapper-plugin/pom.xml                       | 15 -----
 .../it/projects/type_unknown/invoker.properties    | 19 +++++++
 .../src/it/projects/type_unknown/pom.xml           | 29 ++++++++++
 .../src/it/projects/type_unknown/test.properties   | 18 ++++++
 .../src/it/projects/type_unknown/verify.groovy     | 28 ++++++++++
 .../apache/maven/plugins/wrapper/WrapperMojo.java  | 64 +++++++++++++---------
 6 files changed, 131 insertions(+), 42 deletions(-)

diff --git a/maven-wrapper-plugin/pom.xml b/maven-wrapper-plugin/pom.xml
index 6d75f7e..39d2802 100644
--- a/maven-wrapper-plugin/pom.xml
+++ b/maven-wrapper-plugin/pom.xml
@@ -60,21 +60,6 @@ under the License.
       <version>3.3.4</version>
     </dependency>
     <dependency>
-      <groupId>org.apache.maven.shared</groupId>
-      <artifactId>maven-artifact-transfer</artifactId>
-      <version>0.12.0</version>
-      <exclusions>
-        <exclusion>
-          <groupId>org.apache.maven</groupId>
-          <artifactId>maven-artifact</artifactId>
-        </exclusion>
-        <exclusion>
-          <groupId>org.apache.maven</groupId>
-          <artifactId>maven-model</artifactId>
-        </exclusion>
-      </exclusions>
-    </dependency>
-    <dependency>
       <groupId>org.codehaus.plexus</groupId>
       <artifactId>plexus-archiver</artifactId>
       <version>4.2.1</version>
diff --git 
a/maven-wrapper-plugin/src/it/projects/type_unknown/invoker.properties 
b/maven-wrapper-plugin/src/it/projects/type_unknown/invoker.properties
new file mode 100644
index 0000000..c067db4
--- /dev/null
+++ b/maven-wrapper-plugin/src/it/projects/type_unknown/invoker.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.
+
+invoker.buildResult = failure
+
diff --git a/maven-wrapper-plugin/src/it/projects/type_unknown/pom.xml 
b/maven-wrapper-plugin/src/it/projects/type_unknown/pom.xml
new file mode 100644
index 0000000..ed54d55
--- /dev/null
+++ b/maven-wrapper-plugin/src/it/projects/type_unknown/pom.xml
@@ -0,0 +1,29 @@
+<?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>extension</artifactId>
+  <version>1.0.0-SNAPSHOT</version>
+  <packaging>pom</packaging>
+</project>
\ No newline at end of file
diff --git a/maven-wrapper-plugin/src/it/projects/type_unknown/test.properties 
b/maven-wrapper-plugin/src/it/projects/type_unknown/test.properties
new file mode 100644
index 0000000..e2ccdce
--- /dev/null
+++ b/maven-wrapper-plugin/src/it/projects/type_unknown/test.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.
+
+type=unknown-type
diff --git a/maven-wrapper-plugin/src/it/projects/type_unknown/verify.groovy 
b/maven-wrapper-plugin/src/it/projects/type_unknown/verify.groovy
new file mode 100644
index 0000000..7874070
--- /dev/null
+++ b/maven-wrapper-plugin/src/it/projects/type_unknown/verify.groovy
@@ -0,0 +1,28 @@
+/*
+ * 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()
+assert !new File( basedir, '.mvn/wrapper' ).exists()
+
+def buildLog = new File( basedir, "build.log").text;
+
+assert buildLog.matches('(?ms).*artifact: 
org.apache.maven.wrapper:maven-wrapper-distribution:zip:unknown-type:.* not 
resolved.*')
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 e160358..ae70a76 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
@@ -35,17 +35,16 @@ import javax.inject.Inject;
 
 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.project.DefaultProjectBuildingRequest;
-import org.apache.maven.project.ProjectBuildingRequest;
-import org.apache.maven.shared.transfer.artifact.DefaultArtifactCoordinate;
-import org.apache.maven.shared.transfer.artifact.resolve.ArtifactResolver;
-import 
org.apache.maven.shared.transfer.artifact.resolve.ArtifactResolverException;
+import org.apache.maven.repository.RepositorySystem;
 import org.codehaus.plexus.archiver.UnArchiver;
 import org.codehaus.plexus.components.io.fileselectors.FileInfo;
 import org.codehaus.plexus.components.io.fileselectors.FileSelector;
@@ -112,8 +111,8 @@ public class WrapperMojo extends AbstractMojo
     // COMPONENTS 
     
     @Inject
-    private ArtifactResolver artifactResolver;
-    
+    private RepositorySystem repositorySystem;
+
     @Inject
     private Map<String, UnArchiver> unarchivers;
     
@@ -123,15 +122,7 @@ public class WrapperMojo extends AbstractMojo
     {
         String wrapperVersion = getVersion( null, this.getClass(), 
"org.apache.maven.plugins/maven-wrapper-plugin" );
 
-        Artifact artifact;
-        try
-        {
-            artifact = downloadWrapperDistribution( wrapperVersion );
-        }
-        catch ( ArtifactResolverException e )
-        {
-            throw new MojoExecutionException( e.getMessage(), e );
-        }
+        Artifact artifact = downloadWrapperDistribution( wrapperVersion );
 
         try
         {
@@ -155,20 +146,39 @@ public class WrapperMojo extends AbstractMojo
         }
     }
     
-    private Artifact downloadWrapperDistribution( String wrapperVersion )
-        throws ArtifactResolverException
+    private Artifact downloadWrapperDistribution( String wrapperVersion ) 
throws MojoExecutionException
     {
-        ProjectBuildingRequest buildingRequest =
-            new DefaultProjectBuildingRequest( 
session.getProjectBuildingRequest() );
+        Artifact artifact = repositorySystem.createArtifactWithClassifier(
+            WRAPPER_DISTRIBUTION_GROUP_ID,
+            WRAPPER_DISTRIBUTION_ARTIFACT_ID,
+            wrapperVersion,
+            WRAPPER_DISTRIBUTION_EXTENSION,
+            distributionType );
+
+        MavenExecutionRequest executionRequest = session.getRequest();
 
-        DefaultArtifactCoordinate coordinate = new DefaultArtifactCoordinate();
-        coordinate.setGroupId( WRAPPER_DISTRIBUTION_GROUP_ID );
-        coordinate.setArtifactId( WRAPPER_DISTRIBUTION_ARTIFACT_ID );
-        coordinate.setVersion( wrapperVersion ); 
-        coordinate.setClassifier( distributionType );
-        coordinate.setExtension( WRAPPER_DISTRIBUTION_EXTENSION );
+        ArtifactResolutionRequest resolutionRequest = new 
ArtifactResolutionRequest()
+            .setArtifact( artifact )
+            .setLocalRepository( session.getLocalRepository() )
+            .setRemoteRepositories( 
session.getCurrentProject().getPluginArtifactRepositories() )
+            .setOffline( executionRequest.isOffline() )
+            .setForceUpdate( executionRequest.isUpdateSnapshots() );
+
+        ArtifactResolutionResult resolveResult = repositorySystem.resolve( 
resolutionRequest );
+
+        if ( !resolveResult.isSuccess() )
+        {
+            if ( executionRequest.isShowErrors() )
+            {
+                for ( Exception e : resolveResult.getExceptions() )
+                {
+                    getLog().error( e.getMessage(), e );
+                }
+            }
+            throw new MojoExecutionException( "artifact: " + artifact + " not 
resolved." );
+        }
 
-        return artifactResolver.resolveArtifact( buildingRequest, coordinate 
).getArtifact();
+        return artifact;
     }
     
     private void unpack( Artifact artifact, Path targetFolder ) throws 
IOException 

Reply via email to