You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by mi...@apache.org on 2022/12/18 16:30:43 UTC

[maven] 01/02: [MNG-7590] Allow to configure resolver by properties in settings.xml

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

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

commit 386d2c8f09e81fac11e8eb71b7250bac24f2134f
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
    
    Cherry-pick from fa15fcf1536a6a5e92355ac8c91ecfa0301f016e
---
 .../DefaultRepositorySystemSessionFactory.java       | 20 ++++++++++++++++++++
 1 file changed, 20 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 60c6cf17a..b6bb609fa 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
@@ -24,6 +24,7 @@ import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
 import org.apache.maven.bridge.MavenRepositorySystem;
 import org.apache.maven.eventspy.internal.EventSpyDispatcher;
 import org.apache.maven.execution.MavenExecutionRequest;
+import org.apache.maven.model.ModelBase;
 import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
 import org.apache.maven.rtinfo.RuntimeInformation;
 import org.apache.maven.settings.Mirror;
@@ -54,8 +55,11 @@ import org.eclipse.sisu.Nullable;
 
 import javax.inject.Inject;
 import javax.inject.Named;
+
 import java.util.LinkedHashMap;
+import java.util.List;
 import java.util.Map;
+import java.util.stream.Collectors;
 
 /**
  * @since 3.3.0
@@ -104,6 +108,9 @@ 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( getPropertiesFromRequestedProfiles( 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() );
 
@@ -243,6 +250,19 @@ public class DefaultRepositorySystemSessionFactory
         return session;
     }
 
+    private Map<?, ?> getPropertiesFromRequestedProfiles( MavenExecutionRequest request )
+    {
+
+        List<String> activeProfileId =  request.getActiveProfiles();
+
+        return request.getProfiles().stream()
+            .filter( profile -> activeProfileId.contains( profile.getId() ) )
+            .map( ModelBase::getProperties )
+            .flatMap( properties -> properties.entrySet().stream() )
+            .collect(
+                Collectors.toMap( Map.Entry::getKey, Map.Entry::getValue, ( k1, k2 ) -> k2  ) );
+    }
+
     private String getUserAgent()
     {
         String version = runtimeInformation.getMavenVersion();