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/12/18 22:05:17 UTC

[maven] branch MNG-7590-3.8.x created (now 1dddd890d)

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

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


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

This branch includes the following new commits:

     new 1dddd890d [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.8.x
in repository https://gitbox.apache.org/repos/asf/maven.git

commit 1dddd890d586865238a0d7ce1c35457721eecffa
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      | 21 +++++++++++++++++++++
 1 file changed, 21 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 d00bdc09a..b528ce59d 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.Profile;
 import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
 import org.apache.maven.rtinfo.RuntimeInformation;
 import org.apache.maven.settings.Mirror;
@@ -54,7 +55,10 @@ import org.eclipse.sisu.Nullable;
 
 import javax.inject.Inject;
 import javax.inject.Named;
+
+import java.util.HashMap;
 import java.util.LinkedHashMap;
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -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() );
 
@@ -247,6 +254,20 @@ public class DefaultRepositorySystemSessionFactory
         }
     }
 
+    private Map<?, ?> getPropertiesFromRequestedProfiles( MavenExecutionRequest request )
+    {
+        List<String> activeProfileId =  request.getActiveProfiles();
+        Map<Object, Object> result = new HashMap<>();
+        for ( Profile profile: request.getProfiles() )
+        {
+            if ( activeProfileId.contains( profile.getId() ) )
+            {
+                result.putAll( profile.getProperties() );
+            }
+        }
+        return result;
+    }
+
     private String getUserAgent()
     {
         String version = runtimeInformation.getMavenVersion();