[MNG-4334] maven core caches settings.xml

o Last pass: proxies moved out of the components into the requests

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@810444 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2009-09-02 10:16:19 +00:00
parent 7ed1358995
commit 102f4ab603
9 changed files with 101 additions and 39 deletions

View File

@ -85,9 +85,6 @@ public class LegacyRepositorySystem
@Requirement @Requirement
private PlexusContainer plexus; private PlexusContainer plexus;
// TODO: move this out, the component needs to be stateless for safe reuse
private Map<String, Proxy> proxies = new HashMap<String,Proxy>();
public Artifact createArtifact( String groupId, String artifactId, String version, String scope, String type ) public Artifact createArtifact( String groupId, String artifactId, String version, String scope, String type )
{ {
return artifactFactory.createArtifact( groupId, artifactId, version, scope, type ); return artifactFactory.createArtifact( groupId, artifactId, version, scope, type );
@ -379,6 +376,8 @@ public class LegacyRepositorySystem
effectiveRepository.setAuthentication( aliasedRepo.getAuthentication() ); effectiveRepository.setAuthentication( aliasedRepo.getAuthentication() );
effectiveRepository.setProxy( aliasedRepo.getProxy() );
effectiveRepositories.add( effectiveRepository ); effectiveRepositories.add( effectiveRepository );
} }
@ -531,6 +530,51 @@ public class LegacyRepositorySystem
} }
} }
private org.apache.maven.settings.Proxy getProxy( ArtifactRepository repository,
List<org.apache.maven.settings.Proxy> proxies )
{
if ( proxies != null && repository.getProtocol() != null )
{
for ( org.apache.maven.settings.Proxy proxy : proxies )
{
if ( proxy.isActive() && repository.getProtocol().equalsIgnoreCase( proxy.getProtocol() ) )
{
return proxy;
}
}
}
return null;
}
public void injectProxy( List<ArtifactRepository> repositories, List<org.apache.maven.settings.Proxy> proxies )
{
if ( repositories != null )
{
for ( ArtifactRepository repository : repositories )
{
org.apache.maven.settings.Proxy proxy = getProxy( repository, proxies );
if ( proxy != null )
{
Proxy p = new Proxy();
p.setHost( proxy.getHost() );
p.setProtocol( proxy.getProtocol() );
p.setPort( proxy.getPort() );
p.setNonProxyHosts( proxy.getNonProxyHosts() );
p.setUserName( proxy.getUsername() );
p.setPassword( proxy.getPassword() );
repository.setProxy( p );
}
else
{
repository.setProxy( null );
}
}
}
}
public MetadataResolutionResult resolveMetadata( MetadataResolutionRequest request ) public MetadataResolutionResult resolveMetadata( MetadataResolutionRequest request )
{ {
@ -612,25 +656,7 @@ public class LegacyRepositorySystem
ArtifactRepository artifactRepository = artifactRepositoryFactory.createArtifactRepository( repositoryId, url, repositoryLayout, snapshots, releases ); ArtifactRepository artifactRepository = artifactRepositoryFactory.createArtifactRepository( repositoryId, url, repositoryLayout, snapshots, releases );
Proxy proxy = proxies.get( artifactRepository.getProtocol() );
if ( proxy != null )
{
artifactRepository.setProxy( proxy );
}
return artifactRepository; return artifactRepository;
} }
public void addProxy( String protocol, String host, int port, String username, String password, String nonProxyHosts )
{
Proxy proxy = new Proxy();
proxy.setHost( host );
proxy.setProtocol( protocol );
proxy.setPort( port );
proxy.setNonProxyHosts( nonProxyHosts );
proxy.setUserName( username );
proxy.setPassword( password );
proxies.put( protocol, proxy );
}
} }

View File

