o trying to use the request/result pattern everywhere

o remove another use of ResolutionGroup in the core
o remove all the deprecated methods in the resolver, we'll see what breaks and we'll restore in maven-compat


git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@749407 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jason van Zyl 2009-03-02 18:42:31 +00:00
parent 7c537105b2
commit 613253dda7
15 changed files with 167 additions and 620 deletions

View File

@ -31,7 +31,7 @@ public class ArtifactResolutionRequest
private ArtifactRepository localRepository;
private List<ArtifactRepository> remoteRepostories;
private List<ArtifactRepository> remoteRepositories;
private ArtifactFilter filter;
@ -52,7 +52,7 @@ public class ArtifactResolutionRequest
{
this.artifact = artifact;
this.localRepository = localRepository;
this.remoteRepostories = remoteRepositories;
this.remoteRepositories = remoteRepositories;
}
public Artifact getArtifact()
@ -149,12 +149,12 @@ public class ArtifactResolutionRequest
public List<ArtifactRepository> getRemoteRepostories()
{
return remoteRepostories;
return remoteRepositories;
}
public ArtifactResolutionRequest setRemoteRepostories( List<ArtifactRepository> remoteRepostories )
{
this.remoteRepostories = remoteRepostories;
this.remoteRepositories = remoteRepostories;
return this;
}
@ -176,6 +176,13 @@ public class ArtifactResolutionRequest
return listeners;
}
public ArtifactResolutionRequest setListeners( List<ResolutionListener> listeners )
{
this.listeners = listeners;
return this;
}
public ArtifactResolutionRequest addListener( ResolutionListener listener )
{
listeners.add( listener );

View File

@ -63,8 +63,8 @@ public class ArtifactResolutionResult
private List<ArtifactRepository> repositories;
private Set<ResolutionNode> resolutionNodes;
private Set<Artifact> requestedArtifacts;
private Set<Artifact> artifacts;
public Artifact getOriginatingArtifact()
@ -79,40 +79,37 @@ public class ArtifactResolutionResult
return this;
}
public Set<Artifact> getArtifacts()
public void addArtifact( Artifact artifact )
{
if ( artifacts == null )
{
artifacts = new LinkedHashSet<Artifact>();
for (ResolutionNode node : resolutionNodes)
{
artifacts.add(node.getArtifact());
}
}
artifacts.add( artifact );
}
public Set<Artifact> getArtifacts()
{
return artifacts;
}
public Set<ResolutionNode> getArtifactResolutionNodes()
public void addRequestedArtifact( Artifact artifact )
{
if ( resolutionNodes == null)
if ( requestedArtifacts == null )
{
return Collections.emptySet();
requestedArtifacts = new LinkedHashSet<Artifact>();
}
return resolutionNodes;
requestedArtifacts.add( artifact );
}
public void setArtifactResolutionNodes( final Set<ResolutionNode> resolutionNodes )
public Set<Artifact> getRequestedArtifacts()
{
this.resolutionNodes = resolutionNodes;
// clear the cache
this.artifacts = null;
}
public List getMissingArtifacts()
return requestedArtifacts;
}
public List<Artifact> getMissingArtifacts()
{
return missingArtifacts == null ? Collections.EMPTY_LIST : missingArtifacts;
}

View File

