o Collected repo settings in request

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@810174 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2009-09-01 19:03:27 +00:00
parent 6615239fc8
commit b8b148cf8b
5 changed files with 166 additions and 60 deletions

View File

@ -26,6 +26,9 @@
import org.apache.maven.model.Profile; import org.apache.maven.model.Profile;
import org.apache.maven.project.DefaultProjectBuildingRequest; import org.apache.maven.project.DefaultProjectBuildingRequest;
import org.apache.maven.project.ProjectBuildingRequest; import org.apache.maven.project.ProjectBuildingRequest;
import org.apache.maven.settings.Mirror;
import org.apache.maven.settings.Proxy;
import org.apache.maven.settings.Server;
import org.apache.maven.settings.Settings; import org.apache.maven.settings.Settings;
import org.apache.maven.wagon.events.TransferListener; import org.apache.maven.wagon.events.TransferListener;
@ -46,11 +49,11 @@ public class DefaultMavenExecutionRequest
private boolean interactiveMode = true; private boolean interactiveMode = true;
private List proxies; private List<Proxy> proxies;
private List servers; private List<Server> servers;
private List mirrors; private List<Mirror> mirrors;
private List<Profile> profiles; private List<Profile> profiles;
@ -619,20 +622,20 @@ public MavenExecutionRequest setGlobalChecksumPolicy( String globalChecksumPolic
// Settings equivalents // Settings equivalents
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
public List getProxies() public List<Proxy> getProxies()
{ {
if ( proxies == null ) if ( proxies == null )
{ {
proxies = new ArrayList(); proxies = new ArrayList<Proxy>();
} }
return proxies; return proxies;
} }
public MavenExecutionRequest setProxies( List proxies ) public MavenExecutionRequest setProxies( List<Proxy> proxies )
{ {
if ( proxies != null ) if ( proxies != null )
{ {
this.proxies = new ArrayList( proxies ); this.proxies = new ArrayList<Proxy>( proxies );
} }
else else
{ {
@ -642,20 +645,40 @@ public MavenExecutionRequest setProxies( List proxies )
return this; return this;
} }
public List getServers() public MavenExecutionRequest addProxy( Proxy proxy )
{
if ( proxy == null )
{
throw new IllegalArgumentException( "proxy missing" );
}
for ( Proxy p : getProxies() )
{
if ( p.getId() != null && p.getId().equals( proxy.getId() ) )
{
return this;
}
}
getProxies().add( proxy );
return this;
}
public List<Server> getServers()
{ {
if ( servers == null ) if ( servers == null )
{ {
servers = new ArrayList(); servers = new ArrayList<Server>();
} }
return servers; return servers;
} }
public MavenExecutionRequest setServers( List servers ) public MavenExecutionRequest setServers( List<Server> servers )
{ {
if ( servers != null ) if ( servers != null )
{ {
this.servers = new ArrayList( servers ); this.servers = new ArrayList<Server>( servers );
} }
else else
{ {
@ -665,20 +688,40 @@ public MavenExecutionRequest setServers( List servers )
return this; return this;
} }
public List getMirrors() public MavenExecutionRequest addServer( Server server )
{
if ( server == null )
{
throw new IllegalArgumentException( "server missing" );
}
for ( Server p : getServers() )
{
if ( p.getId() != null && p.getId().equals( server.getId() ) )
{
return this;
}
}
getServers().add( server );
return this;
}
public List<Mirror> getMirrors()
{ {
if ( mirrors == null ) if ( mirrors == null )
{ {
mirrors = new ArrayList(); mirrors = new ArrayList<Mirror>();
} }
return mirrors; return mirrors;
} }
public MavenExecutionRequest setMirrors( List mirrors ) public MavenExecutionRequest setMirrors( List<Mirror> mirrors )
{ {
if ( mirrors != null ) if ( mirrors != null )
{ {
this.mirrors = new ArrayList( mirrors ); this.mirrors = new ArrayList<Mirror>( mirrors );
} }
else else
{ {
@ -688,6 +731,26 @@ public MavenExecutionRequest setMirrors( List mirrors )
return this; return this;
} }
public MavenExecutionRequest addMirror( Mirror mirror )
{
if ( mirror == null )
{
throw new IllegalArgumentException( "mirror missing" );
}
for ( Mirror p : getMirrors() )
{
if ( p.getId() != null && p.getId().equals( mirror.getId() ) )
{
return this;
}
}
getMirrors().add( mirror );
return this;
}
public List<Profile> getProfiles() public List<Profile> getProfiles()
{ {
if ( profiles == null ) if ( profiles == null )

View File

@ -29,6 +29,9 @@
import org.apache.maven.artifact.repository.RepositoryCache; import org.apache.maven.artifact.repository.RepositoryCache;
import org.apache.maven.model.Profile; import org.apache.maven.model.Profile;
import org.apache.maven.project.ProjectBuildingRequest; import org.apache.maven.project.ProjectBuildingRequest;
import org.apache.maven.settings.Mirror;
import org.apache.maven.settings.Proxy;
import org.apache.maven.settings.Server;
import org.apache.maven.settings.Settings; import org.apache.maven.settings.Settings;
import org.apache.maven.wagon.events.TransferListener; import org.apache.maven.wagon.events.TransferListener;
import org.codehaus.plexus.logging.Logger; import org.codehaus.plexus.logging.Logger;
@ -207,16 +210,19 @@ public interface MavenExecutionRequest
List<String> getInactiveProfiles(); List<String> getInactiveProfiles();
// Proxies // Proxies
List getProxies(); List<Proxy> getProxies();
MavenExecutionRequest setProxies( List proxies ); MavenExecutionRequest setProxies( List<Proxy> proxies );
MavenExecutionRequest addProxy( Proxy proxy );
// Servers // Servers
List getServers(); List<Server> getServers();
MavenExecutionRequest setServers( List servers ); MavenExecutionRequest setServers( List<Server> servers );
MavenExecutionRequest addServer( Server server );
// Mirrors // Mirrors
List getMirrors(); List<Mirror> getMirrors();
MavenExecutionRequest setMirrors( List mirrors ); MavenExecutionRequest setMirrors( List<Mirror> mirrors );
MavenExecutionRequest addMirror( Mirror mirror );
// Plugin groups // Plugin groups
List<String> getPluginGroups(); List<String> getPluginGroups();

View File

@ -48,6 +48,8 @@ public class MavenSession
private MavenExecutionResult result; private MavenExecutionResult result;
private final Settings settings;
private Properties executionProperties; private Properties executionProperties;
private MavenProject currentProject; private MavenProject currentProject;
@ -76,6 +78,7 @@ public MavenSession( PlexusContainer container, MavenExecutionRequest request, M
this.container = container; this.container = container;
this.request = request; this.request = request;
this.result = result; this.result = result;
this.settings = new SettingsAdapter( request );
setProjects( projects ); setProjects( projects );
} }
@ -84,6 +87,7 @@ public MavenSession( PlexusContainer container, MavenExecutionRequest request, M
this.container = container; this.container = container;
this.request = request; this.request = request;
this.result = result; this.result = result;
this.settings = new SettingsAdapter( request );
} }
public void setProjects( List<MavenProject> projects ) public void setProjects( List<MavenProject> projects )
@ -118,14 +122,14 @@ public Object lookup( String role, String roleHint )
} }
@Deprecated @Deprecated
public List lookupList( String role ) public List<Object> lookupList( String role )
throws ComponentLookupException throws ComponentLookupException
{ {
return container.lookupList( role ); return container.lookupList( role );
} }
@Deprecated @Deprecated
public Map lookupMap( String role ) public Map<String, Object> lookupMap( String role )
throws ComponentLookupException throws ComponentLookupException
{ {
return container.lookupMap( role ); return container.lookupMap( role );
@ -187,7 +191,7 @@ public Properties getExecutionProperties()
public Settings getSettings() public Settings getSettings()
{ {
return request.getSettings(); return settings;
} }
public List<MavenProject> getProjects() public List<MavenProject> getProjects()

View File

@ -1,4 +1,4 @@
package org.apache.maven.embedder.execution; package org.apache.maven.execution;
/* /*
* Licensed to the Apache Software Foundation (ASF) under one * Licensed to the Apache Software Foundation (ASF) under one
@ -21,8 +21,11 @@
import java.util.List; import java.util.List;
import org.apache.maven.execution.MavenExecutionRequest; import org.apache.maven.settings.Mirror;
import org.apache.maven.settings.Profile;
import org.apache.maven.settings.Proxy;
import org.apache.maven.settings.RuntimeInfo; import org.apache.maven.settings.RuntimeInfo;
import org.apache.maven.settings.Server;
import org.apache.maven.settings.Settings; import org.apache.maven.settings.Settings;
/** /**
@ -33,20 +36,21 @@
* *
* @author Jason van Zyl * @author Jason van Zyl
*/ */
public class SettingsAdapter class SettingsAdapter
extends Settings extends Settings
{ {
private MavenExecutionRequest request; private MavenExecutionRequest request;
private Settings settings;
private RuntimeInfo runtimeInfo; private RuntimeInfo runtimeInfo;
public SettingsAdapter( MavenExecutionRequest request, Settings settings ) public SettingsAdapter( MavenExecutionRequest request )
{ {
this.request = request; this.request = request;
this.settings = settings;
this.runtimeInfo = new RuntimeInfo( request.getUserSettingsFile() ); this.runtimeInfo = new RuntimeInfo( request.getUserSettingsFile() );
} }
@Override
public String getLocalRepository() public String getLocalRepository()
{ {
if ( request.getLocalRepositoryPath() != null ) if ( request.getLocalRepositoryPath() != null )
@ -54,53 +58,61 @@ public String getLocalRepository()
return request.getLocalRepositoryPath().getAbsolutePath(); return request.getLocalRepositoryPath().getAbsolutePath();
} }
return settings.getLocalRepository(); return null;
} }
@Override
public boolean isInteractiveMode() public boolean isInteractiveMode()
{ {
return request.isInteractiveMode(); return request.isInteractiveMode();
} }
@Override
public boolean isOffline() public boolean isOffline()
{ {
return request.isOffline(); return request.isOffline();
} }
// These we are not setting in the execution request currently @Override
public List<Proxy> getProxies()
public List getProxies()
{ {
return settings.getProxies(); return request.getProxies();
} }
public List getServers() @Override
public List<Server> getServers()
{ {
return settings.getServers(); return request.getServers();
} }
public List getMirrors() @Override
public List<Mirror> getMirrors()
{ {
return settings.getMirrors(); return request.getMirrors();
} }
public List getProfiles() @Override
public List<Profile> getProfiles()
{ {
return settings.getProfiles(); return request.getSettings().getProfiles();
} }
public List getActiveProfiles() @Override
public List<String> getActiveProfiles()
{ {
return settings.getActiveProfiles(); return request.getActiveProfiles();
} }
public List getPluginGroups() @Override
public List<String> getPluginGroups()
{ {
return settings.getPluginGroups(); return request.getPluginGroups();
} }
@Override
public RuntimeInfo getRuntimeInfo() public RuntimeInfo getRuntimeInfo()
{ {
return runtimeInfo; return runtimeInfo;
} }
} }

View File

@ -101,8 +101,6 @@ private void processSettings( MavenExecutionRequest request )
populateDefaultPluginGroups( request ); populateDefaultPluginGroups( request );
List<org.apache.maven.settings.Profile> settingsProfiles = settings.getProfiles();
// We just need to keep track of what profiles are being activated by the settings. We don't need to process // We just need to keep track of what profiles are being activated by the settings. We don't need to process
// them here. This should be taken care of by the project builder. // them here. This should be taken care of by the project builder.
// //
@ -111,6 +109,8 @@ private void processSettings( MavenExecutionRequest request )
// We only need to take the profiles and make sure they are available when the calculation of the active profiles // We only need to take the profiles and make sure they are available when the calculation of the active profiles
// is determined. // is determined.
// //
List<org.apache.maven.settings.Profile> settingsProfiles = settings.getProfiles();
if ( ( settingsProfiles != null ) && !settingsProfiles.isEmpty() ) if ( ( settingsProfiles != null ) && !settingsProfiles.isEmpty() )
{ {
for ( org.apache.maven.settings.Profile rawProfile : settings.getProfiles() ) for ( org.apache.maven.settings.Profile rawProfile : settings.getProfiles() )
@ -194,30 +194,51 @@ private void processRepositoriesInSettings( MavenExecutionRequest request )
// </proxy> // </proxy>
// </proxies> // </proxies>
Proxy proxy = settings.getActiveProxy(); Proxy activeProxy = settings.getActiveProxy();
if ( proxy != null ) if ( activeProxy != null )
{ {
if ( proxy.getHost() == null ) if ( activeProxy.getHost() == null )
{ {
throw new MavenEmbedderException( "Proxy in settings.xml has no host" ); throw new MavenEmbedderException( "Proxy in settings.xml has no host" );
} }
String password = decrypt( activeProxy.getPassword(), "password for proxy " + activeProxy.getId() );
repositorySystem.addProxy( activeProxy.getProtocol(), activeProxy.getHost(), activeProxy.getPort(),
activeProxy.getUsername(), password, activeProxy.getNonProxyHosts() );
}
for ( Proxy proxy : settings.getProxies() )
{
proxy = proxy.clone();
String password = decrypt( proxy.getPassword(), "password for proxy " + proxy.getId() ); String password = decrypt( proxy.getPassword(), "password for proxy " + proxy.getId() );
repositorySystem.addProxy( proxy.getProtocol(), proxy.getHost(), proxy.getPort(), proxy.getUsername(), proxy.setPassword( password );
password, proxy.getNonProxyHosts() );
request.addProxy( proxy );
} }
for ( Server server : settings.getServers() ) for ( Server server : settings.getServers() )
{ {
server = server.clone();
String password = decrypt( server.getPassword(), "password for server " + server.getId() ); String password = decrypt( server.getPassword(), "password for server " + server.getId() );
server.setPassword( password );
request.addServer( server );
repositorySystem.addAuthenticationForArtifactRepository( server.getId(), server.getUsername(), password ); repositorySystem.addAuthenticationForArtifactRepository( server.getId(), server.getUsername(), password );
} }
for ( Mirror mirror : settings.getMirrors() ) for ( Mirror mirror : settings.getMirrors() )
{ {
mirror = mirror.clone();
request.addMirror( mirror );
repositorySystem.addMirror( mirror.getId(), mirror.getMirrorOf(), mirror.getUrl() ); repositorySystem.addMirror( mirror.getId(), mirror.getMirrorOf(), mirror.getUrl() );
} }
@ -294,11 +315,11 @@ private void settings( MavenExecutionRequest request )
{ {
Settings settings = settingsBuilder.buildSettings( request ); Settings settings = settingsBuilder.buildSettings( request );
request.setSettings( new SettingsAdapter( request, settings ) ); request.setSettings( settings );
} }
catch ( Exception e ) catch ( Exception e )
{ {
request.setSettings( new SettingsAdapter( request, new Settings() ) ); request.setSettings( new Settings() );
} }
} }
} }