[MNG-4413] [regression] Repositories discovered in dependency POMs are not subject to mirroring

git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@831282 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2009-10-30 12:24:40 +00:00
parent 8c43be9fef
commit 02cbed3d5a
8 changed files with 204 additions and 8 deletions

View File

@ -104,6 +104,21 @@ public class DefaultArtifactResolver
if ( session != null )
{
request.setOffline( session.isOffline() );
request.setTransferListener( session.getRequest().getTransferListener() );
}
}
private void injectSession( ArtifactResolutionRequest request )
{
MavenSession session = legacySupport.getSession();
if ( session != null )
{
request.setOffline( session.isOffline() );
request.setServers( session.getRequest().getServers() );
request.setMirrors( session.getRequest().getMirrors() );
request.setProxies( session.getRequest().getProxies() );
request.setTransferListener( session.getRequest().getTransferListener() );
}
}
@ -457,7 +472,7 @@ public class DefaultArtifactResolver
}
}
RepositoryRequest collectionRequest = request;
ArtifactResolutionRequest collectionRequest = request;
if ( request.isResolveTransitively() )
{
@ -500,7 +515,10 @@ public class DefaultArtifactResolver
artifacts = new LinkedHashSet<Artifact>( mergedArtifacts.values() );
}
collectionRequest = new DefaultRepositoryRequest( request );
collectionRequest = new ArtifactResolutionRequest( request );
collectionRequest.setServers( request.getServers() );
collectionRequest.setMirrors( request.getMirrors() );
collectionRequest.setProxies( request.getProxies() );
collectionRequest.setRemoteRepositories( resolutionGroup.getResolutionRepositories() );
}
catch ( ArtifactMetadataRetrievalException e )

View File

@ -35,6 +35,7 @@ import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.DefaultRepositoryRequest;
import org.apache.maven.artifact.repository.RepositoryRequest;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactResolutionRequest;
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
import org.apache.maven.artifact.resolver.CyclicDependencyException;
import org.apache.maven.artifact.resolver.ResolutionListener;
@ -78,7 +79,7 @@ public class DefaultLegacyArtifactCollector
List<ResolutionListener> listeners,
List<ConflictResolver> conflictResolvers )
{
RepositoryRequest request = new DefaultRepositoryRequest();
ArtifactResolutionRequest request = new ArtifactResolutionRequest();
request.setLocalRepository( localRepository );
request.setRemoteRepositories( remoteRepositories );
return collect( artifacts, originatingArtifact, managedVersions, request, source, filter, listeners,
@ -88,7 +89,7 @@ public class DefaultLegacyArtifactCollector
public ArtifactResolutionResult collect( Set<Artifact> artifacts,
Artifact originatingArtifact,
Map managedVersions,
RepositoryRequest repositoryRequest,
ArtifactResolutionRequest repositoryRequest,
ArtifactMetadataSource source,
ArtifactFilter filter,
List<ResolutionListener> listeners,
@ -226,7 +227,7 @@ public class DefaultLegacyArtifactCollector
ResolutionNode node,
Map<Object, List<ResolutionNode>> resolvedArtifacts,
ManagedVersionMap managedVersions,
RepositoryRequest request,
ArtifactResolutionRequest request,
ArtifactMetadataSource source,
ArtifactFilter filter,
List<ResolutionListener> listeners,
@ -568,7 +569,11 @@ public class DefaultLegacyArtifactCollector
+ e.getMessage(), artifact, childRemoteRepositories, e );
}
recurse( result, child, resolvedArtifacts, managedVersions, metadataRequest, source, filter,
ArtifactResolutionRequest subRequest = new ArtifactResolutionRequest( metadataRequest );
subRequest.setServers( request.getServers() );
subRequest.setMirrors( request.getMirrors() );
subRequest.setProxies( request.getProxies() );
recurse( result, child, resolvedArtifacts, managedVersions, subRequest, source, filter,
listeners, conflictResolvers );
}
}

View File

@ -27,6 +27,7 @@ import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.RepositoryRequest;
import org.apache.maven.artifact.resolver.ArtifactResolutionRequest;
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
import org.apache.maven.artifact.resolver.ResolutionListener;
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
@ -46,7 +47,7 @@ public interface LegacyArtifactCollector
ArtifactResolutionResult collect( Set<Artifact> artifacts,
Artifact originatingArtifact,
Map managedVersions,
RepositoryRequest repositoryRequest,
ArtifactResolutionRequest repositoryRequest,
ArtifactMetadataSource source,
ArtifactFilter filter,
List<ResolutionListener> listeners,

View File

@ -136,6 +136,9 @@ public class DefaultProjectDependenciesResolver
.setForceUpdate( session.getRequest().isUpdateSnapshots() )
.setCache( session.getRepositoryCache() );
request.setTransferListener( session.getRequest().getTransferListener() );
request.setServers( session.getRequest().getServers() );
request.setMirrors( session.getRequest().getMirrors() );
request.setProxies( session.getRequest().getProxies() );
Set<String> projectIds = null;

View File

@ -30,6 +30,9 @@ import org.apache.maven.artifact.repository.RepositoryCache;
import org.apache.maven.artifact.repository.RepositoryRequest;
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
import org.apache.maven.repository.ArtifactTransferListener;
import org.apache.maven.settings.Mirror;
import org.apache.maven.settings.Proxy;
import org.apache.maven.settings.Server;
/**
* A resolution request allows you to either use an existing MavenProject, or a coordinate (gid:aid:version)
@ -74,6 +77,12 @@ public class ArtifactResolutionRequest
private boolean forceUpdate;
private List<Server> servers;
private List<Mirror> mirrors;
private List<Proxy> proxies;
public ArtifactResolutionRequest()
{
// nothing here
@ -288,4 +297,55 @@ public class ArtifactResolutionRequest
return this;
}
public ArtifactResolutionRequest setServers( List<Server> servers )
{
this.servers = servers;
return this;
}
public List<Server> getServers()
{
if ( servers == null )
{
servers = new ArrayList<Server>();
}
return servers;
}
public ArtifactResolutionRequest setMirrors( List<Mirror> mirrors )
{
this.mirrors = mirrors;
return this;
}
public List<Mirror> getMirrors()
{
if ( mirrors == null )
{
mirrors = new ArrayList<Mirror>();
}
return mirrors;
}
public ArtifactResolutionRequest setProxies( List<Proxy> proxies )
{
this.proxies = proxies;
return this;
}
public List<Proxy> getProxies()
{
if ( proxies == null )
{
proxies = new ArrayList<Proxy>();
}
return proxies;
}
}

View File

@ -48,12 +48,14 @@ import org.apache.maven.artifact.versioning.ArtifactVersion;
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
import org.apache.maven.artifact.versioning.VersionRange;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.DependencyManagement;
import org.apache.maven.model.DistributionManagement;
import org.apache.maven.model.Exclusion;
import org.apache.maven.model.Relocation;
import org.apache.maven.model.building.ModelBuildingRequest;
import org.apache.maven.plugin.LegacySupport;
import org.apache.maven.project.DefaultProjectBuildingRequest;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.ProjectBuilder;
@ -93,6 +95,23 @@ public class MavenMetadataSource
@Requirement
private MavenMetadataCache cache;
@Requirement
private LegacySupport legacySupport;
private void injectSession( MetadataResolutionRequest request )
{
MavenSession session = legacySupport.getSession();
if ( session != null )
{
request.setOffline( session.isOffline() );
request.setServers( session.getRequest().getServers() );
request.setMirrors( session.getRequest().getMirrors() );
request.setProxies( session.getRequest().getProxies() );
request.setTransferListener( session.getRequest().getTransferListener() );
}
}
public ResolutionGroup retrieve( Artifact artifact, ArtifactRepository localRepository,
List<ArtifactRepository> remoteRepositories )
throws ArtifactMetadataRetrievalException
@ -105,6 +124,7 @@ public class MavenMetadataSource
throws ArtifactMetadataRetrievalException
{
MetadataResolutionRequest request = new DefaultMetadataResolutionRequest();
injectSession( request );
request.setArtifact( artifact );
request.setLocalRepository( localRepository );
request.setRemoteRepositories( remoteRepositories );
@ -391,6 +411,7 @@ public class MavenMetadataSource
throws ArtifactMetadataRetrievalException
{
MetadataResolutionRequest request = new DefaultMetadataResolutionRequest();
injectSession( request );
request.setArtifact( artifact );
request.setLocalRepository( localRepository );
request.setRemoteRepositories( remoteRepositories );
@ -503,7 +524,7 @@ public class MavenMetadataSource
return projectBuilder;
}
private ProjectRelocation retrieveRelocatedProject( Artifact artifact, RepositoryRequest repositoryRequest )
private ProjectRelocation retrieveRelocatedProject( Artifact artifact, MetadataResolutionRequest repositoryRequest )
throws ArtifactMetadataRetrievalException
{
MavenProject project;
@ -543,6 +564,9 @@ public class MavenMetadataSource
configuration.setProcessPlugins( false );
configuration.setSystemProperties( System.getProperties() );
configuration.setTransferListener( repositoryRequest.getTransferListener() );
configuration.setServers( repositoryRequest.getServers() );
configuration.setMirrors( repositoryRequest.getMirrors() );
configuration.setProxies( repositoryRequest.getProxies() );
project = getProjectBuilder().build( pomArtifact, configuration ).getProject();
}

View File

@ -19,6 +19,7 @@ package org.apache.maven.repository.legacy.metadata;
* under the License.
*/
import java.util.ArrayList;
import java.util.List;
import org.apache.maven.artifact.Artifact;
@ -26,7 +27,11 @@ import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.DefaultRepositoryRequest;
import org.apache.maven.artifact.repository.RepositoryCache;
import org.apache.maven.artifact.repository.RepositoryRequest;
import org.apache.maven.artifact.resolver.ArtifactResolutionRequest;
import org.apache.maven.repository.ArtifactTransferListener;
import org.apache.maven.settings.Mirror;
import org.apache.maven.settings.Proxy;
import org.apache.maven.settings.Server;
/**
* Forms a request to retrieve artifact metadata.
@ -43,6 +48,12 @@ public class DefaultMetadataResolutionRequest
private RepositoryRequest repositoryRequest;
private List<Server> servers;
private List<Mirror> mirrors;
private List<Proxy> proxies;
public DefaultMetadataResolutionRequest()
{
repositoryRequest = new DefaultRepositoryRequest();
@ -53,6 +64,14 @@ public class DefaultMetadataResolutionRequest
this.repositoryRequest = new DefaultRepositoryRequest( repositoryRequest );
}
public DefaultMetadataResolutionRequest( ArtifactResolutionRequest resolutionRequest )
{
this.repositoryRequest = new DefaultRepositoryRequest( resolutionRequest );
setServers( resolutionRequest.getServers() );
setMirrors( resolutionRequest.getMirrors() );
setProxies( resolutionRequest.getProxies() );
}
public Artifact getArtifact()
{
return artifact;
@ -149,4 +168,55 @@ public class DefaultMetadataResolutionRequest
return this;
}
public MetadataResolutionRequest setServers( List<Server> servers )
{
this.servers = servers;
return this;
}
public List<Server> getServers()
{
if ( servers == null )
{
servers = new ArrayList<Server>();
}
return servers;
}
public MetadataResolutionRequest setMirrors( List<Mirror> mirrors )
{
this.mirrors = mirrors;
return this;
}
public List<Mirror> getMirrors()
{
if ( mirrors == null )
{
mirrors = new ArrayList<Mirror>();
}
return mirrors;
}
public MetadataResolutionRequest setProxies( List<Proxy> proxies )
{
this.proxies = proxies;
return this;
}
public List<Proxy> getProxies()
{
if ( proxies == null )
{
proxies = new ArrayList<Proxy>();
}
return proxies;
}
}

View File

@ -25,6 +25,9 @@ import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.RepositoryCache;
import org.apache.maven.artifact.repository.RepositoryRequest;
import org.apache.maven.settings.Mirror;
import org.apache.maven.settings.Proxy;
import org.apache.maven.settings.Server;
/**
* Forms a request to retrieve artifact metadata.
@ -126,4 +129,16 @@ public interface MetadataResolutionRequest
*/
MetadataResolutionRequest setResolveManagedVersions( boolean resolveManagedVersions );
MetadataResolutionRequest setServers( List<Server> servers );
List<Server> getServers();
MetadataResolutionRequest setMirrors( List<Mirror> mirrors );
List<Mirror> getMirrors();
MetadataResolutionRequest setProxies( List<Proxy> proxies );
List<Proxy> getProxies();
}