Skip to content

Commit

Permalink
[MNG-7590] Allow to configure resolver by properties in settings.xml
Browse files Browse the repository at this point in the history
  • Loading branch information
slawekjaranowski committed Nov 9, 2022
1 parent dfcf579 commit fa15fcf
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
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;
Expand All @@ -42,6 +43,7 @@
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;
Expand Down Expand Up @@ -150,6 +152,8 @@ 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() );
Expand Down Expand Up @@ -313,6 +317,20 @@ else if ( !MAVEN_RESOLVER_TRANSPORT_AUTO.equals( transport ) )
return session;
}

private Map<?, ?> getPropertiesFromRequestedProfiles( 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() )
.collect(
Collectors.toMap( Map.Entry::getKey, Map.Entry::getValue, ( k1, k2 ) -> k2 ) );
}

private String getUserAgent()
{
String version = runtimeInformation.getMavenVersion();
Expand Down

0 comments on commit fa15fcf

Please sign in to comment.