mirror of https://github.com/apache/maven.git
simplify the resolveTransitively API, and implement the new collector up to the level of functionality of the original.
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@191773 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
854b76e61f
commit
3f2f0d50a3
maven-artifact-ant/src/main/java/org/apache/maven/artifact/ant
maven-artifact-manager/src/main/java/org/apache/maven/artifact/resolver
maven-artifact/src
main/java/org/apache/maven/artifact
factory
resolver
ArtifactCollector.javaArtifactResolver.javaDefaultArtifactCollector.javaLegacyArtifactCollector.java
versioning
test/java/org/apache/maven/artifact/resolver
maven-core/src/main/java/org/apache/maven/plugin
maven-project/src/main/java/org/apache/maven/project
|
@ -88,7 +88,7 @@ public class DependenciesTask
|
||||||
pom = createDummyPom();
|
pom = createDummyPom();
|
||||||
}
|
}
|
||||||
|
|
||||||
Set artifacts = metadataSource.createArtifacts( dependencies, null, null );
|
Set artifacts = MavenMetadataSource.createArtifacts( artifactFactory, dependencies, null, null );
|
||||||
|
|
||||||
log( "Resolving dependencies..." );
|
log( "Resolving dependencies..." );
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,6 @@ import org.codehaus.plexus.logging.AbstractLogEnabled;
|
||||||
import org.codehaus.plexus.logging.Logger;
|
import org.codehaus.plexus.logging.Logger;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
@ -130,23 +129,6 @@ public class DefaultArtifactResolver
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArtifactResolutionResult resolveTransitively( Artifact artifact, List remoteRepositories,
|
|
||||||
ArtifactRepository localRepository,
|
|
||||||
ArtifactMetadataSource source )
|
|
||||||
throws ArtifactResolutionException
|
|
||||||
{
|
|
||||||
return resolveTransitively( artifact, remoteRepositories, localRepository, source, null );
|
|
||||||
}
|
|
||||||
|
|
||||||
public ArtifactResolutionResult resolveTransitively( Artifact artifact, List remoteRepositories,
|
|
||||||
ArtifactRepository localRepository,
|
|
||||||
ArtifactMetadataSource source, ArtifactFilter filter )
|
|
||||||
throws ArtifactResolutionException
|
|
||||||
{
|
|
||||||
return resolveTransitively( Collections.singleton( artifact ), null, remoteRepositories, localRepository,
|
|
||||||
source, filter );
|
|
||||||
}
|
|
||||||
|
|
||||||
public ArtifactResolutionResult resolveTransitively( Set artifacts, Artifact originatingArtifact,
|
public ArtifactResolutionResult resolveTransitively( Set artifacts, Artifact originatingArtifact,
|
||||||
List remoteRepositories, ArtifactRepository localRepository,
|
List remoteRepositories, ArtifactRepository localRepository,
|
||||||
ArtifactMetadataSource source, ArtifactFilter filter )
|
ArtifactMetadataSource source, ArtifactFilter filter )
|
||||||
|
|
|
@ -56,7 +56,7 @@ public class DefaultArtifactFactory
|
||||||
private Artifact createArtifact( String groupId, String artifactId, String version, String scope, String type,
|
private Artifact createArtifact( String groupId, String artifactId, String version, String scope, String type,
|
||||||
String classifier, String inheritedScope )
|
String classifier, String inheritedScope )
|
||||||
{
|
{
|
||||||
// TODO: can refactor, use scope handler
|
// TODO: can refactor - inherited scope calculation belongs in the collector, use scope handler
|
||||||
|
|
||||||
String desiredScope = Artifact.SCOPE_RUNTIME;
|
String desiredScope = Artifact.SCOPE_RUNTIME;
|
||||||
if ( inheritedScope == null )
|
if ( inheritedScope == null )
|
||||||
|
|
|
@ -38,4 +38,10 @@ public interface ArtifactCollector
|
||||||
List remoteRepositories, ArtifactMetadataSource source, ArtifactFilter filter,
|
List remoteRepositories, ArtifactMetadataSource source, ArtifactFilter filter,
|
||||||
ArtifactFactory artifactFactory )
|
ArtifactFactory artifactFactory )
|
||||||
throws ArtifactResolutionException;
|
throws ArtifactResolutionException;
|
||||||
|
|
||||||
|
ArtifactResolutionResult collect( Set artifacts, Artifact originatingArtifact, Set managedVersions,
|
||||||
|
ArtifactRepository localRepository, List remoteRepositories,
|
||||||
|
ArtifactMetadataSource source, ArtifactFilter filter,
|
||||||
|
ArtifactFactory artifactFactory )
|
||||||
|
throws ArtifactResolutionException;
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,15 +39,6 @@ public interface ArtifactResolver
|
||||||
void resolve( Artifact artifact, List remoteRepositories, ArtifactRepository localRepository )
|
void resolve( Artifact artifact, List remoteRepositories, ArtifactRepository localRepository )
|
||||||
throws ArtifactResolutionException;
|
throws ArtifactResolutionException;
|
||||||
|
|
||||||
ArtifactResolutionResult resolveTransitively( Artifact artifact, List remoteRepositories,
|
|
||||||
ArtifactRepository localRepository, ArtifactMetadataSource source )
|
|
||||||
throws ArtifactResolutionException;
|
|
||||||
|
|
||||||
ArtifactResolutionResult resolveTransitively( Artifact artifact, List remoteRepositories,
|
|
||||||
ArtifactRepository localRepository, ArtifactMetadataSource source,
|
|
||||||
ArtifactFilter filter )
|
|
||||||
throws ArtifactResolutionException;
|
|
||||||
|
|
||||||
ArtifactResolutionResult resolveTransitively( Set artifacts, Artifact originatingArtifact, List remoteRepositories,
|
ArtifactResolutionResult resolveTransitively( Set artifacts, Artifact originatingArtifact, List remoteRepositories,
|
||||||
ArtifactRepository localRepository, ArtifactMetadataSource source )
|
ArtifactRepository localRepository, ArtifactMetadataSource source )
|
||||||
throws ArtifactResolutionException;
|
throws ArtifactResolutionException;
|
||||||
|
|
|
@ -23,13 +23,14 @@ import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
|
||||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||||
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
|
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.HashSet;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default implementation of the artifact collector.
|
* Default implementation of the artifact collector.
|
||||||
|
@ -46,112 +47,209 @@ public class DefaultArtifactCollector
|
||||||
ArtifactFactory artifactFactory )
|
ArtifactFactory artifactFactory )
|
||||||
throws ArtifactResolutionException
|
throws ArtifactResolutionException
|
||||||
{
|
{
|
||||||
ArtifactResolutionResult result = new ArtifactResolutionResult();
|
return collect( artifacts, originatingArtifact, Collections.EMPTY_SET, localRepository, remoteRepositories,
|
||||||
|
source, filter, artifactFactory );
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArtifactResolutionResult collect( Set artifacts, Artifact originatingArtifact, Set managedVersions,
|
||||||
|
ArtifactRepository localRepository, List remoteRepositories,
|
||||||
|
ArtifactMetadataSource source, ArtifactFilter filter,
|
||||||
|
ArtifactFactory artifactFactory )
|
||||||
|
throws ArtifactResolutionException
|
||||||
|
{
|
||||||
Map resolvedArtifacts = new HashMap();
|
Map resolvedArtifacts = new HashMap();
|
||||||
|
|
||||||
List queue = new LinkedList();
|
ResolutionNode root = new ResolutionNode( originatingArtifact );
|
||||||
|
root.addDependencies( artifacts, filter );
|
||||||
|
|
||||||
queue.add( artifacts );
|
recurse( root, resolvedArtifacts, localRepository, remoteRepositories, source, filter, artifactFactory );
|
||||||
|
|
||||||
while ( !queue.isEmpty() )
|
Set set = new HashSet();
|
||||||
|
|
||||||
|
for ( Iterator i = resolvedArtifacts.values().iterator(); i.hasNext(); )
|
||||||
{
|
{
|
||||||
Set currentArtifacts = (Set) queue.remove( 0 );
|
ResolutionNode node = (ResolutionNode) i.next();
|
||||||
|
if ( node != root )
|
||||||
for ( Iterator i = currentArtifacts.iterator(); i.hasNext(); )
|
|
||||||
{
|
{
|
||||||
Artifact newArtifact = (Artifact) i.next();
|
set.add( node.getArtifact() );
|
||||||
|
|
||||||
String id = newArtifact.getDependencyConflictId();
|
|
||||||
|
|
||||||
if ( resolvedArtifacts.containsKey( id ) )
|
|
||||||
{
|
|
||||||
Artifact knownArtifact = (Artifact) resolvedArtifacts.get( id );
|
|
||||||
|
|
||||||
String newVersion = newArtifact.getVersion();
|
|
||||||
|
|
||||||
String knownVersion = knownArtifact.getVersion();
|
|
||||||
|
|
||||||
if ( !newVersion.equals( knownVersion ) )
|
|
||||||
{
|
|
||||||
addConflict( result, knownArtifact, newArtifact );
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: scope handler
|
|
||||||
boolean updateScope = false;
|
|
||||||
if ( Artifact.SCOPE_RUNTIME.equals( newArtifact.getScope() ) &&
|
|
||||||
Artifact.SCOPE_TEST.equals( knownArtifact.getScope() ) )
|
|
||||||
{
|
|
||||||
updateScope = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( Artifact.SCOPE_COMPILE.equals( newArtifact.getScope() ) &&
|
|
||||||
!Artifact.SCOPE_COMPILE.equals( knownArtifact.getScope() ) )
|
|
||||||
{
|
|
||||||
updateScope = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( updateScope )
|
|
||||||
{
|
|
||||||
Artifact artifact = artifactFactory.createArtifact( knownArtifact.getGroupId(),
|
|
||||||
knownArtifact.getArtifactId(), knownVersion,
|
|
||||||
newArtifact.getScope(),
|
|
||||||
knownArtifact.getType() );
|
|
||||||
resolvedArtifacts.put( artifact.getDependencyConflictId(), artifact );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// ----------------------------------------------------------------------
|
|
||||||
// It's the first time we have encountered this artifact
|
|
||||||
// ----------------------------------------------------------------------
|
|
||||||
|
|
||||||
if ( filter != null && !filter.include( newArtifact ) )
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
resolvedArtifacts.put( id, newArtifact );
|
|
||||||
|
|
||||||
Set referencedDependencies = null;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
referencedDependencies = source.retrieve( newArtifact, localRepository, remoteRepositories );
|
|
||||||
}
|
|
||||||
catch ( ArtifactMetadataRetrievalException e )
|
|
||||||
{
|
|
||||||
throw new TransitiveArtifactResolutionException( e.getMessage(), newArtifact,
|
|
||||||
remoteRepositories, e );
|
|
||||||
}
|
|
||||||
|
|
||||||
// the pom for given dependency exisit we will add it to the
|
|
||||||
// queue
|
|
||||||
queue.add( referencedDependencies );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
result.setArtifacts( new HashSet( resolvedArtifacts.values() ) );
|
ArtifactResolutionResult result = new ArtifactResolutionResult();
|
||||||
|
|
||||||
|
result.setArtifacts( set );
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addConflict( ArtifactResolutionResult result, Artifact knownArtifact, Artifact newArtifact )
|
private void recurse( ResolutionNode node, Map resolvedArtifacts, ArtifactRepository localRepository,
|
||||||
|
List remoteRepositories, ArtifactMetadataSource source, ArtifactFilter filter,
|
||||||
|
ArtifactFactory artifactFactory )
|
||||||
|
throws ArtifactResolutionException
|
||||||
{
|
{
|
||||||
List conflicts;
|
ResolutionNode previous = (ResolutionNode) resolvedArtifacts.get( node.getKey() );
|
||||||
|
if ( previous != null )
|
||||||
conflicts = (List) result.getConflicts().get( newArtifact.getDependencyConflictId() );
|
|
||||||
|
|
||||||
if ( conflicts == null )
|
|
||||||
{
|
{
|
||||||
conflicts = new LinkedList();
|
// TODO: conflict resolvers
|
||||||
|
|
||||||
conflicts.add( knownArtifact );
|
// previous one is more dominant
|
||||||
|
if ( previous.getDepth() <= node.getDepth() )
|
||||||
|
{
|
||||||
|
boolean updateScope = false;
|
||||||
|
Artifact newArtifact = node.getArtifact();
|
||||||
|
Artifact previousArtifact = previous.getArtifact();
|
||||||
|
|
||||||
result.getConflicts().put( newArtifact.getDependencyConflictId(), conflicts );
|
if ( Artifact.SCOPE_RUNTIME.equals( newArtifact.getScope() ) &&
|
||||||
|
( Artifact.SCOPE_TEST.equals( previousArtifact.getScope() ) ||
|
||||||
|
Artifact.SCOPE_PROVIDED.equals( previousArtifact.getScope() ) ) )
|
||||||
|
{
|
||||||
|
updateScope = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( Artifact.SCOPE_COMPILE.equals( newArtifact.getScope() ) &&
|
||||||
|
!Artifact.SCOPE_COMPILE.equals( previousArtifact.getScope() ) )
|
||||||
|
{
|
||||||
|
updateScope = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( updateScope )
|
||||||
|
{
|
||||||
|
Artifact artifact = artifactFactory.createArtifact( previousArtifact.getGroupId(),
|
||||||
|
previousArtifact.getArtifactId(),
|
||||||
|
previousArtifact.getVersion(),
|
||||||
|
newArtifact.getScope(),
|
||||||
|
previousArtifact.getType() );
|
||||||
|
// TODO: can I just change the scope?
|
||||||
|
previous.setArtifact( artifact );
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
boolean updateScope = false;
|
||||||
|
Artifact previousArtifact = previous.getArtifact();
|
||||||
|
Artifact newArtifact = node.getArtifact();
|
||||||
|
|
||||||
|
if ( Artifact.SCOPE_RUNTIME.equals( previousArtifact.getScope() ) &&
|
||||||
|
( Artifact.SCOPE_TEST.equals( newArtifact.getScope() ) ||
|
||||||
|
Artifact.SCOPE_PROVIDED.equals( newArtifact.getScope() ) ) )
|
||||||
|
{
|
||||||
|
updateScope = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( Artifact.SCOPE_COMPILE.equals( previousArtifact.getScope() ) &&
|
||||||
|
!Artifact.SCOPE_COMPILE.equals( newArtifact.getScope() ) )
|
||||||
|
{
|
||||||
|
updateScope = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( updateScope )
|
||||||
|
{
|
||||||
|
Artifact artifact = artifactFactory.createArtifact( newArtifact.getGroupId(),
|
||||||
|
newArtifact.getArtifactId(),
|
||||||
|
newArtifact.getVersion(),
|
||||||
|
previousArtifact.getScope(),
|
||||||
|
newArtifact.getType() );
|
||||||
|
// TODO: can I just change the scope?
|
||||||
|
node.setArtifact( artifact );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
conflicts.add( newArtifact );
|
resolvedArtifacts.put( node.getKey(), node );
|
||||||
|
|
||||||
|
for ( Iterator i = node.getChildrenIterator(); i.hasNext(); )
|
||||||
|
{
|
||||||
|
ResolutionNode child = (ResolutionNode) i.next();
|
||||||
|
if ( !child.isResolved() )
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Set artifacts = source.retrieve( child.getArtifact(), localRepository, remoteRepositories );
|
||||||
|
child.addDependencies( artifacts, filter );
|
||||||
|
}
|
||||||
|
catch ( ArtifactMetadataRetrievalException e )
|
||||||
|
{
|
||||||
|
throw new TransitiveArtifactResolutionException( e.getMessage(), child.getArtifact(),
|
||||||
|
remoteRepositories, e );
|
||||||
|
}
|
||||||
|
|
||||||
|
recurse( child, resolvedArtifacts, localRepository, remoteRepositories, source, filter,
|
||||||
|
artifactFactory );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static class ResolutionNode
|
||||||
|
{
|
||||||
|
private Artifact artifact;
|
||||||
|
|
||||||
|
private final ResolutionNode parent;
|
||||||
|
|
||||||
|
private List children = null;
|
||||||
|
|
||||||
|
private final int depth;
|
||||||
|
|
||||||
|
public ResolutionNode( Artifact artifact )
|
||||||
|
{
|
||||||
|
this.artifact = artifact;
|
||||||
|
this.parent = null;
|
||||||
|
this.depth = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ResolutionNode( Artifact artifact, ResolutionNode parent )
|
||||||
|
{
|
||||||
|
this.artifact = artifact;
|
||||||
|
this.parent = parent;
|
||||||
|
this.depth = parent.depth + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Artifact getArtifact()
|
||||||
|
{
|
||||||
|
return artifact;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getKey()
|
||||||
|
{
|
||||||
|
return artifact.getDependencyConflictId();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addDependencies( Set artifacts, ArtifactFilter filter )
|
||||||
|
{
|
||||||
|
children = new ArrayList( artifacts.size() );
|
||||||
|
|
||||||
|
for ( Iterator i = artifacts.iterator(); i.hasNext(); )
|
||||||
|
{
|
||||||
|
Artifact a = (Artifact) i.next();
|
||||||
|
|
||||||
|
if ( filter == null || filter.include( a ) )
|
||||||
|
{
|
||||||
|
children.add( new ResolutionNode( a, this ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isResolved()
|
||||||
|
{
|
||||||
|
return children != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Iterator getChildrenIterator()
|
||||||
|
{
|
||||||
|
return children.iterator();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getDepth()
|
||||||
|
{
|
||||||
|
return depth;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setArtifact( Artifact artifact )
|
||||||
|
{
|
||||||
|
this.artifact = artifact;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,169 @@
|
||||||
|
package org.apache.maven.artifact.resolver;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright 2001-2005 The Apache Software Foundation.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import org.apache.maven.artifact.Artifact;
|
||||||
|
import org.apache.maven.artifact.factory.ArtifactFactory;
|
||||||
|
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.artifact.resolver.filter.ArtifactFilter;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Previous implementation of the artifact collector.
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
|
||||||
|
* @version $Id: DefaultArtifactCollector.java 191748 2005-06-22 00:31:33Z brett $
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
|
public class LegacyArtifactCollector
|
||||||
|
implements ArtifactCollector
|
||||||
|
{
|
||||||
|
public ArtifactResolutionResult collect( Set artifacts, Artifact originatingArtifact,
|
||||||
|
ArtifactRepository localRepository, List remoteRepositories,
|
||||||
|
ArtifactMetadataSource source, ArtifactFilter filter,
|
||||||
|
ArtifactFactory artifactFactory )
|
||||||
|
throws ArtifactResolutionException
|
||||||
|
{
|
||||||
|
return collect( artifacts, originatingArtifact, Collections.EMPTY_SET, localRepository, remoteRepositories,
|
||||||
|
source, filter, artifactFactory );
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArtifactResolutionResult collect( Set artifacts, Artifact originatingArtifact, Set managedVersions,
|
||||||
|
ArtifactRepository localRepository, List remoteRepositories,
|
||||||
|
ArtifactMetadataSource source, ArtifactFilter filter,
|
||||||
|
ArtifactFactory artifactFactory )
|
||||||
|
throws ArtifactResolutionException
|
||||||
|
{
|
||||||
|
ArtifactResolutionResult result = new ArtifactResolutionResult();
|
||||||
|
|
||||||
|
Map resolvedArtifacts = new HashMap();
|
||||||
|
|
||||||
|
List queue = new LinkedList();
|
||||||
|
|
||||||
|
queue.add( artifacts );
|
||||||
|
|
||||||
|
while ( !queue.isEmpty() )
|
||||||
|
{
|
||||||
|
Set currentArtifacts = (Set) queue.remove( 0 );
|
||||||
|
|
||||||
|
for ( Iterator i = currentArtifacts.iterator(); i.hasNext(); )
|
||||||
|
{
|
||||||
|
Artifact newArtifact = (Artifact) i.next();
|
||||||
|
|
||||||
|
String id = newArtifact.getDependencyConflictId();
|
||||||
|
|
||||||
|
if ( resolvedArtifacts.containsKey( id ) )
|
||||||
|
{
|
||||||
|
Artifact knownArtifact = (Artifact) resolvedArtifacts.get( id );
|
||||||
|
|
||||||
|
String newVersion = newArtifact.getVersion();
|
||||||
|
|
||||||
|
String knownVersion = knownArtifact.getVersion();
|
||||||
|
|
||||||
|
if ( !newVersion.equals( knownVersion ) )
|
||||||
|
{
|
||||||
|
addConflict( result, knownArtifact, newArtifact );
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: scope handler
|
||||||
|
boolean updateScope = false;
|
||||||
|
if ( Artifact.SCOPE_RUNTIME.equals( newArtifact.getScope() ) &&
|
||||||
|
Artifact.SCOPE_TEST.equals( knownArtifact.getScope() ) )
|
||||||
|
{
|
||||||
|
updateScope = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( Artifact.SCOPE_COMPILE.equals( newArtifact.getScope() ) &&
|
||||||
|
!Artifact.SCOPE_COMPILE.equals( knownArtifact.getScope() ) )
|
||||||
|
{
|
||||||
|
updateScope = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( updateScope )
|
||||||
|
{
|
||||||
|
Artifact artifact = artifactFactory.createArtifact( knownArtifact.getGroupId(),
|
||||||
|
knownArtifact.getArtifactId(), knownVersion,
|
||||||
|
newArtifact.getScope(),
|
||||||
|
knownArtifact.getType() );
|
||||||
|
resolvedArtifacts.put( artifact.getDependencyConflictId(), artifact );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// ----------------------------------------------------------------------
|
||||||
|
// It's the first time we have encountered this artifact
|
||||||
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
|
if ( filter != null && !filter.include( newArtifact ) )
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
resolvedArtifacts.put( id, newArtifact );
|
||||||
|
|
||||||
|
Set referencedDependencies = null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
referencedDependencies = source.retrieve( newArtifact, localRepository, remoteRepositories );
|
||||||
|
}
|
||||||
|
catch ( ArtifactMetadataRetrievalException e )
|
||||||
|
{
|
||||||
|
throw new TransitiveArtifactResolutionException( e.getMessage(), newArtifact,
|
||||||
|
remoteRepositories, e );
|
||||||
|
}
|
||||||
|
|
||||||
|
// the pom for given dependency exisit we will add it to the
|
||||||
|
// queue
|
||||||
|
queue.add( referencedDependencies );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
result.setArtifacts( new HashSet( resolvedArtifacts.values() ) );
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addConflict( ArtifactResolutionResult result, Artifact knownArtifact, Artifact newArtifact )
|
||||||
|
{
|
||||||
|
List conflicts;
|
||||||
|
|
||||||
|
conflicts = (List) result.getConflicts().get( newArtifact.getDependencyConflictId() );
|
||||||
|
|
||||||
|
if ( conflicts == null )
|
||||||
|
{
|
||||||
|
conflicts = new LinkedList();
|
||||||
|
|
||||||
|
conflicts.add( knownArtifact );
|
||||||
|
|
||||||
|
result.getConflicts().put( newArtifact.getDependencyConflictId(), conflicts );
|
||||||
|
}
|
||||||
|
|
||||||
|
conflicts.add( newArtifact );
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,29 @@
|
||||||
|
package org.apache.maven.artifact.versioning;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright 2001-2005 The Apache Software Foundation.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Describes an artifact version in terms of its components, converts it to/from a string and
|
||||||
|
* compares two versions.
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
|
||||||
|
* @version $Id$
|
||||||
|
*/
|
||||||
|
public interface ArtifactVersion
|
||||||
|
extends Comparable
|
||||||
|
{
|
||||||
|
}
|
|
@ -21,12 +21,15 @@ import org.apache.maven.artifact.factory.ArtifactFactory;
|
||||||
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
|
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
|
||||||
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
|
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
|
||||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||||
|
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
|
||||||
|
import org.apache.maven.artifact.resolver.filter.ExclusionSetFilter;
|
||||||
import org.codehaus.plexus.PlexusTestCase;
|
import org.codehaus.plexus.PlexusTestCase;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
@ -48,6 +51,8 @@ public class DefaultArtifactCollectorTest
|
||||||
|
|
||||||
private Source source;
|
private Source source;
|
||||||
|
|
||||||
|
private static final String GROUP_ID = "test";
|
||||||
|
|
||||||
protected void setUp()
|
protected void setUp()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
|
@ -57,10 +62,10 @@ public class DefaultArtifactCollectorTest
|
||||||
this.artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
|
this.artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
|
||||||
this.artifactCollector = new DefaultArtifactCollector();
|
this.artifactCollector = new DefaultArtifactCollector();
|
||||||
|
|
||||||
this.projectArtifact = createArtifact( "project", "1.0" );
|
this.projectArtifact = createArtifact( "project", "1.0", null );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCircularDependencyNotIncludingCurrentProject()
|
public void disabledtestCircularDependencyNotIncludingCurrentProject()
|
||||||
throws ArtifactResolutionException
|
throws ArtifactResolutionException
|
||||||
{
|
{
|
||||||
ArtifactSpec a = createArtifact( "a", "1.0" );
|
ArtifactSpec a = createArtifact( "a", "1.0" );
|
||||||
|
@ -69,7 +74,7 @@ public class DefaultArtifactCollectorTest
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
collect( a );
|
collect( a );
|
||||||
// fail( "Should have failed on cyclic dependency not involving project" );
|
fail( "Should have failed on cyclic dependency not involving project" );
|
||||||
}
|
}
|
||||||
catch ( CyclicDependencyException expected )
|
catch ( CyclicDependencyException expected )
|
||||||
{
|
{
|
||||||
|
@ -77,7 +82,7 @@ public class DefaultArtifactCollectorTest
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCircularDependencyIncludingCurrentProject()
|
public void disabledtestCircularDependencyIncludingCurrentProject()
|
||||||
throws ArtifactResolutionException
|
throws ArtifactResolutionException
|
||||||
{
|
{
|
||||||
ArtifactSpec a = createArtifact( "a", "1.0" );
|
ArtifactSpec a = createArtifact( "a", "1.0" );
|
||||||
|
@ -86,7 +91,7 @@ public class DefaultArtifactCollectorTest
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
collect( a );
|
collect( a );
|
||||||
// fail( "Should have failed on cyclic dependency involving project" );
|
fail( "Should have failed on cyclic dependency involving project" );
|
||||||
}
|
}
|
||||||
catch ( CyclicDependencyException expected )
|
catch ( CyclicDependencyException expected )
|
||||||
{
|
{
|
||||||
|
@ -94,6 +99,25 @@ public class DefaultArtifactCollectorTest
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testResolveWithFilter()
|
||||||
|
throws ArtifactResolutionException
|
||||||
|
{
|
||||||
|
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" );
|
||||||
|
ArtifactSpec d = b.addDependency( "d", "4.0" );
|
||||||
|
|
||||||
|
ArtifactResolutionResult res = collect( a );
|
||||||
|
assertEquals( "Check artifact list", createSet( new Object[]{a.artifact, b.artifact, c.artifact, d.artifact} ),
|
||||||
|
res.getArtifacts() );
|
||||||
|
|
||||||
|
ArtifactFilter filter = new ExclusionSetFilter( new String[]{"b"} );
|
||||||
|
res = collect( a, filter );
|
||||||
|
assertEquals( "Check artifact list", createSet( new Object[]{a.artifact, c.artifact} ), res.getArtifacts() );
|
||||||
|
}
|
||||||
|
|
||||||
public void testResolveNearest()
|
public void testResolveNearest()
|
||||||
throws ArtifactResolutionException
|
throws ArtifactResolutionException
|
||||||
{
|
{
|
||||||
|
@ -104,60 +128,143 @@ public class DefaultArtifactCollectorTest
|
||||||
b.addDependency( "c", "2.0" );
|
b.addDependency( "c", "2.0" );
|
||||||
|
|
||||||
ArtifactResolutionResult res = collect( a );
|
ArtifactResolutionResult res = collect( a );
|
||||||
assertEquals( "Check artifact list",
|
assertEquals( "Check artifact list", createSet( new Object[]{a.artifact, b.artifact, c.artifact} ),
|
||||||
new HashSet( Arrays.asList( new Object[]{a.artifact, b.artifact, c.artifact} ) ),
|
|
||||||
res.getArtifacts() );
|
res.getArtifacts() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void disabledtestResolveManagedVersion()
|
||||||
|
throws ArtifactResolutionException
|
||||||
|
{
|
||||||
|
ArtifactSpec a = createArtifact( "a", "1.0" );
|
||||||
|
a.addDependency( "b", "3.0", Artifact.SCOPE_RUNTIME );
|
||||||
|
|
||||||
|
Artifact managedVersion = createArtifact( "b", "5.0" ).artifact;
|
||||||
|
Artifact modifiedB = createArtifact( "b", "5.0", Artifact.SCOPE_RUNTIME ).artifact;
|
||||||
|
|
||||||
|
ArtifactResolutionResult res = collect( a, managedVersion );
|
||||||
|
assertEquals( "Check artifact list", createSet( new Object[]{a.artifact, modifiedB} ), res.getArtifacts() );
|
||||||
|
}
|
||||||
|
|
||||||
public void testResolveCompileScopeOverTestScope()
|
public void testResolveCompileScopeOverTestScope()
|
||||||
throws ArtifactResolutionException
|
throws ArtifactResolutionException
|
||||||
{
|
{
|
||||||
ArtifactSpec a = createArtifact( "a", "1.0" );
|
ArtifactSpec a = createArtifact( "a", "1.0" );
|
||||||
ArtifactSpec b = a.addDependency( "b", "1.0" );
|
ArtifactSpec c = createArtifact( "c", "3.0", Artifact.SCOPE_TEST );
|
||||||
a.addDependency( "c", "3.0", Artifact.SCOPE_TEST );
|
|
||||||
|
|
||||||
b.addDependency( "c", "2.0", Artifact.SCOPE_COMPILE );
|
a.addDependency( "c", "2.0", Artifact.SCOPE_COMPILE );
|
||||||
|
|
||||||
Artifact modifiedC = createArtifact( "c", "3.0", Artifact.SCOPE_COMPILE ).artifact;
|
Artifact modifiedC = createArtifact( "c", "3.0", Artifact.SCOPE_COMPILE ).artifact;
|
||||||
|
|
||||||
ArtifactResolutionResult res = collect( a );
|
ArtifactResolutionResult res = collect( createSet( new Object[]{a.artifact, c.artifact} ) );
|
||||||
assertEquals( "Check artifact list",
|
assertEquals( "Check artifact list", createSet( new Object[]{a.artifact, modifiedC} ), res.getArtifacts() );
|
||||||
new HashSet( Arrays.asList( new Object[]{a.artifact, b.artifact, modifiedC} ) ),
|
Artifact artifact = getArtifact( "c", res.getArtifacts() );
|
||||||
res.getArtifacts() );
|
assertEquals( "Check scope", Artifact.SCOPE_COMPILE, artifact.getScope() );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testResolveRuntimeScopeOverTestScope()
|
public void testResolveRuntimeScopeOverTestScope()
|
||||||
throws ArtifactResolutionException
|
throws ArtifactResolutionException
|
||||||
{
|
{
|
||||||
ArtifactSpec a = createArtifact( "a", "1.0" );
|
ArtifactSpec a = createArtifact( "a", "1.0" );
|
||||||
ArtifactSpec b = a.addDependency( "b", "1.0" );
|
ArtifactSpec c = createArtifact( "c", "3.0", Artifact.SCOPE_TEST );
|
||||||
a.addDependency( "c", "3.0", Artifact.SCOPE_TEST );
|
|
||||||
|
|
||||||
b.addDependency( "c", "2.0", Artifact.SCOPE_RUNTIME );
|
a.addDependency( "c", "2.0", Artifact.SCOPE_RUNTIME );
|
||||||
|
|
||||||
Artifact modifiedC = createArtifact( "c", "3.0", Artifact.SCOPE_RUNTIME ).artifact;
|
Artifact modifiedC = createArtifact( "c", "3.0", Artifact.SCOPE_RUNTIME ).artifact;
|
||||||
|
|
||||||
ArtifactResolutionResult res = collect( a );
|
ArtifactResolutionResult res = collect( createSet( new Object[]{a.artifact, c.artifact} ) );
|
||||||
assertEquals( "Check artifact list",
|
assertEquals( "Check artifact list", createSet( new Object[]{a.artifact, modifiedC} ), res.getArtifacts() );
|
||||||
new HashSet( Arrays.asList( new Object[]{a.artifact, b.artifact, modifiedC} ) ),
|
Artifact artifact = getArtifact( "c", res.getArtifacts() );
|
||||||
res.getArtifacts() );
|
assertEquals( "Check scope", Artifact.SCOPE_RUNTIME, artifact.getScope() );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testResolveCompileScopeOverRuntimeScope()
|
public void testResolveCompileScopeOverRuntimeScope()
|
||||||
throws ArtifactResolutionException
|
throws ArtifactResolutionException
|
||||||
{
|
{
|
||||||
ArtifactSpec a = createArtifact( "a", "1.0" );
|
ArtifactSpec a = createArtifact( "a", "1.0" );
|
||||||
ArtifactSpec b = a.addDependency( "b", "1.0" );
|
ArtifactSpec c = createArtifact( "c", "3.0", Artifact.SCOPE_RUNTIME );
|
||||||
a.addDependency( "c", "3.0", Artifact.SCOPE_RUNTIME );
|
|
||||||
|
|
||||||
b.addDependency( "c", "2.0", Artifact.SCOPE_COMPILE );
|
a.addDependency( "c", "2.0", Artifact.SCOPE_COMPILE );
|
||||||
|
|
||||||
Artifact modifiedC = createArtifact( "c", "3.0", Artifact.SCOPE_COMPILE ).artifact;
|
Artifact modifiedC = createArtifact( "c", "3.0", Artifact.SCOPE_COMPILE ).artifact;
|
||||||
|
|
||||||
ArtifactResolutionResult res = collect( a );
|
ArtifactResolutionResult res = collect( createSet( new Object[]{a.artifact, c.artifact} ) );
|
||||||
assertEquals( "Check artifact list",
|
assertEquals( "Check artifact list", createSet( new Object[]{a.artifact, modifiedC} ), res.getArtifacts() );
|
||||||
new HashSet( Arrays.asList( new Object[]{a.artifact, b.artifact, modifiedC} ) ),
|
Artifact artifact = getArtifact( "c", res.getArtifacts() );
|
||||||
res.getArtifacts() );
|
assertEquals( "Check scope", Artifact.SCOPE_COMPILE, artifact.getScope() );
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testResolveCompileScopeOverProvidedScope()
|
||||||
|
throws ArtifactResolutionException
|
||||||
|
{
|
||||||
|
ArtifactSpec a = createArtifact( "a", "1.0" );
|
||||||
|
ArtifactSpec c = createArtifact( "c", "3.0", Artifact.SCOPE_PROVIDED );
|
||||||
|
|
||||||
|
a.addDependency( "c", "2.0", Artifact.SCOPE_COMPILE );
|
||||||
|
|
||||||
|
Artifact modifiedC = createArtifact( "c", "3.0", Artifact.SCOPE_COMPILE ).artifact;
|
||||||
|
|
||||||
|
ArtifactResolutionResult res = collect( createSet( new Object[]{a.artifact, c.artifact} ) );
|
||||||
|
assertEquals( "Check artifact list", createSet( new Object[]{a.artifact, modifiedC} ), res.getArtifacts() );
|
||||||
|
Artifact artifact = getArtifact( "c", res.getArtifacts() );
|
||||||
|
assertEquals( "Check scope", Artifact.SCOPE_COMPILE, artifact.getScope() );
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testResolveRuntimeScopeOverProvidedScope()
|
||||||
|
throws ArtifactResolutionException
|
||||||
|
{
|
||||||
|
ArtifactSpec a = createArtifact( "a", "1.0" );
|
||||||
|
ArtifactSpec c = createArtifact( "c", "3.0", Artifact.SCOPE_PROVIDED );
|
||||||
|
|
||||||
|
a.addDependency( "c", "2.0", Artifact.SCOPE_RUNTIME );
|
||||||
|
|
||||||
|
Artifact modifiedC = createArtifact( "c", "3.0", Artifact.SCOPE_RUNTIME ).artifact;
|
||||||
|
|
||||||
|
ArtifactResolutionResult res = collect( createSet( new Object[]{a.artifact, c.artifact} ) );
|
||||||
|
assertEquals( "Check artifact list", createSet( new Object[]{a.artifact, modifiedC} ), res.getArtifacts() );
|
||||||
|
Artifact artifact = getArtifact( "c", res.getArtifacts() );
|
||||||
|
assertEquals( "Check scope", Artifact.SCOPE_RUNTIME, artifact.getScope() );
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testProvidedScopeNotTransitive()
|
||||||
|
throws ArtifactResolutionException
|
||||||
|
{
|
||||||
|
ArtifactSpec a = createArtifact( "a", "1.0", Artifact.SCOPE_PROVIDED );
|
||||||
|
ArtifactSpec b = createArtifact( "b", "1.0" );
|
||||||
|
b.addDependency( "c", "3.0", Artifact.SCOPE_PROVIDED );
|
||||||
|
|
||||||
|
ArtifactResolutionResult res = collect( createSet( new Object[]{a.artifact, b.artifact} ) );
|
||||||
|
assertEquals( "Check artifact list", createSet( new Object[]{a.artifact, b.artifact} ), res.getArtifacts() );
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testTestScopeNotTransitive()
|
||||||
|
throws ArtifactResolutionException
|
||||||
|
{
|
||||||
|
ArtifactSpec a = createArtifact( "a", "1.0", Artifact.SCOPE_TEST );
|
||||||
|
ArtifactSpec b = createArtifact( "b", "1.0" );
|
||||||
|
b.addDependency( "c", "3.0", Artifact.SCOPE_TEST );
|
||||||
|
|
||||||
|
ArtifactResolutionResult res = collect( createSet( new Object[]{a.artifact, b.artifact} ) );
|
||||||
|
assertEquals( "Check artifact list", createSet( new Object[]{a.artifact, b.artifact} ), res.getArtifacts() );
|
||||||
|
}
|
||||||
|
|
||||||
|
private Artifact getArtifact( String id, Set artifacts )
|
||||||
|
{
|
||||||
|
for ( Iterator i = artifacts.iterator(); i.hasNext(); )
|
||||||
|
{
|
||||||
|
Artifact a = (Artifact) i.next();
|
||||||
|
if ( a.getArtifactId().equals( id ) && a.getGroupId().equals( GROUP_ID ) )
|
||||||
|
{
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ArtifactResolutionResult collect( Set artifacts )
|
||||||
|
throws ArtifactResolutionException
|
||||||
|
{
|
||||||
|
return artifactCollector.collect( artifacts, projectArtifact.artifact, null, null, source, null,
|
||||||
|
artifactFactory );
|
||||||
}
|
}
|
||||||
|
|
||||||
private ArtifactResolutionResult collect( ArtifactSpec a )
|
private ArtifactResolutionResult collect( ArtifactSpec a )
|
||||||
|
@ -167,19 +274,39 @@ public class DefaultArtifactCollectorTest
|
||||||
source, null, artifactFactory );
|
source, null, artifactFactory );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ArtifactResolutionResult collect( ArtifactSpec a, ArtifactFilter filter )
|
||||||
|
throws ArtifactResolutionException
|
||||||
|
{
|
||||||
|
return artifactCollector.collect( Collections.singleton( a.artifact ), projectArtifact.artifact, null, null,
|
||||||
|
source, filter, artifactFactory );
|
||||||
|
}
|
||||||
|
|
||||||
|
private ArtifactResolutionResult collect( ArtifactSpec a, Artifact managedVersion )
|
||||||
|
throws ArtifactResolutionException
|
||||||
|
{
|
||||||
|
return artifactCollector.collect( Collections.singleton( a.artifact ), projectArtifact.artifact,
|
||||||
|
Collections.singleton( managedVersion ), null, null, source, null,
|
||||||
|
artifactFactory );
|
||||||
|
}
|
||||||
|
|
||||||
private ArtifactSpec createArtifact( String id, String version )
|
private ArtifactSpec createArtifact( String id, String version )
|
||||||
{
|
{
|
||||||
return createArtifact( id, version, null );
|
return createArtifact( id, version, Artifact.SCOPE_COMPILE );
|
||||||
}
|
}
|
||||||
|
|
||||||
private ArtifactSpec createArtifact( String id, String version, String scope )
|
private ArtifactSpec createArtifact( String id, String version, String scope )
|
||||||
{
|
{
|
||||||
ArtifactSpec spec = new ArtifactSpec();
|
ArtifactSpec spec = new ArtifactSpec();
|
||||||
spec.artifact = artifactFactory.createArtifact( "test", id, version, scope, "jar" );
|
spec.artifact = artifactFactory.createArtifact( GROUP_ID, id, version, scope, "jar" );
|
||||||
source.artifacts.put( spec.artifact.getId(), spec );
|
source.artifacts.put( spec.artifact.getId(), spec );
|
||||||
return spec;
|
return spec;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Set createSet( Object[] x )
|
||||||
|
{
|
||||||
|
return new HashSet( Arrays.asList( x ) );
|
||||||
|
}
|
||||||
|
|
||||||
private class ArtifactSpec
|
private class ArtifactSpec
|
||||||
{
|
{
|
||||||
Artifact artifact;
|
Artifact artifact;
|
||||||
|
@ -199,7 +326,7 @@ public class DefaultArtifactCollectorTest
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class Source
|
private class Source
|
||||||
implements ArtifactMetadataSource
|
implements ArtifactMetadataSource
|
||||||
{
|
{
|
||||||
Map artifacts = new HashMap();
|
Map artifacts = new HashMap();
|
||||||
|
@ -208,7 +335,31 @@ public class DefaultArtifactCollectorTest
|
||||||
throws ArtifactMetadataRetrievalException, ArtifactResolutionException
|
throws ArtifactMetadataRetrievalException, ArtifactResolutionException
|
||||||
{
|
{
|
||||||
ArtifactSpec a = (ArtifactSpec) artifacts.get( artifact.getId() );
|
ArtifactSpec a = (ArtifactSpec) artifacts.get( artifact.getId() );
|
||||||
return a.dependencies;
|
return createArtifacts( artifactFactory, a.dependencies, artifact.getScope(),
|
||||||
|
artifact.getDependencyFilter() );
|
||||||
|
}
|
||||||
|
|
||||||
|
private Set createArtifacts( ArtifactFactory artifactFactory, Set dependencies, String inheritedScope,
|
||||||
|
ArtifactFilter dependencyFilter )
|
||||||
|
{
|
||||||
|
Set projectArtifacts = new HashSet();
|
||||||
|
|
||||||
|
for ( Iterator i = dependencies.iterator(); i.hasNext(); )
|
||||||
|
{
|
||||||
|
Artifact d = (Artifact) i.next();
|
||||||
|
|
||||||
|
Artifact artifact = artifactFactory.createArtifact( d.getGroupId(), d.getArtifactId(), d.getVersion(),
|
||||||
|
d.getScope(), d.getType(), inheritedScope );
|
||||||
|
|
||||||
|
if ( artifact != null && ( dependencyFilter == null || dependencyFilter.include( artifact ) ) )
|
||||||
|
{
|
||||||
|
artifact.setDependencyFilter( dependencyFilter );
|
||||||
|
|
||||||
|
projectArtifacts.add( artifact );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return projectArtifacts;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ package org.apache.maven.plugin;
|
||||||
|
|
||||||
import org.apache.maven.artifact.Artifact;
|
import org.apache.maven.artifact.Artifact;
|
||||||
import org.apache.maven.artifact.factory.ArtifactFactory;
|
import org.apache.maven.artifact.factory.ArtifactFactory;
|
||||||
|
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
|
||||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||||
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
||||||
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
|
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
|
||||||
|
@ -213,7 +214,7 @@ public class DefaultPluginManager
|
||||||
|
|
||||||
Artifact pluginArtifact = artifactFactory.createArtifact( groupId, artifactId, version,
|
Artifact pluginArtifact = artifactFactory.createArtifact( groupId, artifactId, version,
|
||||||
Artifact.SCOPE_RUNTIME,
|
Artifact.SCOPE_RUNTIME,
|
||||||
MojoDescriptor.MAVEN_PLUGIN, null );
|
MojoDescriptor.MAVEN_PLUGIN );
|
||||||
|
|
||||||
addPlugin( pluginKey, pluginArtifact, project, localRepository );
|
addPlugin( pluginKey, pluginArtifact, project, localRepository );
|
||||||
|
|
||||||
|
@ -555,10 +556,13 @@ public class DefaultPluginManager
|
||||||
artifactFactory );
|
artifactFactory );
|
||||||
|
|
||||||
List remoteArtifactRepositories = project.getRemoteArtifactRepositories();
|
List remoteArtifactRepositories = project.getRemoteArtifactRepositories();
|
||||||
ArtifactResolutionResult result = artifactResolver.resolveTransitively( pluginArtifact,
|
ArtifactRepository localRepository = session.getLocalRepository();
|
||||||
|
Set dependencies = metadataSource.retrieve( pluginArtifact, localRepository,
|
||||||
|
remoteArtifactRepositories );
|
||||||
|
|
||||||
|
ArtifactResolutionResult result = artifactResolver.resolveTransitively( dependencies, pluginArtifact,
|
||||||
remoteArtifactRepositories,
|
remoteArtifactRepositories,
|
||||||
session.getLocalRepository(),
|
localRepository, metadataSource,
|
||||||
metadataSource,
|
|
||||||
artifactFilter );
|
artifactFilter );
|
||||||
|
|
||||||
Set resolved = result.getArtifacts();
|
Set resolved = result.getArtifacts();
|
||||||
|
@ -582,7 +586,7 @@ public class DefaultPluginManager
|
||||||
ArtifactFilter distroProvidedFilter = new InversionArtifactFilter( artifactFilter );
|
ArtifactFilter distroProvidedFilter = new InversionArtifactFilter( artifactFilter );
|
||||||
|
|
||||||
ArtifactResolutionResult distroProvidedResult = artifactResolver
|
ArtifactResolutionResult distroProvidedResult = artifactResolver
|
||||||
.resolveTransitively( pluginArtifact, remoteArtifactRepositories, session.getLocalRepository(),
|
.resolveTransitively( dependencies, pluginArtifact, remoteArtifactRepositories, localRepository,
|
||||||
metadataSource, distroProvidedFilter );
|
metadataSource, distroProvidedFilter );
|
||||||
|
|
||||||
Set distroProvided = distroProvidedResult.getArtifacts();
|
Set distroProvided = distroProvidedResult.getArtifacts();
|
||||||
|
@ -602,6 +606,10 @@ public class DefaultPluginManager
|
||||||
{
|
{
|
||||||
throw new PluginConfigurationException( "Cannot start plugin container", e );
|
throw new PluginConfigurationException( "Cannot start plugin container", e );
|
||||||
}
|
}
|
||||||
|
catch ( ArtifactMetadataRetrievalException e )
|
||||||
|
{
|
||||||
|
throw new PluginConfigurationException( "Cannot resolve plugin dependencies", e );
|
||||||
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
if ( artifactFactory != null )
|
if ( artifactFactory != null )
|
||||||
|
|
|
@ -268,7 +268,7 @@ public class DefaultMavenProjectBuilder
|
||||||
for ( Iterator i = lineage.iterator(); i.hasNext(); )
|
for ( Iterator i = lineage.iterator(); i.hasNext(); )
|
||||||
{
|
{
|
||||||
MavenProject currentProject = (MavenProject) i.next();
|
MavenProject currentProject = (MavenProject) i.next();
|
||||||
|
|
||||||
Model current = currentProject.getModel();
|
Model current = currentProject.getModel();
|
||||||
|
|
||||||
forcePluginExecutionIdCollision( pomLocation, current );
|
forcePluginExecutionIdCollision( pomLocation, current );
|
||||||
|
@ -312,7 +312,9 @@ public class DefaultMavenProjectBuilder
|
||||||
}
|
}
|
||||||
catch ( IllegalStateException collisionException )
|
catch ( IllegalStateException collisionException )
|
||||||
{
|
{
|
||||||
throw new ProjectBuildingException( "Detected illegal plugin-execution configuration in: " + pomLocation + " Error output: \n\n" + collisionException.getMessage(), collisionException );
|
throw new ProjectBuildingException(
|
||||||
|
"Detected illegal plugin-execution configuration in: " + pomLocation +
|
||||||
|
" Error output: \n\n" + collisionException.getMessage(), collisionException );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -388,7 +390,7 @@ public class DefaultMavenProjectBuilder
|
||||||
{
|
{
|
||||||
Artifact parentArtifact = artifactFactory.createArtifact( parentProject.getGroupId(),
|
Artifact parentArtifact = artifactFactory.createArtifact( parentProject.getGroupId(),
|
||||||
parentProject.getArtifactId(),
|
parentProject.getArtifactId(),
|
||||||
parentProject.getVersion(), null, "pom", null );
|
parentProject.getVersion(), null, "pom" );
|
||||||
project.setParentArtifact( parentArtifact );
|
project.setParentArtifact( parentArtifact );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -450,7 +452,7 @@ public class DefaultMavenProjectBuilder
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
Artifact artifact = artifactFactory.createArtifact( parentModel.getGroupId(), parentModel.getArtifactId(),
|
Artifact artifact = artifactFactory.createArtifact( parentModel.getGroupId(), parentModel.getArtifactId(),
|
||||||
parentModel.getVersion(), null, "pom", null );
|
parentModel.getVersion(), null, "pom" );
|
||||||
|
|
||||||
model = findModelFromRepository( artifact, aggregatedRemoteWagonRepositories, localRepository );
|
model = findModelFromRepository( artifact, aggregatedRemoteWagonRepositories, localRepository );
|
||||||
|
|
||||||
|
@ -535,9 +537,7 @@ public class DefaultMavenProjectBuilder
|
||||||
|
|
||||||
protected Set createArtifacts( List dependencies )
|
protected Set createArtifacts( List dependencies )
|
||||||
{
|
{
|
||||||
// TODO: merge with MavenMetadataSource properly
|
return MavenMetadataSource.createArtifacts( artifactFactory, dependencies, null, null );
|
||||||
return new MavenMetadataSource( artifactResolver, this, artifactFactory ).createArtifacts( dependencies, null,
|
|
||||||
null );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Set createPluginArtifacts( List plugins )
|
protected Set createPluginArtifacts( List plugins )
|
||||||
|
@ -559,7 +559,7 @@ public class DefaultMavenProjectBuilder
|
||||||
}
|
}
|
||||||
|
|
||||||
Artifact artifact = artifactFactory.createArtifact( p.getGroupId(), p.getArtifactId(), version, null,
|
Artifact artifact = artifactFactory.createArtifact( p.getGroupId(), p.getArtifactId(), version, null,
|
||||||
"maven-plugin", null );
|
"maven-plugin" );
|
||||||
if ( artifact != null )
|
if ( artifact != null )
|
||||||
{
|
{
|
||||||
pluginArtifacts.add( artifact );
|
pluginArtifacts.add( artifact );
|
||||||
|
|
|
@ -139,10 +139,11 @@ public class MavenMetadataSource
|
||||||
IOUtil.close( reader );
|
IOUtil.close( reader );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return createArtifacts( dependencies, artifact.getScope(), artifact.getDependencyFilter() );
|
return createArtifacts( artifactFactory, dependencies, artifact.getScope(), artifact.getDependencyFilter() );
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set createArtifacts( List dependencies, String inheritedScope, ArtifactFilter dependencyFilter )
|
public static Set createArtifacts( ArtifactFactory artifactFactory, List dependencies, String inheritedScope,
|
||||||
|
ArtifactFilter dependencyFilter )
|
||||||
{
|
{
|
||||||
Set projectArtifacts = new HashSet();
|
Set projectArtifacts = new HashSet();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue