From 61f1f0160eb5fc681b1443226e94dcfe170205d4 Mon Sep 17 00:00:00 2001 From: Slawomir Jaranowski Date: Sat, 5 Nov 2022 17:21:11 +0100 Subject: [PATCH] [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 d00bdc09aee1..b528ce59dcae 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.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 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 DefaultRepositorySystemSession newRepositorySession( MavenExecutionReques 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 @@ private void setUpLocalRepositoryManager( MavenExecutionRequest request, Default } } + private Map getPropertiesFromRequestedProfiles( MavenExecutionRequest request ) + { + List activeProfileId = request.getActiveProfiles(); + Map 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();