You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by cs...@apache.org on 2022/04/08 17:09:19 UTC

[maven] branch MNG-7454-master-resolver-http-transport created (now e3a8d50cd)

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

cstamas pushed a change to branch MNG-7454-master-resolver-http-transport
in repository https://gitbox.apache.org/repos/asf/maven.git


      at e3a8d50cd [MNG-7454] Include resolver-transport-http in Maven

This branch includes the following new commits:

     new e3a8d50cd [MNG-7454] Include resolver-transport-http in Maven

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[maven] 01/01: [MNG-7454] Include resolver-transport-http in Maven

Posted by cs...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

cstamas pushed a commit to branch MNG-7454-master-resolver-http-transport
in repository https://gitbox.apache.org/repos/asf/maven.git

commit e3a8d50cdfcbf175f142de0a251a6bfd6d93027f
Author: Tamas Cservenak <ta...@cservenak.net>
AuthorDate: Fri Apr 8 19:08:37 2022 +0200

    [MNG-7454] Include resolver-transport-http in Maven
    
    But keep Wagon as default transport. This PR merely includes
    resolver http and file transport and switches wagon-http
    to non-shaded one.
    
    Changes:
    * switch to non-shaded wagon-http (as httpClient is now shared)
    * include resolver http and file transport
    * override resolver default behaviour (native transport preferred over wagon, when both on classpath)
    * provide simplistic means to choose transport
    
    The chosen transport can be seen in debug (-X) output on line
    `[DEBUG] Using transporter XXX...`
    
    The `-Dmaven.transport` simplistic switch can be used to choose transport:
    * not set: default, that is Wagon
    * `wagon`: explicitly sets Wagon
    * `resolver`: explicitly sets resolver native transports (file and http)
    * `auto`: relies on resolver "auto discovery" (priorities, etc). This is MUST to keep transport pluggable with 3rd party transports. In fact, this was the default so far in Maven, along with the fact that native resolver transports were not included (as resolver prefers native ones over Wagon).
---
 apache-maven/pom.xml                               | 29 +++++++-----------
 .../DefaultRepositorySystemSessionFactory.java     | 35 ++++++++++++++++++++++
 maven-resolver-provider/pom.xml                    |  6 ++--
 pom.xml                                            | 13 ++++++--
 4 files changed, 60 insertions(+), 23 deletions(-)

diff --git a/apache-maven/pom.xml b/apache-maven/pom.xml
index 5fc55288e..b8f1c3bfe 100644
--- a/apache-maven/pom.xml
+++ b/apache-maven/pom.xml
@@ -63,21 +63,10 @@ under the License.
     <dependency>
       <groupId>org.apache.maven.wagon</groupId>
       <artifactId>wagon-http</artifactId>
-      <classifier>shaded</classifier>
-      <exclusions>
-        <exclusion>
-          <groupId>org.apache.httpcomponents</groupId>
-          <artifactId>httpclient</artifactId>
-        </exclusion>
-        <exclusion>
-          <groupId>org.apache.httpcomponents</groupId>
-          <artifactId>httpcore</artifactId>
-        </exclusion>
-        <exclusion>
-          <groupId>org.apache.maven.wagon</groupId>
-          <artifactId>wagon-http-shared</artifactId>
-        </exclusion>
-      </exclusions>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven.wagon</groupId>
+      <artifactId>wagon-file</artifactId>
     </dependency>
     <dependency>
       <groupId>org.slf4j</groupId>
@@ -86,12 +75,16 @@ under the License.
       <scope>runtime</scope>
     </dependency>
     <dependency>
-      <groupId>org.apache.maven.wagon</groupId>
-      <artifactId>wagon-file</artifactId>
+      <groupId>org.apache.maven.resolver</groupId>
+      <artifactId>maven-resolver-connector-basic</artifactId>
     </dependency>
     <dependency>
       <groupId>org.apache.maven.resolver</groupId>
-      <artifactId>maven-resolver-connector-basic</artifactId>
+      <artifactId>maven-resolver-transport-file</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven.resolver</groupId>
+      <artifactId>maven-resolver-transport-http</artifactId>
     </dependency>
     <dependency>
       <groupId>org.apache.maven.resolver</groupId>
