change artifact resolution result to have a set of artifacts instead of a map, as everything dealt with them as a collection anyway.

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@191748 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-06-22 00:31:33 +00:00
parent 748de75a58
commit 3bee4a55c1
8 changed files with 43 additions and 34 deletions

View File

@ -126,7 +126,7 @@ public class DependenciesTask
FileSet fileSet = new FileSet();
fileSet.setDir( fileList.getDir( getProject() ) );
for ( Iterator i = result.getArtifacts().values().iterator(); i.hasNext(); )
for ( Iterator i = result.getArtifacts().iterator(); i.hasNext(); )
{
Artifact artifact = (Artifact) i.next();
String filename = localRepo.pathOf( artifact );

View File

@ -157,7 +157,7 @@ public class DefaultArtifactResolver
artifactResolutionResult = artifactCollector.collect( artifacts, originatingArtifact, localRepository,
remoteRepositories, source, filter, artifactFactory );
for ( Iterator i = artifactResolutionResult.getArtifacts().values().iterator(); i.hasNext(); )
for ( Iterator i = artifactResolutionResult.getArtifacts().iterator(); i.hasNext(); )
{
Artifact artifact = (Artifact) i.next();
resolve( artifact, remoteRepositories, localRepository );

View File

@ -114,9 +114,9 @@ public class ArtifactResolverTest
assertEquals( 2, result.getArtifacts().size() );
assertTrue( result.getArtifacts().containsKey( g.getId() ) );
assertTrue( result.getArtifacts().contains( g ) );
assertTrue( result.getArtifacts().containsKey( h.getId() ) );
assertTrue( result.getArtifacts().contains( h ) );
assertLocalArtifactPresent( g );
@ -153,9 +153,9 @@ public class ArtifactResolverTest
assertEquals( 2, result.getArtifacts().size() );
assertTrue( result.getArtifacts().containsKey( i.getId() ) );
assertTrue( result.getArtifacts().contains( i ) );
assertTrue( result.getArtifacts().containsKey( j.getId() ) );
assertTrue( result.getArtifacts().contains( j ) );
assertLocalArtifactPresent( i );

View File

@ -18,6 +18,8 @@ package org.apache.maven.artifact.resolver;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.Collections;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
@ -25,18 +27,16 @@ import java.util.Map;
*/
public class ArtifactResolutionResult
{
private Map artifacts;
private Set artifacts = Collections.EMPTY_SET;
private Map conflicts;
public ArtifactResolutionResult()
{
artifacts = new HashMap();
conflicts = new HashMap();
}
public Map getArtifacts()
public Set getArtifacts()
{
return artifacts;
}
@ -45,4 +45,9 @@ public class ArtifactResolutionResult
{
return conflicts;
}
public void setArtifacts( Set artifacts )
{
this.artifacts = artifacts;
}
}

View File

@ -29,6 +29,7 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.HashSet;
/**
* Default implementation of the artifact collector.
@ -131,20 +132,7 @@ public class DefaultArtifactCollector
}
}
// ----------------------------------------------------------------------
// 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();
for ( Iterator it = resolvedArtifacts.values().iterator(); it.hasNext(); )
{
Artifact artifact = (Artifact) it.next();
artifactResult.put( artifact.getId(), artifact );
}
result.setArtifacts( new HashSet( resolvedArtifacts.values() ) );
return result;
}

View File

@ -23,6 +23,7 @@ import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.codehaus.plexus.PlexusTestCase;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
@ -93,11 +94,26 @@ public class DefaultArtifactCollectorTest
}
}
private void collect( ArtifactSpec a )
public void testResolveNearest()
throws ArtifactResolutionException
{
artifactCollector.collect( Collections.singleton( a.artifact ), projectArtifact.artifact, null, null, source,
null, artifactFactory );
ArtifactSpec a = createArtifact( "a", "1.0" );
ArtifactSpec b = a.addDependency( "b", "1.0" );
ArtifactSpec c = a.addDependency( "c", "3.0" );
b.addDependency( "c", "2.0" );
ArtifactResolutionResult res = collect( a );
assertEquals( "Check artifact list",
new HashSet( Arrays.asList( new Object[]{a.artifact, b.artifact, c.artifact} ) ),
res.getArtifacts() );
}
private ArtifactResolutionResult collect( ArtifactSpec a )
throws ArtifactResolutionException
{
return artifactCollector.collect( Collections.singleton( a.artifact ), projectArtifact.artifact, null, null,
source, null, artifactFactory );
}
private ArtifactSpec createArtifact( String id, String version )

View File

@ -561,9 +561,9 @@ public class DefaultPluginManager
metadataSource,
artifactFilter );
Map resolved = result.getArtifacts();
Set resolved = result.getArtifacts();
for ( Iterator it = resolved.values().iterator(); it.hasNext(); )
for ( Iterator it = resolved.iterator(); it.hasNext(); )
{
Artifact artifact = (Artifact) it.next();
@ -585,12 +585,12 @@ public class DefaultPluginManager
.resolveTransitively( pluginArtifact, remoteArtifactRepositories, session.getLocalRepository(),
metadataSource, distroProvidedFilter );
Map distroProvided = distroProvidedResult.getArtifacts();
Set distroProvided = distroProvidedResult.getArtifacts();
List unfilteredArtifactList = new ArrayList( resolved.size() + distroProvided.size() );
unfilteredArtifactList.addAll( resolved.values() );
unfilteredArtifactList.addAll( distroProvided.values() );
unfilteredArtifactList.addAll( resolved );
unfilteredArtifactList.addAll( distroProvided );
pluginDescriptor.setArtifacts( unfilteredArtifactList );
}
@ -1020,7 +1020,7 @@ public class DefaultPluginManager
context.getLocalRepository(),
sourceReader, filter );
project.setArtifacts( new HashSet( result.getArtifacts().values() ) );
project.setArtifacts( result.getArtifacts() );
}
// ----------------------------------------------------------------------

View File

@ -150,7 +150,7 @@ public class DefaultMavenProjectBuilder
localRepository,
artifactMetadataSource );
project.setArtifacts( new HashSet( result.getArtifacts().values() ) );
project.setArtifacts( result.getArtifacts() );
return project;
}