mirror of https://github.com/apache/maven.git
[MNG-7590] Allow to configure resolver by properties in settings.xml
This commit is contained in:
parent
dfcf5791fc
commit
fa15fcf153
|
@ -25,6 +25,7 @@ import java.io.InputStream;
|
|||
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;
|
||||
|
@ -42,6 +43,7 @@ import org.apache.maven.execution.MavenExecutionRequest;
|
|||
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;
|
||||
|
@ -150,6 +152,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() );
|
||||
|
@ -313,6 +317,20 @@ public class DefaultRepositorySystemSessionFactory
|
|||
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();
|
||||
|
|
Loading…
Reference in New Issue