diff --git a/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java b/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java
index d157e7621..80c6ba794 100644
--- a/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java
+++ b/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java
@@ -78,6 +78,22 @@ import org.slf4j.LoggerFactory;
 @Named
 public class DefaultRepositorySystemSessionFactory
 {
+    private static final String MAVEN_TRANSPORT_KEY = "maven.transport";
+
+    private static final String MAVEN_TRANSPORT_WAGON = "wagon";
+
+    private static final String MAVEN_TRANSPORT_RESOLVER = "resolver";
+
+    private static final String MAVEN_TRANSPORT_AUTO = "auto";
+
+    private static final String WAGON_TRANSPORTER_KEY_PRIORITY_KEY = "aether.priority.WagonTransporterFactory";
+
+    private static final String RESOLVER_HTTP_TRANSPORTER_PRIORITY_KEY = "aether.priority.HttpTransporterFactory";
+
+    private static final String RESOLVER_FILE_TRANSPORTER_PRIORITY_KEY = "aether.priority.FileTransporterFactory";
+
+    private static final String RESOLVER_MAX_PRIORITY = String.valueOf( Float.MAX_VALUE );
+
     private final Logger logger = LoggerFactory.getLogger( getClass() );
 
     private final ArtifactHandlerManager artifactHandlerManager;
@@ -245,6 +261,25 @@ public class DefaultRepositorySystemSessionFactory
         }
         session.setAuthenticationSelector( authSelector );
 
+        String transport = request.getUserProperties().getProperty( MAVEN_TRANSPORT_KEY, MAVEN_TRANSPORT_WAGON );
+        if ( MAVEN_TRANSPORT_RESOLVER.equals( transport ) )
+        {
+            // Make sure (whatever extra priority is set) that resolver native is selected
+            configProps.put( RESOLVER_FILE_TRANSPORTER_PRIORITY_KEY, RESOLVER_MAX_PRIORITY );
+            configProps.put( RESOLVER_HTTP_TRANSPORTER_PRIORITY_KEY, RESOLVER_MAX_PRIORITY );
+        }
+        else if ( MAVEN_TRANSPORT_WAGON.equals( transport ) )
+        {
+            // Make sure (whatever extra priority is set) that wagon is selected
+            configProps.put( WAGON_TRANSPORTER_KEY_PRIORITY_KEY, RESOLVER_MAX_PRIORITY );
+        }
+        else if ( !MAVEN_TRANSPORT_AUTO.equals( transport ) )
+        {
+            throw new IllegalArgumentException( "Unknown maven.transport=" + transport
+                    + ". Supported ones are: " + MAVEN_TRANSPORT_WAGON + ", "
+                    + MAVEN_TRANSPORT_RESOLVER + " and " + MAVEN_TRANSPORT_AUTO );
+        }
+
         session.setTransferListener( request.getTransferListener() );
 
         session.setRepositoryListener( eventSpyDispatcher.chainListener( new LoggingRepositoryListener( logger ) ) );
diff --git a/maven-resolver-provider/pom.xml b/maven-resolver-provider/pom.xml
index 0027e348f..5b416a4ef 100644
--- a/maven-resolver-provider/pom.xml
+++ b/maven-resolver-provider/pom.xml
@@ -117,12 +117,12 @@ under the License.
     </dependency>
     <dependency>
       <groupId>org.apache.maven.resolver</groupId>
-      <artifactId>maven-resolver-transport-wagon</artifactId>
+      <artifactId>maven-resolver-transport-file</artifactId>
       <scope>test</scope>
     </dependency>
     <dependency>
-      <groupId>org.apache.maven.wagon</groupId>
-      <artifactId>wagon-file</artifactId>
+      <groupId>org.apache.maven.resolver</groupId>
+      <artifactId>maven-resolver-transport-http</artifactId>
       <scope>test</scope>
     </dependency>
     <dependency>
diff --git a/pom.xml b/pom.xml
index 4c2c09c74..f5e1dff20 100644
--- a/pom.xml
+++ b/pom.xml
@@ -65,7 +65,7 @@ under the License.
     <cipherVersion>2.0</cipherVersion>
     <modelloVersion>2.0.0</modelloVersion>
     <jxpathVersion>1.3</jxpathVersion>
-    <resolverVersion>1.7.2</resolverVersion>
+    <resolverVersion>1.7.3</resolverVersion>
     <slf4jVersion>1.7.32</slf4jVersion>
     <xmlunitVersion>2.6.4</xmlunitVersion>
     <maven.test.redirectTestOutputToFile>true</maven.test.redirectTestOutputToFile>
@@ -340,7 +340,6 @@ under the License.
         <groupId>org.apache.maven.wagon</groupId>
         <artifactId>wagon-http</artifactId>
         <version>${wagonVersion}</version>
-        <classifier>shaded</classifier>
       </dependency>
       <!--  Repository -->
       <dependency>
@@ -368,6 +367,16 @@ under the License.
         <artifactId>maven-resolver-connector-basic</artifactId>
         <version>${resolverVersion}</version>
       </dependency>
+      <dependency>
+        <groupId>org.apache.maven.resolver</groupId>
+        <artifactId>maven-resolver-transport-file</artifactId>
+        <version>${resolverVersion}</version>
+      </dependency>
+      <dependency>
+        <groupId>org.apache.maven.resolver</groupId>
+        <artifactId>maven-resolver-transport-http</artifactId>
+        <version>${resolverVersion}</version>
+      </dependency>
       <dependency>
         <groupId>org.apache.maven.resolver</groupId>
         <artifactId>maven-resolver-transport-wagon</artifactId>