From 02cbed3d5ab45caeda78352adf5db62ac413a694 Mon Sep 17 00:00:00 2001 From: Benjamin Bentmann Date: Fri, 30 Oct 2009 12:24:40 +0000 Subject: [PATCH] [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 --- .../resolver/DefaultArtifactResolver.java | 22 +++++- .../DefaultLegacyArtifactCollector.java | 13 ++-- .../resolver/LegacyArtifactCollector.java | 3 +- .../DefaultProjectDependenciesResolver.java | 3 + .../resolver/ArtifactResolutionRequest.java | 60 ++++++++++++++++ .../project/artifact/MavenMetadataSource.java | 26 ++++++- .../DefaultMetadataResolutionRequest.java | 70 +++++++++++++++++++ .../metadata/MetadataResolutionRequest.java | 15 ++++ 8 files changed, 204 insertions(+), 8 deletions(-) diff --git a/maven-compat/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java b/maven-compat/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java index e3a19fdfd1..90402808a5 100644 --- a/maven-compat/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java +++ b/maven-compat/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java @@ -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( 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 ) diff --git a/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/DefaultLegacyArtifactCollector.java b/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/DefaultLegacyArtifactCollector.java index 24a342c89c..24e71adf3a 100644 --- a/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/DefaultLegacyArtifactCollector.java +++ b/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/DefaultLegacyArtifactCollector.java @@ -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 listeners, List 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 artifacts, Artifact originatingArtifact, Map managedVersions, - RepositoryRequest repositoryRequest, + ArtifactResolutionRequest repositoryRequest, ArtifactMetadataSource source, ArtifactFilter filter, List listeners, @@ -226,7 +227,7 @@ public class DefaultLegacyArtifactCollector ResolutionNode node, Map> resolvedArtifacts, ManagedVersionMap managedVersions, - RepositoryRequest request, + ArtifactResolutionRequest request, ArtifactMetadataSource source, ArtifactFilter filter, List 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 ); } } diff --git a/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/LegacyArtifactCollector.java b/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/LegacyArtifactCollector.java index 9f31391fba..5e5738f0c1 100644 --- a/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/LegacyArtifactCollector.java +++ b/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/LegacyArtifactCollector.java @@ -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 artifacts, Artifact originatingArtifact, Map managedVersions, - RepositoryRequest repositoryRequest, + ArtifactResolutionRequest repositoryRequest, ArtifactMetadataSource source, ArtifactFilter filter, List listeners, diff --git a/maven-core/src/main/java/org/apache/maven/DefaultProjectDependenciesResolver.java b/maven-core/src/main/java/org/apache/maven/DefaultProjectDependenciesResolver.java index 37b0a2b8de..a1d49a398d 100644 --- a/maven-core/src/main/java/org/apache/maven/DefaultProjectDependenciesResolver.java +++ b/maven-core/src/main/java/org/apache/maven/DefaultProjectDependenciesResolver.java @@ -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 projectIds = null; diff --git a/maven-core/src/main/java/org/apache/maven/artifact/resolver/ArtifactResolutionRequest.java b/maven-core/src/main/java/org/apache/maven/artifact/resolver/ArtifactResolutionRequest.java index b21ec1531c..9720254c45 100644 --- a/maven-core/src/main/java/org/apache/maven/artifact/resolver/ArtifactResolutionRequest.java +++ b/maven-core/src/main/java/org/apache/maven/artifact/resolver/ArtifactResolutionRequest.java @@ -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 servers; + + private List mirrors; + + private List proxies; + public ArtifactResolutionRequest() { // nothing here @@ -288,4 +297,55 @@ public class ArtifactResolutionRequest return this; } + public ArtifactResolutionRequest setServers( List servers ) + { + this.servers = servers; + + return this; + } + + public List getServers() + { + if ( servers == null ) + { + servers = new ArrayList(); + } + + return servers; + } + + public ArtifactResolutionRequest setMirrors( List mirrors ) + { + this.mirrors = mirrors; + + return this; + } + + public List getMirrors() + { + if ( mirrors == null ) + { + mirrors = new ArrayList(); + } + + return mirrors; + } + + public ArtifactResolutionRequest setProxies( List proxies ) + { + this.proxies = proxies; + + return this; + } + + public List getProxies() + { + if ( proxies == null ) + { + proxies = new ArrayList(); + } + + return proxies; + } + } diff --git a/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java b/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java index 9134098cd8..1c113a6fb2 100644 --- a/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java +++ b/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java @@ -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 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(); } diff --git a/maven-core/src/main/java/org/apache/maven/repository/legacy/metadata/DefaultMetadataResolutionRequest.java b/maven-core/src/main/java/org/apache/maven/repository/legacy/metadata/DefaultMetadataResolutionRequest.java index 7b27e411fd..3671948187 100644 --- a/maven-core/src/main/java/org/apache/maven/repository/legacy/metadata/DefaultMetadataResolutionRequest.java +++ b/maven-core/src/main/java/org/apache/maven/repository/legacy/metadata/DefaultMetadataResolutionRequest.java @@ -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 servers; + + private List mirrors; + + private List 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 servers ) + { + this.servers = servers; + + return this; + } + + public List getServers() + { + if ( servers == null ) + { + servers = new ArrayList(); + } + + return servers; + } + + public MetadataResolutionRequest setMirrors( List mirrors ) + { + this.mirrors = mirrors; + + return this; + } + + public List getMirrors() + { + if ( mirrors == null ) + { + mirrors = new ArrayList(); + } + + return mirrors; + } + + public MetadataResolutionRequest setProxies( List proxies ) + { + this.proxies = proxies; + + return this; + } + + public List getProxies() + { + if ( proxies == null ) + { + proxies = new ArrayList(); + } + + return proxies; + } + } diff --git a/maven-core/src/main/java/org/apache/maven/repository/legacy/metadata/MetadataResolutionRequest.java b/maven-core/src/main/java/org/apache/maven/repository/legacy/metadata/MetadataResolutionRequest.java index 803057bd84..ba0f1c41ac 100644 --- a/maven-core/src/main/java/org/apache/maven/repository/legacy/metadata/MetadataResolutionRequest.java +++ b/maven-core/src/main/java/org/apache/maven/repository/legacy/metadata/MetadataResolutionRequest.java @@ -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 servers ); + + List getServers(); + + MetadataResolutionRequest setMirrors( List mirrors ); + + List getMirrors(); + + MetadataResolutionRequest setProxies( List proxies ); + + List getProxies(); + }