@ -19,123 +19,13 @@ package org.apache.maven.artifact.resolver;
* under the License.
*/
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.resolver.filter.ArtifactFilter;
import org.apache.maven.artifact.resolver.conflict.ConflictResolver;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* I want to use it for hidding the fact that sometime artifact must be
* downloaded. I am just asking LocalRepository for given artifact and I don't
* care if it is alredy there or how it will get there.
*
* @author Michal Maczka
* @author Jason van Zyl
* @version $Id$
*/
public interface ArtifactResolver
{
String ROLE = ArtifactResolver.class.getName();
/** @deprecated use {@link #resolve(ArtifactResolutionRequest)} */
@Deprecated
void resolve( Artifact artifact,
List<ArtifactRepository> remoteRepositories,
ArtifactRepository localRepository )
throws ArtifactResolutionException, ArtifactNotFoundException;
/** @deprecated use {@link #resolve(ArtifactResolutionRequest)} */
@Deprecated
ArtifactResolutionResult resolveTransitively( Set<Artifact> artifacts,
Artifact originatingArtifact,
List<ArtifactRepository> remoteRepositories,
ArtifactRepository localRepository,
ArtifactMetadataSource source )
throws ArtifactResolutionException, ArtifactNotFoundException;
/** @deprecated use {@link #resolve(ArtifactResolutionRequest)} */
@Deprecated
ArtifactResolutionResult resolveTransitively( Set<Artifact> artifacts,
Artifact originatingArtifact,
List<ArtifactRepository> remoteRepositories,
ArtifactRepository localRepository,
ArtifactMetadataSource source,
List<ResolutionListener> listeners )
throws ArtifactResolutionException, ArtifactNotFoundException;
/** @deprecated use {@link #resolve(ArtifactResolutionRequest)} */
@Deprecated
ArtifactResolutionResult resolveTransitively( Set<Artifact> artifacts,
Artifact originatingArtifact,
ArtifactRepository localRepository,
List<ArtifactRepository> remoteRepositories,
ArtifactMetadataSource source,
ArtifactFilter filter )
throws ArtifactResolutionException, ArtifactNotFoundException;
/** @deprecated use {@link #resolve(ArtifactResolutionRequest)} */
@Deprecated
ArtifactResolutionResult resolveTransitively( Set<Artifact> artifacts,
Artifact originatingArtifact,
Map managedVersions,
ArtifactRepository localRepository,
List<ArtifactRepository> remoteRepositories,
ArtifactMetadataSource source )
throws ArtifactResolutionException, ArtifactNotFoundException;
/** @deprecated use {@link #resolve(ArtifactResolutionRequest)} */
@Deprecated
ArtifactResolutionResult resolveTransitively( Set<Artifact> artifacts,
Artifact originatingArtifact,
Map managedVersions,
ArtifactRepository localRepository,
List<ArtifactRepository> remoteRepositories,
ArtifactMetadataSource source,
ArtifactFilter filter )
throws ArtifactResolutionException, ArtifactNotFoundException;
/** @deprecated use {@link #resolve(ArtifactResolutionRequest)} */
@Deprecated
ArtifactResolutionResult resolveTransitively( Set<Artifact> artifacts,
Artifact originatingArtifact,
Map managedVersions,
ArtifactRepository localRepository,
List<ArtifactRepository> remoteRepositories,
ArtifactMetadataSource source,
ArtifactFilter filter,
List<ResolutionListener> listeners )
throws ArtifactResolutionException, ArtifactNotFoundException;
/**
* @since 3.0
* @deprecated use {@link #resolve(ArtifactResolutionRequest)}
*/
@Deprecated
ArtifactResolutionResult resolveTransitively( Set<Artifact> artifacts,
Artifact originatingArtifact,
Map managedVersions,
ArtifactRepository localRepository,
List<ArtifactRepository> remoteRepositories,
ArtifactMetadataSource source,
ArtifactFilter filter,
List<ResolutionListener> listeners,
List<ConflictResolver> conflictResolvers )
throws ArtifactResolutionException, ArtifactNotFoundException;
/** @deprecated use {@link #resolve(ArtifactResolutionRequest)} */
@Deprecated
void resolveAlways( Artifact artifact,
List<ArtifactRepository> remoteRepositories,
ArtifactRepository localRepository )
throws ArtifactResolutionException, ArtifactNotFoundException;
// New API
/** @since 3.0 */
ArtifactResolutionResult resolve( ArtifactResolutionRequest request );
ArtifactResolutionResult resolveWithExceptions( ArtifactResolutionRequest request )
throws ArtifactResolutionException, ArtifactNotFoundException;
}

View File

@ -170,6 +170,8 @@ public class DefaultArtifactCollector
artifact.setDependencyTrail( node.getDependencyTrail() );
set.add( node );
result.addRequestedArtifact( artifact );
}
}
}
@ -181,8 +183,6 @@ public class DefaultArtifactCollector
}
}
result.setArtifactResolutionNodes( set );
return result;
}

View File

