From fa9735291fe1e377e5a4316b86a16824e9791974 Mon Sep 17 00:00:00 2001 From: Jason van Zyl Date: Wed, 6 Oct 2004 14:30:00 +0000 Subject: [PATCH] o putting into play the use of the artifact filter during the transitive collection of artifacts. -> I was previously using a an exclude list but that was only taking into account the top-level pass of the artifacts so what was happening was things like maven-core weren't going in repeatedly but all of maven-core's deps were going in repeatedly. So by using the filter in the collector that sort of behaviour is stopped and now I can make the filter do anything I want to account for any weirdisms I subsequently encounter. git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163185 13f79535-47bb-0310-9956-ffa450edef68 --- .../artifact/resolver/ArtifactResolver.java | 17 ++++-- .../resolver/DefaultArtifactResolver.java | 52 ++++++++++++++++--- 2 files changed, 58 insertions(+), 11 deletions(-) diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/ArtifactResolver.java b/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/ArtifactResolver.java index 3d5b19c580..aa1799a1c3 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/ArtifactResolver.java +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/ArtifactResolver.java @@ -1,9 +1,9 @@ package org.apache.maven.artifact.resolver; import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.resolver.filter.ArtifactFilter; +import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.metadata.ArtifactMetadataSource; -import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import java.util.Set; @@ -23,13 +23,15 @@ public interface ArtifactResolver Set remoteRepositories, ArtifactRepository localRepository ) throws ArtifactResolutionException; - + ArtifactResolutionResult resolveTransitively( Artifact artifact, Set remoteRepositories, ArtifactRepository localRepository, ArtifactMetadataSource source ) throws ArtifactResolutionException; + + Set resolve( Set artifacts, Set remoteRepositories, ArtifactRepository localRepository ) @@ -40,4 +42,13 @@ public interface ArtifactResolver ArtifactRepository localRepository, ArtifactMetadataSource source ) throws ArtifactResolutionException; + + ArtifactResolutionResult resolveTransitively( Set artifacts, + Set remoteRepositories, + ArtifactRepository localRepository, + ArtifactMetadataSource source, + ArtifactFilter filter ) + throws ArtifactResolutionException; + + } diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java b/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java index e7d24cfee7..8963069522 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java @@ -2,10 +2,11 @@ package org.apache.maven.artifact.resolver; import org.apache.maven.artifact.AbstractArtifactComponent; import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.resolver.filter.ArtifactFilter; import org.apache.maven.artifact.handler.manager.ArtifactHandlerNotFoundException; import org.apache.maven.artifact.manager.WagonManager; -import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; +import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.wagon.TransferFailedException; @@ -117,7 +118,8 @@ public class DefaultArtifactResolver public ArtifactResolutionResult resolveTransitively( Set artifacts, Set remoteRepositories, ArtifactRepository localRepository, - ArtifactMetadataSource source ) + ArtifactMetadataSource source, + ArtifactFilter filter ) throws ArtifactResolutionException { ArtifactResolutionResult artifactResolutionResult; @@ -127,7 +129,8 @@ public class DefaultArtifactResolver artifactResolutionResult = collect( artifacts, localRepository, remoteRepositories, - source ); + source, + filter ); } catch ( TransitiveArtifactResolutionException e ) { @@ -142,6 +145,15 @@ public class DefaultArtifactResolver return artifactResolutionResult; } + public ArtifactResolutionResult resolveTransitively( Set artifacts, + Set remoteRepositories, + ArtifactRepository localRepository, + ArtifactMetadataSource source ) + throws ArtifactResolutionException + { + return resolveTransitively( artifacts, remoteRepositories, localRepository, source, null ); + } + public ArtifactResolutionResult resolveTransitively( Artifact artifact, Set remoteRepositories, ArtifactRepository localRepository, @@ -160,10 +172,11 @@ public class DefaultArtifactResolver // // ---------------------------------------------------------------------- - public ArtifactResolutionResult collect( Set artifacts, - ArtifactRepository localRepository, - Set remoteRepositories, - ArtifactMetadataSource source ) + protected ArtifactResolutionResult collect( Set artifacts, + ArtifactRepository localRepository, + Set remoteRepositories, + ArtifactMetadataSource source, + ArtifactFilter filter ) throws TransitiveArtifactResolutionException { ArtifactResolutionResult result = new ArtifactResolutionResult(); @@ -199,7 +212,15 @@ public class DefaultArtifactResolver } else { - //It's the first time we have encountered this artifact + // ---------------------------------------------------------------------- + // It's the first time we have encountered this artifact + // ---------------------------------------------------------------------- + + if ( filter != null && !filter.include( newArtifact.getArtifactId() ) ) + { + continue; + } + resolvedArtifacts.put( id, newArtifact ); Set referencedDependencies = null; @@ -219,8 +240,10 @@ public class DefaultArtifactResolver } } + // ---------------------------------------------------------------------- // the dependencies list is keyed by groupId+artifactId+type // so it must be 'rekeyed' to the complete id: groupId+artifactId+type+version + // ---------------------------------------------------------------------- Map artifactResult = result.getArtifacts(); @@ -260,4 +283,17 @@ public class DefaultArtifactResolver conflicts.add( newArtifact ); } + + protected boolean includeArtifact( String artifactId, String[] artifactExcludes ) + { + for ( int b = 0; b < artifactExcludes.length; b++ ) + { + if ( artifactId.equals( artifactExcludes[b] ) ) + { + return false; + } + } + + return true; + } }