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/09 23:03:43 UTC

[maven] branch MNG-7590-3.9 created (now a5844634d)

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

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


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

This branch includes the following new commits:

     new a5844634d [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-3.9
in repository https://gitbox.apache.org/repos/asf/maven.git

commit a5844634d375d52bf1ec4f0d2e3f37000777788e
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
---
 .../aether/DefaultRepositorySystemSessionFactory.java | 19 +++++++++++++++++++
 1 file changed, 19 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 cdedab2de..8c8e7fc12 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
@@ -123,6 +127,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( 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() );
@@ -302,6 +308,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();