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 2022/11/05 16:21:34 UTC

[maven] branch MNG-7590 created (now 6b3087c39)

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

sjaranowski pushed a change to branch MNG-7590
in repository https://gitbox.apache.org/repos/asf/maven.git


      at 6b3087c39 [MNG-7590] Allow to configure resolver by properties in settings.xml

This branch includes the following new commits:

     new 6b3087c39 [MNG-7590] Allow to configure resolver by properties in settings.xml

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-7590] Allow to configure resolver by properties in settings.xml

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

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

commit 6b3087c39e5ff0866ecb4bac4a32a4ba219bfb39
Author: Slawomir Jaranowski <s....@gmail.com>
AuthorDate: Sat Nov 5 17:21:11 2022 +0100

    [MNG-7590] Allow to configure resolver by properties in settings.xml
---
 .../DefaultRepositorySystemSessionFactory.java     | 26 ++++++++++++++++++++++
 1 file changed, 26 insertions(+)

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 e238e3bf6..17d935276 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
@@ -25,6 +25,7 @@ import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.HashSet;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
@@ -42,6 +43,7 @@ import org.apache.maven.execution.MavenExecutionRequest;
 import org.apache.maven.feature.Features;
 import org.apache.maven.internal.xml.XmlPlexusConfiguration;
 import org.apache.maven.internal.xml.Xpp3Dom;
+import org.apache.maven.model.ModelBase;
 import org.apache.maven.model.building.TransformerContext;
 import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
 import org.apache.maven.rtinfo.RuntimeInformation;
@@ -150,6 +152,8 @@ public class DefaultRepositorySystemSessionFactory
         configProps.put( ConfigurationProperties.USER_AGENT, getUserAgent() );
         configProps.put( ConfigurationProperties.INTERACTIVE, request.isInteractiveMode() );
         configProps.put( "maven.startTime", request.getStartTime() );
+        // First add properties populated from settings.xml
+        configProps.putAll( getConfigFromRequestProfiles( request ) );
         // Resolver's ConfigUtils solely rely on config properties, that is why we need to add both here as well.
         configProps.putAll( request.getSystemProperties() );
         configProps.putAll( request.getUserProperties() );
@@ -313,6 +317,28 @@ public class DefaultRepositorySystemSessionFactory
         return session;
     }
 
+    private Map<?, ?> getConfigFromRequestProfiles( MavenExecutionRequest request )
+    {
+
+        HashSet<String> activeProfileId = new HashSet<>( request.getProfileActivation().getRequiredActiveProfileIds() );
+        activeProfileId.addAll( request.getProfileActivation().getOptionalActiveProfileIds() );
+
+        return request.getProfiles().stream()
+            .filter( profile -> activeProfileId.contains( profile.getId() ) )
+            .map( ModelBase::getProperties )
+            .flatMap( properties -> properties.entrySet().stream() )
+            .filter( entry -> isPropertyForResolver( entry.getKey().toString() ) )
+            .collect(
+                Collectors.toMap( Map.Entry::getKey, Map.Entry::getValue, ( k1, k2 ) -> k2  ) );
+    }
+
+    private boolean isPropertyForResolver( String propertyName )
+    {
+        return propertyName != null
+            && ( propertyName.startsWith( "maven.resolver." ) || propertyName.startsWith( "aether." ) );
+    }
+
+
     private String getUserAgent()
     {
         String version = runtimeInformation.getMavenVersion();