@ -103,11 +103,22 @@ public interface RepositorySystem
*/ */
void injectMirror( List<ArtifactRepository> repositories, List<Mirror> mirrors ); void injectMirror( List<ArtifactRepository> repositories, List<Mirror> mirrors );
/**
* Injects the proxy information into the specified repositories. For each repository that is matched by a proxy,
* its proxy data will be set accordingly. Repositories without a matching proxy will have their proxy cleared.
* <em>Note:</em> This method must be called after {@link #injectMirror(List, List)} or the repositories will end up
* with the wrong proxies.
*
* @param repositories The repositories into which to inject the proxy information, may be {@code null}.
* @param proxies The available proxies, may be {@code null}.
*/
void injectProxy( List<ArtifactRepository> repositories, List<org.apache.maven.settings.Proxy> proxies );
/** /**
* Injects the authentication information into the specified repositories. For each repository that is matched by a * Injects the authentication information into the specified repositories. For each repository that is matched by a
* server, its credentials will be updated to match the values from the server specification. Repositories without a * server, its credentials will be updated to match the values from the server specification. Repositories without a
* matching server will have their credentials cleared. <em>Note:</em> This method must be called before * matching server will have their credentials cleared. <em>Note:</em> This method must be called after
* {@link #injectAuthentication(List, List)} or the repositories will end up with the wrong credentials. * {@link #injectMirror(List, List)} or the repositories will end up with the wrong credentials.
* *
* @param repositories The repositories into which to inject the authentication information, may be {@code null}. * @param repositories The repositories into which to inject the authentication information, may be {@code null}.
* @param servers The available servers, may be {@code null}. * @param servers The available servers, may be {@code null}.
@ -133,5 +144,4 @@ public interface RepositorySystem
void retrieve( ArtifactRepository repository, File destination, String remotePath, TransferListener downloadMonitor ) void retrieve( ArtifactRepository repository, File destination, String remotePath, TransferListener downloadMonitor )
throws TransferFailedException, ResourceDoesNotExistException; throws TransferFailedException, ResourceDoesNotExistException;
void addProxy( String protocol, String host, int port, String username, String password, String nonProxyHosts );
} }

View File

@ -967,6 +967,7 @@ public class DefaultMavenExecutionRequest
projectBuildingRequest.setOffline( isOffline() ); projectBuildingRequest.setOffline( isOffline() );
projectBuildingRequest.setServers( getServers() ); projectBuildingRequest.setServers( getServers() );
projectBuildingRequest.setMirrors( getMirrors() ); projectBuildingRequest.setMirrors( getMirrors() );
projectBuildingRequest.setProxies( getProxies() );
projectBuildingRequest.setActiveProfileIds( getActiveProfiles() ); projectBuildingRequest.setActiveProfileIds( getActiveProfiles() );
projectBuildingRequest.setInactiveProfileIds( getInactiveProfiles() ); projectBuildingRequest.setInactiveProfileIds( getInactiveProfiles() );
projectBuildingRequest.setProfiles( getProfiles() ); projectBuildingRequest.setProfiles( getProfiles() );

View File

@ -86,6 +86,7 @@ public class DefaultMavenProjectBuilder
{ {
ArtifactRepository repo = repositorySystem.buildArtifactRepository( (Repository) repository ); ArtifactRepository repo = repositorySystem.buildArtifactRepository( (Repository) repository );
repositorySystem.injectMirror( Arrays.asList( repo ), configuration.getMirrors() ); repositorySystem.injectMirror( Arrays.asList( repo ), configuration.getMirrors() );
repositorySystem.injectProxy( Arrays.asList( repo ), configuration.getProxies() );
repositorySystem.injectAuthentication( Arrays.asList( repo ), configuration.getServers() ); repositorySystem.injectAuthentication( Arrays.asList( repo ), configuration.getServers() );
repos.add( repo ); repos.add( repo );
} }

View File

@ -100,6 +100,8 @@ public class DefaultProjectBuildingHelper
repositorySystem.injectMirror( artifactRepositories, request.getMirrors() ); repositorySystem.injectMirror( artifactRepositories, request.getMirrors() );
repositorySystem.injectProxy( artifactRepositories, request.getProxies() );
repositorySystem.injectAuthentication( artifactRepositories, request.getServers() ); repositorySystem.injectAuthentication( artifactRepositories, request.getServers() );
if ( externalRepositories != null ) if ( externalRepositories != null )

View File

@ -30,6 +30,7 @@ import org.apache.maven.model.Profile;
import org.apache.maven.model.building.ModelBuildingRequest; import org.apache.maven.model.building.ModelBuildingRequest;
import org.apache.maven.model.building.ModelEventListener; import org.apache.maven.model.building.ModelEventListener;
import org.apache.maven.settings.Mirror; import org.apache.maven.settings.Mirror;
import org.apache.maven.settings.Proxy;
import org.apache.maven.settings.Server; import org.apache.maven.settings.Server;
public class DefaultProjectBuildingRequest public class DefaultProjectBuildingRequest
@ -50,6 +51,8 @@ public class DefaultProjectBuildingRequest
private List<Mirror> mirrors; private List<Mirror> mirrors;
private List<Proxy> proxies;
private List<ModelEventListener> listeners; private List<ModelEventListener> listeners;
private MavenProject project; private MavenProject project;
@ -87,6 +90,7 @@ public class DefaultProjectBuildingRequest
pluginArtifactRepositories = new ArrayList<ArtifactRepository>(); pluginArtifactRepositories = new ArrayList<ArtifactRepository>();
servers = new ArrayList<Server>(); servers = new ArrayList<Server>();
mirrors = new ArrayList<Mirror>(); mirrors = new ArrayList<Mirror>();
proxies = new ArrayList<Proxy>();
} }
public MavenProject getProject() public MavenProject getProject()
@ -210,6 +214,25 @@ public class DefaultProjectBuildingRequest
return mirrors; return mirrors;
} }
public ProjectBuildingRequest setProxies( List<Proxy> proxies )
{
if ( proxies != null )
{
this.proxies = new ArrayList<Proxy>( proxies );
}
else
{
this.proxies.clear();
}
return this;
}
public List<Proxy> getProxies()
{
return proxies;
}
public Properties getSystemProperties() public Properties getSystemProperties()
{ {
return systemProperties; return systemProperties;

View File

@ -28,6 +28,7 @@ import org.apache.maven.artifact.repository.RepositoryCache;
import org.apache.maven.model.Profile; import org.apache.maven.model.Profile;
import org.apache.maven.model.building.ModelBuildingRequest; import org.apache.maven.model.building.ModelBuildingRequest;
import org.apache.maven.settings.Mirror; import org.apache.maven.settings.Mirror;
import org.apache.maven.settings.Proxy;
import org.apache.maven.settings.Server; import org.apache.maven.settings.Server;
public interface ProjectBuildingRequest public interface ProjectBuildingRequest
@ -61,6 +62,10 @@ public interface ProjectBuildingRequest
List<Mirror> getMirrors(); List<Mirror> getMirrors();
ProjectBuildingRequest setProxies( List<Proxy> proxies );
List<Proxy> getProxies();
/** /**
* Sets the system properties to use for interpolation and profile activation. The system properties are collected * Sets the system properties to use for interpolation and profile activation. The system properties are collected
* from the runtime environment like {@link System#getProperties()} and environment variables. * from the runtime environment like {@link System#getProperties()} and environment variables.

View File

@ -102,6 +102,8 @@ class RepositoryModelResolver
repositorySystem.injectMirror( Arrays.asList( repo ), projectBuildingRequest.getMirrors() ); repositorySystem.injectMirror( Arrays.asList( repo ), projectBuildingRequest.getMirrors() );
repositorySystem.injectProxy( Arrays.asList( repo ), projectBuildingRequest.getProxies() );
repositorySystem.injectAuthentication( Arrays.asList( repo ), projectBuildingRequest.getServers() ); repositorySystem.injectAuthentication( Arrays.asList( repo ), projectBuildingRequest.getServers() );
remoteRepositories.add( 0, repo ); remoteRepositories.add( 0, repo );

View File

@ -194,23 +194,13 @@ public class DefaultMavenExecutionRequestPopulator
// </proxy> // </proxy>
// </proxies> // </proxies>
Proxy activeProxy = settings.getActiveProxy();
if ( activeProxy != null )
{
if ( activeProxy.getHost() == null )
{
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() ) for ( Proxy proxy : settings.getProxies() )
{ {
if ( !proxy.isActive() )
{
continue;
}
proxy = proxy.clone(); proxy = proxy.clone();
String password = decrypt( proxy.getPassword(), "password for proxy " + proxy.getId() ); String password = decrypt( proxy.getPassword(), "password for proxy " + proxy.getId() );
@ -247,11 +237,13 @@ public class DefaultMavenExecutionRequestPopulator
} }
repositorySystem.injectMirror( request.getRemoteRepositories(), request.getMirrors() ); repositorySystem.injectMirror( request.getRemoteRepositories(), request.getMirrors() );
repositorySystem.injectProxy( request.getRemoteRepositories(), request.getProxies() );
repositorySystem.injectAuthentication( request.getRemoteRepositories(), request.getServers() ); repositorySystem.injectAuthentication( request.getRemoteRepositories(), request.getServers() );
request.setRemoteRepositories( repositorySystem.getEffectiveRepositories( request.getRemoteRepositories() ) ); request.setRemoteRepositories( repositorySystem.getEffectiveRepositories( request.getRemoteRepositories() ) );
repositorySystem.injectMirror( request.getPluginArtifactRepositories(), request.getMirrors() ); repositorySystem.injectMirror( request.getPluginArtifactRepositories(), request.getMirrors() );
repositorySystem.injectProxy( request.getPluginArtifactRepositories(), request.getProxies() );
repositorySystem.injectAuthentication( request.getPluginArtifactRepositories(), request.getServers() ); repositorySystem.injectAuthentication( request.getPluginArtifactRepositories(), request.getServers() );
request.setPluginArtifactRepositories( repositorySystem.getEffectiveRepositories( request.getPluginArtifactRepositories() ) ); request.setPluginArtifactRepositories( repositorySystem.getEffectiveRepositories( request.getPluginArtifactRepositories() ) );