From 733866dfd4da19cd5b7a7548b46281991c72f3fd Mon Sep 17 00:00:00 2001 From: Brett Leslie Porter Date: Wed, 22 Jun 2005 07:51:16 +0000 Subject: [PATCH] implement managed versions in tests git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@191781 13f79535-47bb-0310-9956-ffa450edef68 --- .../artifact/resolver/ArtifactCollector.java | 3 ++- .../resolver/DefaultArtifactCollector.java | 26 ++++++++++++------- .../resolver/LegacyArtifactCollector.java | 4 +-- .../DefaultArtifactCollectorTest.java | 11 ++++---- 4 files changed, 27 insertions(+), 17 deletions(-) diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/ArtifactCollector.java b/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/ArtifactCollector.java index f7ea0e751c..18b95279f0 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/ArtifactCollector.java +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/ArtifactCollector.java @@ -24,6 +24,7 @@ import org.apache.maven.artifact.resolver.filter.ArtifactFilter; import java.util.List; import java.util.Set; +import java.util.Map; /** * Artifact collector - takes a set of original artifacts and resolves all of the best versions to use @@ -39,7 +40,7 @@ public interface ArtifactCollector ArtifactFactory artifactFactory ) throws ArtifactResolutionException; - ArtifactResolutionResult collect( Set artifacts, Artifact originatingArtifact, Set managedVersions, + ArtifactResolutionResult collect( Set artifacts, Artifact originatingArtifact, Map managedVersions, ArtifactRepository localRepository, List remoteRepositories, ArtifactMetadataSource source, ArtifactFilter filter, ArtifactFactory artifactFactory ) diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactCollector.java b/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactCollector.java index 395eaaa376..9befeefee4 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactCollector.java +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactCollector.java @@ -47,11 +47,11 @@ public class DefaultArtifactCollector ArtifactFactory artifactFactory ) throws ArtifactResolutionException { - return collect( artifacts, originatingArtifact, Collections.EMPTY_SET, localRepository, remoteRepositories, + return collect( artifacts, originatingArtifact, Collections.EMPTY_MAP, localRepository, remoteRepositories, source, filter, artifactFactory ); } - public ArtifactResolutionResult collect( Set artifacts, Artifact originatingArtifact, Set managedVersions, + public ArtifactResolutionResult collect( Set artifacts, Artifact originatingArtifact, Map managedVersions, ArtifactRepository localRepository, List remoteRepositories, ArtifactMetadataSource source, ArtifactFilter filter, ArtifactFactory artifactFactory ) @@ -62,7 +62,8 @@ public class DefaultArtifactCollector ResolutionNode root = new ResolutionNode( originatingArtifact ); root.addDependencies( artifacts, filter ); - recurse( root, resolvedArtifacts, localRepository, remoteRepositories, source, filter, artifactFactory ); + recurse( root, resolvedArtifacts, managedVersions, localRepository, remoteRepositories, source, filter, + artifactFactory ); Set set = new HashSet(); @@ -82,12 +83,19 @@ public class DefaultArtifactCollector return result; } - private void recurse( ResolutionNode node, Map resolvedArtifacts, ArtifactRepository localRepository, - List remoteRepositories, ArtifactMetadataSource source, ArtifactFilter filter, - ArtifactFactory artifactFactory ) + private void recurse( ResolutionNode node, Map resolvedArtifacts, Map managedVersions, + ArtifactRepository localRepository, List remoteRepositories, ArtifactMetadataSource source, + ArtifactFilter filter, ArtifactFactory artifactFactory ) throws ArtifactResolutionException { - ResolutionNode previous = (ResolutionNode) resolvedArtifacts.get( node.getKey() ); + // TODO: conflict resolvers, shouldn't be munging original artifact perhaps? + Object key = node.getKey(); + if ( managedVersions.containsKey( key ) ) + { + node.getArtifact().setVersion( (String) managedVersions.get( key ) ); + } + + ResolutionNode previous = (ResolutionNode) resolvedArtifacts.get( key ); if ( previous != null ) { // TODO: conflict resolvers @@ -158,7 +166,7 @@ public class DefaultArtifactCollector } } - resolvedArtifacts.put( node.getKey(), node ); + resolvedArtifacts.put( key, node ); for ( Iterator i = node.getChildrenIterator(); i.hasNext(); ) { @@ -176,7 +184,7 @@ public class DefaultArtifactCollector remoteRepositories, e ); } - recurse( child, resolvedArtifacts, localRepository, remoteRepositories, source, filter, + recurse( child, resolvedArtifacts, managedVersions, localRepository, remoteRepositories, source, filter, artifactFactory ); } } diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/LegacyArtifactCollector.java b/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/LegacyArtifactCollector.java index 7c154599d6..7dd567fc77 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/LegacyArtifactCollector.java +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/LegacyArtifactCollector.java @@ -48,11 +48,11 @@ public class LegacyArtifactCollector ArtifactFactory artifactFactory ) throws ArtifactResolutionException { - return collect( artifacts, originatingArtifact, Collections.EMPTY_SET, localRepository, remoteRepositories, + return collect( artifacts, originatingArtifact, Collections.EMPTY_MAP, localRepository, remoteRepositories, source, filter, artifactFactory ); } - public ArtifactResolutionResult collect( Set artifacts, Artifact originatingArtifact, Set managedVersions, + public ArtifactResolutionResult collect( Set artifacts, Artifact originatingArtifact, Map managedVersions, ArtifactRepository localRepository, List remoteRepositories, ArtifactMetadataSource source, ArtifactFilter filter, ArtifactFactory artifactFactory ) diff --git a/maven-artifact/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactCollectorTest.java b/maven-artifact/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactCollectorTest.java index 31c9115940..b2387f51f5 100644 --- a/maven-artifact/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactCollectorTest.java +++ b/maven-artifact/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactCollectorTest.java @@ -65,7 +65,7 @@ public class DefaultArtifactCollectorTest this.projectArtifact = createArtifact( "project", "1.0", null ); } - public void disabledtestCircularDependencyNotIncludingCurrentProject() + public void testCircularDependencyNotIncludingCurrentProject() throws ArtifactResolutionException { ArtifactSpec a = createArtifact( "a", "1.0" ); @@ -82,7 +82,7 @@ public class DefaultArtifactCollectorTest } } - public void disabledtestCircularDependencyIncludingCurrentProject() + public void testCircularDependencyIncludingCurrentProject() throws ArtifactResolutionException { ArtifactSpec a = createArtifact( "a", "1.0" ); @@ -132,7 +132,7 @@ public class DefaultArtifactCollectorTest res.getArtifacts() ); } - public void disabledtestResolveManagedVersion() + public void testResolveManagedVersion() throws ArtifactResolutionException { ArtifactSpec a = createArtifact( "a", "1.0" ); @@ -284,9 +284,10 @@ public class DefaultArtifactCollectorTest private ArtifactResolutionResult collect( ArtifactSpec a, Artifact managedVersion ) throws ArtifactResolutionException { + Map managedVersions = Collections.singletonMap( managedVersion.getDependencyConflictId(), + managedVersion.getVersion() ); return artifactCollector.collect( Collections.singleton( a.artifact ), projectArtifact.artifact, - Collections.singleton( managedVersion ), null, null, source, null, - artifactFactory ); + managedVersions, null, null, source, null, artifactFactory ); } private ArtifactSpec createArtifact( String id, String version )