@ -291,34 +291,28 @@ public class DefaultArtifactResolver
}
public ArtifactResolutionResult resolveTransitively( Set<Artifact> artifacts, Artifact originatingArtifact, Map managedVersions, ArtifactRepository localRepository,
List<ArtifactRepository> remoteRepositories, ArtifactMetadataSource source, ArtifactFilter filter, List<ResolutionListener> listeners,
List<ConflictResolver> conflictResolvers )
List<ArtifactRepository> remoteRepositories, ArtifactMetadataSource source, ArtifactFilter filter, List<ResolutionListener> listeners,
List<ConflictResolver> conflictResolvers )
throws ArtifactResolutionException, ArtifactNotFoundException
{
if ( listeners == null )
{
// TODO: this is simplistic.
listeners = new ArrayList<ResolutionListener>();
if ( getLogger().isDebugEnabled() )
{
listeners.add( new DebugResolutionListener( getLogger() ) );
}
listeners.add( new WarningResolutionListener( getLogger() ) );
}
ArtifactResolutionResult result;
result = artifactCollector.collect(
artifacts,
originatingArtifact,
managedVersions,
localRepository,
remoteRepositories,
source,
filter,
listeners,
conflictResolvers );
ArtifactResolutionRequest request = new ArtifactResolutionRequest()
.setArtifact( originatingArtifact )
.setArtifactDependencies( artifacts )
.setManagedVersionMap( managedVersions )
.setLocalRepository( localRepository )
.setRemoteRepostories( remoteRepositories )
.setMetadataSource( source )
.setFilter( filter )
.setListeners( listeners )
.setConflictResolvers( conflictResolvers );
return resolveWithExceptions( request );
}
public ArtifactResolutionResult resolveWithExceptions( ArtifactResolutionRequest request )
throws ArtifactResolutionException, ArtifactNotFoundException
{
ArtifactResolutionResult result = resolve( request );
// We have collected all the problems so let's mimic the way the old code worked and just blow up right here.
// That's right lets just let it rip right here and send a big incomprehensible blob of text at unsuspecting
@ -347,29 +341,9 @@ public class DefaultArtifactResolver
throw result.getVersionRangeViolation( 0 );
}
List<Artifact> resolvedArtifacts = new ArrayList<Artifact>();
List<Artifact> missingArtifacts = new ArrayList<Artifact>();
for ( ResolutionNode node : result.getArtifactResolutionNodes() )
if ( result.getMissingArtifacts().size() > 0 )
{
try
{
resolve( node.getArtifact(), node.getRemoteRepositories(), localRepository );
resolvedArtifacts.add( node.getArtifact() );
}
catch ( ArtifactNotFoundException anfe )
{
getLogger().debug( anfe.getMessage(), anfe );
missingArtifacts.add( node.getArtifact() );
}
}
if ( missingArtifacts.size() > 0 )
{
throw new MultipleArtifactsNotFoundException( originatingArtifact, resolvedArtifacts, missingArtifacts, remoteRepositories );
throw new MultipleArtifactsNotFoundException( request.getArtifact(), new ArrayList( result.getArtifacts() ), result.getMissingArtifacts(), request.getRemoteRepostories() );
}
return result;
@ -382,33 +356,28 @@ public class DefaultArtifactResolver
public ArtifactResolutionResult resolve( ArtifactResolutionRequest request )
{
Artifact originatingArtifact = request.getArtifact();
Set<Artifact> artifacts = request.getArtifactDependencies();
Map managedVersions = request.getManagedVersionMap();
ArtifactRepository localRepository = request.getLocalRepository();
List<ArtifactRepository> remoteRepositories = request.getRemoteRepostories();
ArtifactMetadataSource source = request.getMetadataSource();
List<ResolutionListener> listeners = request.getListeners();
ArtifactFilter filter = request.getFilter();
// This is an attempt to get the metadata for the artifacts we are ultimately trying to resolve.
// We still
if ( listeners == null )
{
listeners = new ArrayList<ResolutionListener>();
if ( getLogger().isDebugEnabled() )
{
listeners.add( new DebugResolutionListener( getLogger() ) );
}
ArtifactResolutionResult result = artifactCollector.collect(
artifacts,
originatingArtifact,
managedVersions,
localRepository,
remoteRepositories,
source,
filter,
listeners );
listeners.add( new WarningResolutionListener( getLogger() ) );
}
// After the collection we will have the artifact object in the result but they will not be resolved yet.
ArtifactResolutionResult result = artifactCollector.collect( artifacts, originatingArtifact, managedVersions, localRepository, remoteRepositories, source, filter, listeners );
// Let's grab all the repositories that were gleaned. This we should know up front. I'm not sure
// what the metadata source is doing. Repositories in POMs are deadly.
@ -418,23 +387,25 @@ public class DefaultArtifactResolver
// so we give this back to the calling code and let them deal with this information
// appropriately.
if ( result.hasMetadataResolutionExceptions() || result.hasVersionRangeViolations() )
if ( result.hasMetadataResolutionExceptions() || result.hasVersionRangeViolations() || result.hasCircularDependencyExceptions() )
{
return result;
}
for ( ResolutionNode node : result.getArtifactResolutionNodes() )
for ( Artifact requestedArtifact : result.getRequestedArtifacts() )
{
try
{
resolve( node.getArtifact(), node.getRemoteRepositories(), localRepository );
resolve( requestedArtifact, remoteRepositories, localRepository );
result.addArtifact( requestedArtifact );
}
catch ( ArtifactNotFoundException anfe )
{
// These are cases where the artifact just isn't present in any of the remote repositories
// because it wasn't deployed, or it was deployed in the wrong place.
result.addMissingArtifact( node.getArtifact() );
result.addMissingArtifact( requestedArtifact );
}
catch ( ArtifactResolutionException e )
{

View File

@ -1,227 +0,0 @@
package org.apache.maven.artifact.resolver.metadata;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactResolutionRequest;
import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.artifact.resolver.conflict.GraphConflictResolver;
import org.apache.maven.artifact.transform.ClasspathTransformation;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.logging.AbstractLogEnabled;
/**
* default implementation of the metadata resolver
*
* @author <a href="oleg@codehaus.org">Oleg Gusakov</a>
*
*/
@Component(role=MetadataResolver.class)
public class DefaultMetadataResolver
extends AbstractLogEnabled
implements MetadataResolver
{
//------------------------------------------------------------------------
@Requirement
ArtifactResolver artifactResolver;
@Requirement
ArtifactFactory artifactFactory;
@Requirement
MetadataSource metadataSource;
@Requirement
GraphConflictResolver conflictResolver;
@Requirement
ClasspathTransformation classpathTransformation;
//------------------------------------------------------------------------
public MetadataResolutionResult resolveMetadata( MetadataResolutionRequest req )
throws MetadataResolutionException
{
try
{
getLogger().debug( "Received request for: " + req.getQuery() );
MetadataResolutionResult res = new MetadataResolutionResult();
MetadataTreeNode tree = resolveMetadataTree( req.getQuery()
, null
, req.getLocalRepository()
, req.getRemoteRepositories()
);
res.setTree( tree );
return res;
}
catch ( MetadataResolutionException mrEx )
{
throw mrEx;
}
catch ( Exception anyEx )
{
throw new MetadataResolutionException( anyEx );
}
}
//------------------------------------------------------------------------
private MetadataTreeNode resolveMetadataTree( ArtifactMetadata query
, MetadataTreeNode parent
, ArtifactRepository localRepository
, List<ArtifactRepository> remoteRepositories
)
throws MetadataResolutionException
{
try
{
Artifact pomArtifact = artifactFactory.createArtifact(
query.getGroupId()
, query.getArtifactId()
, query.getVersion()
, query.getScope()
, query.getType() == null ? "jar" : query.getType()
);
getLogger().debug( "resolveMetadata request:"
+ "\n> artifact : " + pomArtifact.toString()
+ "\n> remoteRepos: " + remoteRepositories
+ "\n> localRepo : " + localRepository
);
String error = null;
try
{
ArtifactResolutionRequest arr = new ArtifactResolutionRequest();
arr.setArtifact( pomArtifact );
arr.setLocalRepository( localRepository );
arr.setRemoteRepostories( remoteRepositories );
artifactResolver.resolve( pomArtifact, remoteRepositories , localRepository );
//System.out.println("Resolved "+query+" : "+pomArtifact.isResolved() );
if ( !pomArtifact.isResolved() )
{
getLogger().info( "*************> Did not resolve " + pomArtifact.toString()
+ "\nURL: " + pomArtifact.getDownloadUrl()
+ "\nRepos: " + remoteRepositories
+ "\nLocal: " + localRepository
);
}
}
catch ( ArtifactResolutionException are )
{
pomArtifact.setResolved( false );
error = are.getMessage();
}
catch ( ArtifactNotFoundException anfe )
{
pomArtifact.setResolved( false );
error = anfe.getMessage();
}
if( error != null )
{
getLogger().info( "*************> Did not resolve " + pomArtifact.toString()
+ "\nRepos: " + remoteRepositories
+ "\nLocal: " + localRepository
+ "\nerror: " + error
);
}
if( pomArtifact.isResolved() )
{
MetadataResolution metadataResolution = metadataSource.retrieve(
query
, localRepository
, remoteRepositories
);
ArtifactMetadata found = metadataResolution.getArtifactMetadata();
if( pomArtifact.getFile() != null && pomArtifact.getFile().toURI() != null )
found.setArtifactUri( pomArtifact.getFile().toURI().toString() );
MetadataTreeNode node = new MetadataTreeNode( found
, parent
, true
, found.getScopeAsEnum()
);
Collection<ArtifactMetadata> dependencies
= metadataResolution.getArtifactMetadata().getDependencies();
if( dependencies != null && dependencies.size() > 0 )
{
int nKids = dependencies.size();
node.setNChildren(nKids);
int kidNo = 0;
for ( ArtifactMetadata a : dependencies )
{
MetadataTreeNode kidNode = resolveMetadataTree( a
, node
, localRepository
, remoteRepositories
);
node.addChild( kidNo++, kidNode );
}
}
return node;
} else {
return new MetadataTreeNode( pomArtifact, parent, false, query.getArtifactScope() );
}
}
catch( Exception anyEx )
{
throw new MetadataResolutionException( anyEx );
}
}
//------------------------------------------------------------------------
public List<Artifact> resolveArtifact(
List<ArtifactMetadata> mdCollection
, ArtifactRepository localRepository
, List<ArtifactRepository> remoteRepositories
)
throws ArtifactResolutionException
{
if( mdCollection == null || mdCollection.isEmpty() )
return null;
ArrayList<Artifact> res = new ArrayList<Artifact>( mdCollection.size() );
Artifact artifact = null;
try {
// TODO: optimize retrieval by zipping returns from repo managers (nexus)
for( ArtifactMetadata md : mdCollection )
{
artifact = artifactFactory.createArtifact(
md.getGroupId()
, md.getArtifactId()
, md.getVersion()
, md.getScope()
, md.getType() == null ? "jar" : md.getType()
);
artifactResolver.resolve( artifact, remoteRepositories , localRepository );
res.add(artifact);
}
return res;
} catch (ArtifactNotFoundException e) {
e.printStackTrace();
throw new ArtifactResolutionException( e.getMessage()
, artifact
, remoteRepositories
);
}
}
//------------------------------------------------------------------------
//------------------------------------------------------------------------
}

View File

@ -1,45 +0,0 @@
package org.apache.maven.artifact.resolver.metadata;
import java.util.Collection;
import java.util.List;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
/**
* entry point into metadata resolution component
*
* @author <a href="oleg@codehaus.org">Oleg Gusakov</a>
*
*/
public interface MetadataResolver
{
String ROLE = MetadataResolver.class.getName();
/**
* collect all dependency metadata into one "dirty" tree
*
* @param request
* @return
* @throws MetadataResolutionException
*/
MetadataResolutionResult resolveMetadata( MetadataResolutionRequest request )
throws MetadataResolutionException;
/**
* resolve artifact List, given metadata List (order matters!)
*
* @param mdCollection - collection of artifact metadata's
* @param localRepository
* @param remoteRepositories
* @return collection of resolved artifacts
* @throws ArtifactResolutionException
*/
public List<Artifact> resolveArtifact(
List<ArtifactMetadata> mdCollection,
ArtifactRepository localRepository,
List<ArtifactRepository> remoteRepositories)
throws ArtifactResolutionException;
}

View File

@ -19,14 +19,6 @@ package org.apache.maven.artifact.resolver;
* under the License.
*/
import org.apache.maven.artifact.AbstractArtifactComponentTestCase;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.metadata.ResolutionGroup;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.versioning.ArtifactVersion;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
@ -35,6 +27,14 @@ import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import org.apache.maven.artifact.AbstractArtifactComponentTestCase;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.metadata.ResolutionGroup;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.versioning.ArtifactVersion;
// It would be cool if there was a hook that i could use to setup a test environment.
// I want to setup a local/remote repositories for testing but i don't want to have
// to change them when i change the layout of the repositories. So i want to generate
@ -48,7 +48,7 @@ import java.util.Set;
public class ArtifactResolverTest
extends AbstractArtifactComponentTestCase
{
private ArtifactResolver artifactResolver;
private DefaultArtifactResolver artifactResolver;
private Artifact projectArtifact;
@ -58,7 +58,7 @@ public class ArtifactResolverTest
{
super.setUp();
artifactResolver = (ArtifactResolver) lookup( ArtifactResolver.ROLE );
artifactResolver = (DefaultArtifactResolver) lookup( ArtifactResolver.class );
projectArtifact = createLocalArtifact( "project", "3.0" );
}

View File

@ -19,6 +19,10 @@ package org.apache.maven.artifact.resolver;
* under the License.
*/
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import org.apache.maven.artifact.AbstractArtifactComponentTestCase;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.manager.WagonManager;
@ -32,10 +36,6 @@ import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryM
import org.apache.maven.artifact.repository.metadata.Versioning;
import org.codehaus.plexus.util.FileUtils;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
public class ArtifactUpdatePolicyTest
extends AbstractArtifactComponentTestCase
{
@ -46,7 +46,7 @@ public class ArtifactUpdatePolicyTest
private static final long TWO_DAYS = 2 * 86400L * 1000L;
private ArtifactResolver artifactResolver;
private DefaultArtifactResolver artifactResolver;
private List<ArtifactRepository> remoteRepositories;
@ -70,7 +70,7 @@ public class ArtifactUpdatePolicyTest
{
super.setUp();
artifactResolver = (ArtifactResolver) lookup( ArtifactResolver.ROLE );
artifactResolver = (DefaultArtifactResolver) lookup( ArtifactResolver.class );
remoteRepositories = remoteRepositories();
remoteRepository = (DefaultArtifactRepository) remoteRepositories.get( 0 );

View File

@ -9,7 +9,7 @@ public class DefaultArtifactResolverTest
public void testLookup()
throws Exception
{
ArtifactResolver resolver = (ArtifactResolver) lookup( ArtifactResolver.ROLE, "default" );
ArtifactResolver resolver = lookup( ArtifactResolver.class, "default" );
}
}

View File

@ -43,7 +43,6 @@ import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
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.MultipleArtifactsNotFoundException;
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
@ -480,10 +479,7 @@ public class DefaultPluginManager
resolved.add( artifact );
}
getLogger().debug(
"Using the following artifacts for classpath of: "
+ pluginArtifact.getId() + ":\n\n"
+ resolved.toString().replace( ',', '\n' ) );
getLogger().debug( "Using the following artifacts for classpath of: " + pluginArtifact.getId() + ":\n\n" + resolved.toString().replace( ',', '\n' ) );
return resolved;
}
@ -1602,13 +1598,13 @@ public class DefaultPluginManager
throws ArtifactResolutionException, ArtifactNotFoundException
{
ArtifactRepository localRepository = context.getLocalRepository();
List remoteArtifactRepositories = project.getRemoteArtifactRepositories();
List<ArtifactRepository> remoteArtifactRepositories = project.getRemoteArtifactRepositories();
for ( Iterator it = project.getArtifacts().iterator(); it.hasNext(); )
for ( Iterator<Artifact> it = project.getArtifacts().iterator(); it.hasNext(); )
{
Artifact artifact = (Artifact) it.next();
repositorySystem.resolve( artifact, localRepository, remoteArtifactRepositories );
repositorySystem.resolve( new ArtifactResolutionRequest( artifact, localRepository, remoteArtifactRepositories ) );
}
}

View File

@ -19,17 +19,17 @@ package org.apache.maven.plugin;
* under the License.
*/
import java.util.ArrayList;
import java.util.List;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.artifact.resolver.ArtifactResolutionRequest;
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
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.execution.RuntimeInformation;
import org.apache.maven.model.Plugin;
@ -43,6 +43,8 @@ import org.apache.maven.project.ProjectBuildingException;
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
import org.apache.maven.realm.RealmManagementException;
import org.apache.maven.realm.RealmScanningUtils;
import org.apache.maven.repository.MavenRepositorySystem;
import org.apache.maven.repository.VersionNotFoundException;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.context.Context;
@ -51,19 +53,13 @@ import org.codehaus.plexus.logging.LogEnabled;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
import java.util.ArrayList;
import java.util.List;
@Component(role = PluginManagerSupport.class)
public class DefaultPluginManagerSupport
implements PluginManagerSupport, LogEnabled, Contextualizable
{
@Requirement
private ArtifactResolver artifactResolver;
@Requirement
private ArtifactFactory artifactFactory;
private MavenRepositorySystem repositorySystem;
@Requirement
private MavenProjectBuilder mavenProjectBuilder;
@ -86,16 +82,6 @@ public class DefaultPluginManagerSupport
{
ArtifactRepository localRepository = session.getLocalRepository();
VersionRange versionRange;
try
{
versionRange = VersionRange.createFromVersionSpec( plugin.getVersion() );
}
catch ( InvalidVersionSpecificationException e )
{
throw new PluginManagerException( plugin, e );
}
List remoteRepositories = new ArrayList();
remoteRepositories.addAll( project.getRemoteArtifactRepositories() );
@ -122,25 +108,19 @@ public class DefaultPluginManagerSupport
checkPluginDependencySpec( plugin, pluginProject );
Artifact pluginArtifact = artifactFactory.createPluginArtifact( plugin.getGroupId(),
plugin.getArtifactId(),
versionRange );
Artifact pluginArtifact = repositorySystem.createPluginArtifact( plugin.getGroupId(), plugin.getArtifactId(), plugin.getVersion() );
pluginArtifact = project.replaceWithActiveArtifact( pluginArtifact );
artifactResolver.resolve( pluginArtifact, remoteRepositories, localRepository );
repositorySystem.resolve( new ArtifactResolutionRequest( pluginArtifact, localRepository, remoteRepositories ) );
return pluginArtifact;
}
public MavenProject buildPluginProject( Plugin plugin,
ArtifactRepository localRepository,
List remoteRepositories )
public MavenProject buildPluginProject( Plugin plugin, ArtifactRepository localRepository, List remoteRepositories )
throws InvalidPluginException
{
Artifact artifact = artifactFactory.createProjectArtifact( plugin.getGroupId(),
plugin.getArtifactId(),
plugin.getVersion() );
Artifact artifact = repositorySystem.createProjectArtifact( plugin.getGroupId(), plugin.getArtifactId(), plugin.getVersion() );
try
{
return mavenProjectBuilder.buildFromRepository( artifact,
@ -183,19 +163,17 @@ public class DefaultPluginManagerSupport
}
}
public void checkPluginDependencySpec( Plugin plugin,
MavenProject pluginProject )
public void checkPluginDependencySpec( Plugin plugin, MavenProject pluginProject )
throws InvalidPluginException
{
ArtifactFilter filter = new ScopeArtifactFilter( "runtime" );
try
{
pluginProject.createArtifacts( artifactFactory, null, filter );
repositorySystem.createArtifacts( pluginProject.getDependencies(), null, filter, pluginProject );
}
catch ( InvalidDependencyVersionException e )
catch ( VersionNotFoundException e )
{
throw new InvalidPluginException( "Plugin: " + plugin.getKey()
+ " has a dependency with an invalid version.", e );
throw new InvalidPluginException( "Plugin: " + plugin.getKey() + " has a dependency with an invalid version." );
}
}

View File

@ -19,10 +19,25 @@ package org.apache.maven.project;
* under the License.
*/
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.*;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.io.StringWriter;
import java.io.Writer;
import java.lang.reflect.Method;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.ArtifactUtils;
@ -35,33 +50,39 @@ import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
import org.apache.maven.model.Build;
import org.apache.maven.model.Model;
import org.apache.maven.model.Profile;
import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.project.ProfileManager;
import org.apache.maven.project.DefaultProfileManager;
import org.apache.maven.project.ProfileActivationContext;
import org.apache.maven.project.ProfileActivationException;
import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
import org.apache.maven.project.builder.*;
import org.apache.maven.project.builder.PomClassicDomainModel;
import org.apache.maven.project.builder.PomClassicDomainModelFactory;
import org.apache.maven.project.builder.PomInterpolatorTag;
import org.apache.maven.project.builder.PomTransformer;
import org.apache.maven.project.builder.ProjectUri;
import org.apache.maven.project.builder.profile.ProfileContext;
import org.apache.maven.project.validation.ModelValidationResult;
import org.apache.maven.project.validation.ModelValidator;
import org.apache.maven.repository.MavenRepositorySystem;
import org.apache.maven.repository.VersionNotFoundException;
import org.apache.maven.shared.model.*;
import org.apache.maven.shared.model.DomainModel;
import org.apache.maven.shared.model.InterpolatorProperty;
import org.apache.maven.shared.model.ModelContainer;
import org.apache.maven.shared.model.ModelEventListener;
import org.apache.maven.shared.model.ModelMarshaller;
import org.apache.maven.shared.model.ModelProperty;
import org.apache.maven.shared.model.ModelTransformerContext;
import org.apache.maven.shared.model.impl.DefaultModelDataSource;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.logging.LogEnabled;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.ReaderFactory;
import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.WriterFactory;
import org.codehaus.plexus.util.ReaderFactory;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.xml.pull.MXSerializer;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import org.codehaus.plexus.util.xml.pull.XmlSerializer;
import org.codehaus.plexus.util.xml.pull.MXSerializer;
import org.codehaus.plexus.PlexusContainer;
/**
@ -303,8 +324,7 @@ public class DefaultMavenProjectBuilder
this.logger = logger;
}
private MavenProject buildWithProfiles( Model model, ProjectBuilderConfiguration config, File projectDescriptor,
File parentDescriptor )
private MavenProject buildWithProfiles( Model model, ProjectBuilderConfiguration config, File projectDescriptor, File parentDescriptor )
throws ProjectBuildingException
{
String projectId = safeVersionlessKey( model.getGroupId(), model.getArtifactId() );
@ -763,31 +783,6 @@ public class DefaultMavenProjectBuilder
}
}
private void resolve( Artifact artifact, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories )
throws IOException
{
if(localRepository == null || remoteRepositories == null)
{
throw new IOException("LocalRepository or RemoteRepositories: null");
}
File artifactFile = new File( localRepository.getBasedir(), localRepository.pathOf( artifact ) );
artifact.setFile( artifactFile );
try
{
repositorySystem.resolve( artifact, localRepository, remoteRepositories );
}
catch ( ArtifactResolutionException e )
{
throw new IOException( e.getMessage() );
}
catch ( ArtifactNotFoundException e )
{
throw new IOException( e.getMessage() );
}
}
private List<DomainModel> getDomainModelParentsFromRepository( PomClassicDomainModel domainModel,
ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories,
List<InterpolatorProperty> properties,
@ -807,14 +802,15 @@ public class DefaultMavenProjectBuilder
Artifact artifactParent = repositorySystem.createParentArtifact( domainModel.getParentGroupId(),
domainModel.getParentArtifactId(), domainModel.getParentVersion() );
resolve( artifactParent, localRepository, remoteRepositories );
ArtifactResolutionResult result = repositorySystem.resolve( new ArtifactResolutionRequest( artifactParent, localRepository, remoteRepositories ) );
PomClassicDomainModel parentDomainModel = new PomClassicDomainModel( artifactParent.getFile() );
if ( !parentDomainModel.matchesParentOf( domainModel ) )
{
logger.debug( "Parent pom ids do not match: Parent File = " + artifactParent.getFile().getAbsolutePath() +
": Child ID = " + domainModel.getId() );
//shane: what does this mean exactly and why does it occur
logger.debug( "Parent pom ids do not match: Parent File = " + artifactParent.getFile().getAbsolutePath() + ": Child ID = " + domainModel.getId() );
return domainModels;
}

View File

@ -96,6 +96,18 @@ public class LegacyMavenRepositorySystem
@Requirement
private Logger logger;
private boolean online = true;
private boolean interactive = true;
private TransferListener downloadMonitor;
private Map<String, ProxyInfo> proxies = new HashMap<String, ProxyInfo>();
private Map<String, AuthenticationInfo> authenticationInfoMap = new HashMap<String, AuthenticationInfo>();
private Map<String, RepositoryPermissions> serverPermissionsMap = new HashMap<String, RepositoryPermissions>();
private static HashMap<String, Artifact> cache = new HashMap<String, Artifact>();
// Artifact Creation
@ -454,7 +466,7 @@ public class LegacyMavenRepositorySystem
projectArtifact = artifactFactory.createProjectArtifact( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getScope() );
}
resolve( projectArtifact, localRepository, remoteArtifactRepositories );
resolve( new ArtifactResolutionRequest( projectArtifact, localRepository, remoteArtifactRepositories ) );
File file = projectArtifact.getFile();
artifact.setFile( file );
@ -518,35 +530,11 @@ public class LegacyMavenRepositorySystem
return ArtifactUtils.versionlessKey( gid, aid );
}
/**
* Resolves the specified artifact
*
* @param artifact the artifact to resolve
* @throws IOException if there is a problem resolving the artifact
*/
public void resolve( Artifact artifact, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories )
throws ArtifactResolutionException, ArtifactNotFoundException
{
artifactResolver.resolve( artifact, remoteRepositories, localRepository );
}
public ArtifactResolutionResult resolve( ArtifactResolutionRequest request )
{
{
return artifactResolver.resolve( request );
}
private boolean online = true;
private boolean interactive = true;
private TransferListener downloadMonitor;
private Map<String, ProxyInfo> proxies = new HashMap<String, ProxyInfo>();
private Map<String, AuthenticationInfo> authenticationInfoMap = new HashMap<String, AuthenticationInfo>();
private Map<String, RepositoryPermissions> serverPermissionsMap = new HashMap<String, RepositoryPermissions>();
public void setOnline( boolean online )
{
this.online = online;

View File

@ -89,15 +89,11 @@ public interface MavenRepositorySystem
ArtifactResolutionResult resolve( ArtifactResolutionRequest request );
// This can be reduced to the request/result
void resolve( Artifact artifact, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories )
throws ArtifactResolutionException, ArtifactNotFoundException;
// Metadata
void findModelFromRepository( Artifact artifact, List remoteArtifactRepositories, ArtifactRepository localRepository )
throws InvalidRepositoryException, ArtifactResolutionException, ArtifactNotFoundException;
// Version retrieval or metadata operations
ResolutionGroup retrieve( Artifact artifact, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories )
throws ArtifactMetadataRetrievalException;