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
Cherry-pick from fa15fcf
  • Loading branch information
slawekjaranowski committed Dec 19, 2022
1 parent 8fd8a05 commit 61f1f01
Showing 1 changed file with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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() );

Expand Down Expand Up @@ -247,6 +254,20 @@ private void setUpLocalRepositoryManager( MavenExecutionRequest request, Default
}
}

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();
Expand Down

0 comments on commit 61f1f01

Please sign in to comment.