mirror of https://github.com/apache/maven.git
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:
parent
7c537105b2
commit
613253dda7
|
@ -31,7 +31,7 @@ public class ArtifactResolutionRequest
|
||||||
|
|
||||||
private ArtifactRepository localRepository;
|
private ArtifactRepository localRepository;
|
||||||
|
|
||||||
private List<ArtifactRepository> remoteRepostories;
|
private List<ArtifactRepository> remoteRepositories;
|
||||||
|
|
||||||
private ArtifactFilter filter;
|
private ArtifactFilter filter;
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ public class ArtifactResolutionRequest
|
||||||
{
|
{
|
||||||
this.artifact = artifact;
|
this.artifact = artifact;
|
||||||
this.localRepository = localRepository;
|
this.localRepository = localRepository;
|
||||||
this.remoteRepostories = remoteRepositories;
|
this.remoteRepositories = remoteRepositories;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Artifact getArtifact()
|
public Artifact getArtifact()
|
||||||
|
@ -149,12 +149,12 @@ public class ArtifactResolutionRequest
|
||||||
|
|
||||||
public List<ArtifactRepository> getRemoteRepostories()
|
public List<ArtifactRepository> getRemoteRepostories()
|
||||||
{
|
{
|
||||||
return remoteRepostories;
|
return remoteRepositories;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArtifactResolutionRequest setRemoteRepostories( List<ArtifactRepository> remoteRepostories )
|
public ArtifactResolutionRequest setRemoteRepostories( List<ArtifactRepository> remoteRepostories )
|
||||||
{
|
{
|
||||||
this.remoteRepostories = remoteRepostories;
|
this.remoteRepositories = remoteRepostories;
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -176,6 +176,13 @@ public class ArtifactResolutionRequest
|
||||||
return listeners;
|
return listeners;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ArtifactResolutionRequest setListeners( List<ResolutionListener> listeners )
|
||||||
|
{
|
||||||
|
this.listeners = listeners;
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public ArtifactResolutionRequest addListener( ResolutionListener listener )
|
public ArtifactResolutionRequest addListener( ResolutionListener listener )
|
||||||
{
|
{
|
||||||
listeners.add( listener );
|
listeners.add( listener );
|
||||||
|
|
|
@ -63,8 +63,8 @@ public class ArtifactResolutionResult
|
||||||
|
|
||||||
private List<ArtifactRepository> repositories;
|
private List<ArtifactRepository> repositories;
|
||||||
|
|
||||||
private Set<ResolutionNode> resolutionNodes;
|
private Set<Artifact> requestedArtifacts;
|
||||||
|
|
||||||
private Set<Artifact> artifacts;
|
private Set<Artifact> artifacts;
|
||||||
|
|
||||||
public Artifact getOriginatingArtifact()
|
public Artifact getOriginatingArtifact()
|
||||||
|
@ -79,40 +79,37 @@ public class ArtifactResolutionResult
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<Artifact> getArtifacts()
|
public void addArtifact( Artifact artifact )
|
||||||
{
|
{
|
||||||
if ( artifacts == null )
|
if ( artifacts == null )
|
||||||
{
|
{
|
||||||
artifacts = new LinkedHashSet<Artifact>();
|
artifacts = new LinkedHashSet<Artifact>();
|
||||||
|
|
||||||
for (ResolutionNode node : resolutionNodes)
|
|
||||||
{
|
|
||||||
artifacts.add(node.getArtifact());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
artifacts.add( artifact );
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<Artifact> getArtifacts()
|
||||||
|
{
|
||||||
return artifacts;
|
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;
|
return requestedArtifacts;
|
||||||
|
}
|
||||||
// clear the cache
|
|
||||||
this.artifacts = null;
|
public List<Artifact> getMissingArtifacts()
|
||||||
}
|
|
||||||
|
|
||||||
public List getMissingArtifacts()
|
|
||||||
{
|
{
|
||||||
return missingArtifacts == null ? Collections.EMPTY_LIST : missingArtifacts;
|
return missingArtifacts == null ? Collections.EMPTY_LIST : missingArtifacts;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,123 +19,13 @@ package org.apache.maven.artifact.resolver;
|
||||||
* under the License.
|
* 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
|
* @author Jason van Zyl
|
||||||
* @version $Id$
|
|
||||||
*/
|
*/
|
||||||
public interface ArtifactResolver
|
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 resolve( ArtifactResolutionRequest request );
|
||||||
|
|
||||||
|
ArtifactResolutionResult resolveWithExceptions( ArtifactResolutionRequest request )
|
||||||
|
throws ArtifactResolutionException, ArtifactNotFoundException;
|
||||||
}
|
}
|
|
@ -170,6 +170,8 @@ public class DefaultArtifactCollector
|
||||||
artifact.setDependencyTrail( node.getDependencyTrail() );
|
artifact.setDependencyTrail( node.getDependencyTrail() );
|
||||||
|
|
||||||
set.add( node );
|
set.add( node );
|
||||||
|
|
||||||
|
result.addRequestedArtifact( artifact );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -181,8 +183,6 @@ public class DefaultArtifactCollector
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
result.setArtifactResolutionNodes( set );
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -291,34 +291,28 @@ public class DefaultArtifactResolver
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArtifactResolutionResult resolveTransitively( Set<Artifact> artifacts, Artifact originatingArtifact, Map managedVersions, ArtifactRepository localRepository,
|
public ArtifactResolutionResult resolveTransitively( Set<Artifact> artifacts, Artifact originatingArtifact, Map managedVersions, ArtifactRepository localRepository,
|
||||||
List<ArtifactRepository> remoteRepositories, ArtifactMetadataSource source, ArtifactFilter filter, List<ResolutionListener> listeners,
|
List<ArtifactRepository> remoteRepositories, ArtifactMetadataSource source, ArtifactFilter filter, List<ResolutionListener> listeners,
|
||||||
List<ConflictResolver> conflictResolvers )
|
List<ConflictResolver> conflictResolvers )
|
||||||
throws ArtifactResolutionException, ArtifactNotFoundException
|
throws ArtifactResolutionException, ArtifactNotFoundException
|
||||||
{
|
{
|
||||||
if ( listeners == null )
|
ArtifactResolutionRequest request = new ArtifactResolutionRequest()
|
||||||
{
|
.setArtifact( originatingArtifact )
|
||||||
// TODO: this is simplistic.
|
.setArtifactDependencies( artifacts )
|
||||||
listeners = new ArrayList<ResolutionListener>();
|
.setManagedVersionMap( managedVersions )
|
||||||
if ( getLogger().isDebugEnabled() )
|
.setLocalRepository( localRepository )
|
||||||
{
|
.setRemoteRepostories( remoteRepositories )
|
||||||
listeners.add( new DebugResolutionListener( getLogger() ) );
|
.setMetadataSource( source )
|
||||||
}
|
.setFilter( filter )
|
||||||
|
.setListeners( listeners )
|
||||||
listeners.add( new WarningResolutionListener( getLogger() ) );
|
.setConflictResolvers( conflictResolvers );
|
||||||
}
|
|
||||||
|
return resolveWithExceptions( request );
|
||||||
ArtifactResolutionResult result;
|
}
|
||||||
|
|
||||||
result = artifactCollector.collect(
|
public ArtifactResolutionResult resolveWithExceptions( ArtifactResolutionRequest request )
|
||||||
artifacts,
|
throws ArtifactResolutionException, ArtifactNotFoundException
|
||||||
originatingArtifact,
|
{
|
||||||
managedVersions,
|
ArtifactResolutionResult result = resolve( request );
|
||||||
localRepository,
|
|
||||||
remoteRepositories,
|
|
||||||
source,
|
|
||||||
filter,
|
|
||||||
listeners,
|
|
||||||
conflictResolvers );
|
|
||||||
|
|
||||||
// We have collected all the problems so let's mimic the way the old code worked and just blow up right here.
|
// 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
|
// 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 );
|
throw result.getVersionRangeViolation( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Artifact> resolvedArtifacts = new ArrayList<Artifact>();
|
if ( result.getMissingArtifacts().size() > 0 )
|
||||||
|
|
||||||
List<Artifact> missingArtifacts = new ArrayList<Artifact>();
|
|
||||||
|
|
||||||
for ( ResolutionNode node : result.getArtifactResolutionNodes() )
|
|
||||||
{
|
{
|
||||||
try
|
throw new MultipleArtifactsNotFoundException( request.getArtifact(), new ArrayList( result.getArtifacts() ), result.getMissingArtifacts(), request.getRemoteRepostories() );
|
||||||
{
|
|
||||||
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 );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
@ -382,33 +356,28 @@ public class DefaultArtifactResolver
|
||||||
public ArtifactResolutionResult resolve( ArtifactResolutionRequest request )
|
public ArtifactResolutionResult resolve( ArtifactResolutionRequest request )
|
||||||
{
|
{
|
||||||
Artifact originatingArtifact = request.getArtifact();
|
Artifact originatingArtifact = request.getArtifact();
|
||||||
|
|
||||||
Set<Artifact> artifacts = request.getArtifactDependencies();
|
Set<Artifact> artifacts = request.getArtifactDependencies();
|
||||||
|
|
||||||
Map managedVersions = request.getManagedVersionMap();
|
Map managedVersions = request.getManagedVersionMap();
|
||||||
|
|
||||||
ArtifactRepository localRepository = request.getLocalRepository();
|
ArtifactRepository localRepository = request.getLocalRepository();
|
||||||
|
|
||||||
List<ArtifactRepository> remoteRepositories = request.getRemoteRepostories();
|
List<ArtifactRepository> remoteRepositories = request.getRemoteRepostories();
|
||||||
|
|
||||||
ArtifactMetadataSource source = request.getMetadataSource();
|
ArtifactMetadataSource source = request.getMetadataSource();
|
||||||
|
|
||||||
List<ResolutionListener> listeners = request.getListeners();
|
List<ResolutionListener> listeners = request.getListeners();
|
||||||
|
|
||||||
ArtifactFilter filter = request.getFilter();
|
ArtifactFilter filter = request.getFilter();
|
||||||
|
|
||||||
// This is an attempt to get the metadata for the artifacts we are ultimately trying to resolve.
|
if ( listeners == null )
|
||||||
// We still
|
{
|
||||||
|
listeners = new ArrayList<ResolutionListener>();
|
||||||
|
|
||||||
|
if ( getLogger().isDebugEnabled() )
|
||||||
|
{
|
||||||
|
listeners.add( new DebugResolutionListener( getLogger() ) );
|
||||||
|
}
|
||||||
|
|
||||||
ArtifactResolutionResult result = artifactCollector.collect(
|
listeners.add( new WarningResolutionListener( getLogger() ) );
|
||||||
artifacts,
|
}
|
||||||
originatingArtifact,
|
|
||||||
managedVersions,
|
// After the collection we will have the artifact object in the result but they will not be resolved yet.
|
||||||
localRepository,
|
ArtifactResolutionResult result = artifactCollector.collect( artifacts, originatingArtifact, managedVersions, localRepository, remoteRepositories, source, filter, listeners );
|
||||||
remoteRepositories,
|
|
||||||
source,
|
|
||||||
filter,
|
|
||||||
listeners );
|
|
||||||
|
|
||||||
// Let's grab all the repositories that were gleaned. This we should know up front. I'm not sure
|
// 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.
|
// 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
|
// so we give this back to the calling code and let them deal with this information
|
||||||
// appropriately.
|
// appropriately.
|
||||||
|
|
||||||
if ( result.hasMetadataResolutionExceptions() || result.hasVersionRangeViolations() )
|
if ( result.hasMetadataResolutionExceptions() || result.hasVersionRangeViolations() || result.hasCircularDependencyExceptions() )
|
||||||
{
|
{
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( ResolutionNode node : result.getArtifactResolutionNodes() )
|
for ( Artifact requestedArtifact : result.getRequestedArtifacts() )
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
resolve( node.getArtifact(), node.getRemoteRepositories(), localRepository );
|
resolve( requestedArtifact, remoteRepositories, localRepository );
|
||||||
|
|
||||||
|
result.addArtifact( requestedArtifact );
|
||||||
}
|
}
|
||||||
catch ( ArtifactNotFoundException anfe )
|
catch ( ArtifactNotFoundException anfe )
|
||||||
{
|
{
|
||||||
// These are cases where the artifact just isn't present in any of the remote repositories
|
// 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.
|
// because it wasn't deployed, or it was deployed in the wrong place.
|
||||||
|
|
||||||
result.addMissingArtifact( node.getArtifact() );
|
result.addMissingArtifact( requestedArtifact );
|
||||||
}
|
}
|
||||||
catch ( ArtifactResolutionException e )
|
catch ( ArtifactResolutionException e )
|
||||||
{
|
{
|
||||||
|
|
|
@ -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
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//------------------------------------------------------------------------
|
|
||||||
//------------------------------------------------------------------------
|
|
||||||
}
|
|
|
@ -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;
|
|
||||||
}
|
|
|
@ -19,14 +19,6 @@ package org.apache.maven.artifact.resolver;
|
||||||
* under the License.
|
* 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.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
@ -35,6 +27,14 @@ import java.util.LinkedHashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
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.
|
// 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
|
// 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
|
// 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
|
public class ArtifactResolverTest
|
||||||
extends AbstractArtifactComponentTestCase
|
extends AbstractArtifactComponentTestCase
|
||||||
{
|
{
|
||||||
private ArtifactResolver artifactResolver;
|
private DefaultArtifactResolver artifactResolver;
|
||||||
|
|
||||||
private Artifact projectArtifact;
|
private Artifact projectArtifact;
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ public class ArtifactResolverTest
|
||||||
{
|
{
|
||||||
super.setUp();
|
super.setUp();
|
||||||
|
|
||||||
artifactResolver = (ArtifactResolver) lookup( ArtifactResolver.ROLE );
|
artifactResolver = (DefaultArtifactResolver) lookup( ArtifactResolver.class );
|
||||||
|
|
||||||
projectArtifact = createLocalArtifact( "project", "3.0" );
|
projectArtifact = createLocalArtifact( "project", "3.0" );
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,10 @@ package org.apache.maven.artifact.resolver;
|
||||||
* under the License.
|
* 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.AbstractArtifactComponentTestCase;
|
||||||
import org.apache.maven.artifact.Artifact;
|
import org.apache.maven.artifact.Artifact;
|
||||||
import org.apache.maven.artifact.manager.WagonManager;
|
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.apache.maven.artifact.repository.metadata.Versioning;
|
||||||
import org.codehaus.plexus.util.FileUtils;
|
import org.codehaus.plexus.util.FileUtils;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class ArtifactUpdatePolicyTest
|
public class ArtifactUpdatePolicyTest
|
||||||
extends AbstractArtifactComponentTestCase
|
extends AbstractArtifactComponentTestCase
|
||||||
{
|
{
|
||||||
|
@ -46,7 +46,7 @@ public class ArtifactUpdatePolicyTest
|
||||||
|
|
||||||
private static final long TWO_DAYS = 2 * 86400L * 1000L;
|
private static final long TWO_DAYS = 2 * 86400L * 1000L;
|
||||||
|
|
||||||
private ArtifactResolver artifactResolver;
|
private DefaultArtifactResolver artifactResolver;
|
||||||
|
|
||||||
private List<ArtifactRepository> remoteRepositories;
|
private List<ArtifactRepository> remoteRepositories;
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ public class ArtifactUpdatePolicyTest
|
||||||
{
|
{
|
||||||
super.setUp();
|
super.setUp();
|
||||||
|
|
||||||
artifactResolver = (ArtifactResolver) lookup( ArtifactResolver.ROLE );
|
artifactResolver = (DefaultArtifactResolver) lookup( ArtifactResolver.class );
|
||||||
|
|
||||||
remoteRepositories = remoteRepositories();
|
remoteRepositories = remoteRepositories();
|
||||||
remoteRepository = (DefaultArtifactRepository) remoteRepositories.get( 0 );
|
remoteRepository = (DefaultArtifactRepository) remoteRepositories.get( 0 );
|
||||||
|
|
|
@ -9,7 +9,7 @@ public class DefaultArtifactResolverTest
|
||||||
public void testLookup()
|
public void testLookup()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
ArtifactResolver resolver = (ArtifactResolver) lookup( ArtifactResolver.ROLE, "default" );
|
ArtifactResolver resolver = lookup( ArtifactResolver.class, "default" );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,6 @@ import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
|
||||||
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
||||||
import org.apache.maven.artifact.resolver.ArtifactResolutionRequest;
|
import org.apache.maven.artifact.resolver.ArtifactResolutionRequest;
|
||||||
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
|
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.ArtifactFilter;
|
||||||
import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
|
import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
|
||||||
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
|
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
|
||||||
|
@ -480,10 +479,7 @@ public class DefaultPluginManager
|
||||||
resolved.add( artifact );
|
resolved.add( artifact );
|
||||||
}
|
}
|
||||||
|
|
||||||
getLogger().debug(
|
getLogger().debug( "Using the following artifacts for classpath of: " + pluginArtifact.getId() + ":\n\n" + resolved.toString().replace( ',', '\n' ) );
|
||||||
"Using the following artifacts for classpath of: "
|
|
||||||
+ pluginArtifact.getId() + ":\n\n"
|
|
||||||
+ resolved.toString().replace( ',', '\n' ) );
|
|
||||||
|
|
||||||
return resolved;
|
return resolved;
|
||||||
}
|
}
|
||||||
|
@ -1602,13 +1598,13 @@ public class DefaultPluginManager
|
||||||
throws ArtifactResolutionException, ArtifactNotFoundException
|
throws ArtifactResolutionException, ArtifactNotFoundException
|
||||||
{
|
{
|
||||||
ArtifactRepository localRepository = context.getLocalRepository();
|
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();
|
Artifact artifact = (Artifact) it.next();
|
||||||
|
|
||||||
repositorySystem.resolve( artifact, localRepository, remoteArtifactRepositories );
|
repositorySystem.resolve( new ArtifactResolutionRequest( artifact, localRepository, remoteArtifactRepositories ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,17 +19,17 @@ package org.apache.maven.plugin;
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.maven.artifact.Artifact;
|
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.repository.ArtifactRepository;
|
||||||
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
|
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
|
||||||
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
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.ArtifactFilter;
|
||||||
import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
|
import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
|
||||||
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
|
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.MavenSession;
|
||||||
import org.apache.maven.execution.RuntimeInformation;
|
import org.apache.maven.execution.RuntimeInformation;
|
||||||
import org.apache.maven.model.Plugin;
|
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.project.artifact.InvalidDependencyVersionException;
|
||||||
import org.apache.maven.realm.RealmManagementException;
|
import org.apache.maven.realm.RealmManagementException;
|
||||||
import org.apache.maven.realm.RealmScanningUtils;
|
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.Component;
|
||||||
import org.codehaus.plexus.component.annotations.Requirement;
|
import org.codehaus.plexus.component.annotations.Requirement;
|
||||||
import org.codehaus.plexus.context.Context;
|
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.logging.Logger;
|
||||||
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
|
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Component(role = PluginManagerSupport.class)
|
@Component(role = PluginManagerSupport.class)
|
||||||
public class DefaultPluginManagerSupport
|
public class DefaultPluginManagerSupport
|
||||||
implements PluginManagerSupport, LogEnabled, Contextualizable
|
implements PluginManagerSupport, LogEnabled, Contextualizable
|
||||||
{
|
{
|
||||||
@Requirement
|
@Requirement
|
||||||
private ArtifactResolver artifactResolver;
|
private MavenRepositorySystem repositorySystem;
|
||||||
|
|
||||||
@Requirement
|
|
||||||
private ArtifactFactory artifactFactory;
|
|
||||||
|
|
||||||
@Requirement
|
@Requirement
|
||||||
private MavenProjectBuilder mavenProjectBuilder;
|
private MavenProjectBuilder mavenProjectBuilder;
|
||||||
|
|
||||||
|
@ -86,16 +82,6 @@ public class DefaultPluginManagerSupport
|
||||||
{
|
{
|
||||||
ArtifactRepository localRepository = session.getLocalRepository();
|
ArtifactRepository localRepository = session.getLocalRepository();
|
||||||
|
|
||||||
VersionRange versionRange;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
versionRange = VersionRange.createFromVersionSpec( plugin.getVersion() );
|
|
||||||
}
|
|
||||||
catch ( InvalidVersionSpecificationException e )
|
|
||||||
{
|
|
||||||
throw new PluginManagerException( plugin, e );
|
|
||||||
}
|
|
||||||
|
|
||||||
List remoteRepositories = new ArrayList();
|
List remoteRepositories = new ArrayList();
|
||||||
|
|
||||||
remoteRepositories.addAll( project.getRemoteArtifactRepositories() );
|
remoteRepositories.addAll( project.getRemoteArtifactRepositories() );
|
||||||
|
@ -122,25 +108,19 @@ public class DefaultPluginManagerSupport
|
||||||
|
|
||||||
checkPluginDependencySpec( plugin, pluginProject );
|
checkPluginDependencySpec( plugin, pluginProject );
|
||||||
|
|
||||||
Artifact pluginArtifact = artifactFactory.createPluginArtifact( plugin.getGroupId(),
|
Artifact pluginArtifact = repositorySystem.createPluginArtifact( plugin.getGroupId(), plugin.getArtifactId(), plugin.getVersion() );
|
||||||
plugin.getArtifactId(),
|
|
||||||
versionRange );
|
|
||||||
|
|
||||||
pluginArtifact = project.replaceWithActiveArtifact( pluginArtifact );
|
pluginArtifact = project.replaceWithActiveArtifact( pluginArtifact );
|
||||||
|
|
||||||
artifactResolver.resolve( pluginArtifact, remoteRepositories, localRepository );
|
repositorySystem.resolve( new ArtifactResolutionRequest( pluginArtifact, localRepository, remoteRepositories ) );
|
||||||
|
|
||||||
return pluginArtifact;
|
return pluginArtifact;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MavenProject buildPluginProject( Plugin plugin,
|
public MavenProject buildPluginProject( Plugin plugin, ArtifactRepository localRepository, List remoteRepositories )
|
||||||
ArtifactRepository localRepository,
|
|
||||||
List remoteRepositories )
|
|
||||||
throws InvalidPluginException
|
throws InvalidPluginException
|
||||||
{
|
{
|
||||||
Artifact artifact = artifactFactory.createProjectArtifact( plugin.getGroupId(),
|
Artifact artifact = repositorySystem.createProjectArtifact( plugin.getGroupId(), plugin.getArtifactId(), plugin.getVersion() );
|
||||||
plugin.getArtifactId(),
|
|
||||||
plugin.getVersion() );
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return mavenProjectBuilder.buildFromRepository( artifact,
|
return mavenProjectBuilder.buildFromRepository( artifact,
|
||||||
|
@ -183,19 +163,17 @@ public class DefaultPluginManagerSupport
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void checkPluginDependencySpec( Plugin plugin,
|
public void checkPluginDependencySpec( Plugin plugin, MavenProject pluginProject )
|
||||||
MavenProject pluginProject )
|
|
||||||
throws InvalidPluginException
|
throws InvalidPluginException
|
||||||
{
|
{
|
||||||
ArtifactFilter filter = new ScopeArtifactFilter( "runtime" );
|
ArtifactFilter filter = new ScopeArtifactFilter( "runtime" );
|
||||||
try
|
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()
|
throw new InvalidPluginException( "Plugin: " + plugin.getKey() + " has a dependency with an invalid version." );
|
||||||
+ " has a dependency with an invalid version.", e );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,10 +19,25 @@ package org.apache.maven.project;
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.text.SimpleDateFormat;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.util.*;
|
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.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.Artifact;
|
||||||
import org.apache.maven.artifact.ArtifactUtils;
|
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.Build;
|
||||||
import org.apache.maven.model.Model;
|
import org.apache.maven.model.Model;
|
||||||
import org.apache.maven.model.Profile;
|
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.model.io.xpp3.MavenXpp3Reader;
|
||||||
import org.apache.maven.project.ProfileManager;
|
import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
|
||||||
import org.apache.maven.project.DefaultProfileManager;
|
|
||||||
import org.apache.maven.project.ProfileActivationContext;
|
|
||||||
import org.apache.maven.project.ProfileActivationException;
|
|
||||||
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
|
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.builder.profile.ProfileContext;
|
||||||
import org.apache.maven.project.validation.ModelValidationResult;
|
import org.apache.maven.project.validation.ModelValidationResult;
|
||||||
import org.apache.maven.project.validation.ModelValidator;
|
import org.apache.maven.project.validation.ModelValidator;
|
||||||
import org.apache.maven.repository.MavenRepositorySystem;
|
import org.apache.maven.repository.MavenRepositorySystem;
|
||||||
import org.apache.maven.repository.VersionNotFoundException;
|
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.apache.maven.shared.model.impl.DefaultModelDataSource;
|
||||||
|
import org.codehaus.plexus.PlexusContainer;
|
||||||
import org.codehaus.plexus.component.annotations.Component;
|
import org.codehaus.plexus.component.annotations.Component;
|
||||||
import org.codehaus.plexus.component.annotations.Requirement;
|
import org.codehaus.plexus.component.annotations.Requirement;
|
||||||
import org.codehaus.plexus.logging.LogEnabled;
|
import org.codehaus.plexus.logging.LogEnabled;
|
||||||
import org.codehaus.plexus.logging.Logger;
|
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.StringUtils;
|
||||||
import org.codehaus.plexus.util.WriterFactory;
|
import org.codehaus.plexus.util.WriterFactory;
|
||||||
import org.codehaus.plexus.util.ReaderFactory;
|
import org.codehaus.plexus.util.xml.pull.MXSerializer;
|
||||||
import org.codehaus.plexus.util.IOUtil;
|
|
||||||
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
|
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
|
||||||
import org.codehaus.plexus.util.xml.pull.XmlSerializer;
|
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;
|
this.logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
private MavenProject buildWithProfiles( Model model, ProjectBuilderConfiguration config, File projectDescriptor,
|
private MavenProject buildWithProfiles( Model model, ProjectBuilderConfiguration config, File projectDescriptor, File parentDescriptor )
|
||||||
File parentDescriptor )
|
|
||||||
throws ProjectBuildingException
|
throws ProjectBuildingException
|
||||||
{
|
{
|
||||||
String projectId = safeVersionlessKey( model.getGroupId(), model.getArtifactId() );
|
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,
|
private List<DomainModel> getDomainModelParentsFromRepository( PomClassicDomainModel domainModel,
|
||||||
ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories,
|
ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories,
|
||||||
List<InterpolatorProperty> properties,
|
List<InterpolatorProperty> properties,
|
||||||
|
@ -807,14 +802,15 @@ public class DefaultMavenProjectBuilder
|
||||||
Artifact artifactParent = repositorySystem.createParentArtifact( domainModel.getParentGroupId(),
|
Artifact artifactParent = repositorySystem.createParentArtifact( domainModel.getParentGroupId(),
|
||||||
domainModel.getParentArtifactId(), domainModel.getParentVersion() );
|
domainModel.getParentArtifactId(), domainModel.getParentVersion() );
|
||||||
|
|
||||||
resolve( artifactParent, localRepository, remoteRepositories );
|
ArtifactResolutionResult result = repositorySystem.resolve( new ArtifactResolutionRequest( artifactParent, localRepository, remoteRepositories ) );
|
||||||
|
|
||||||
PomClassicDomainModel parentDomainModel = new PomClassicDomainModel( artifactParent.getFile() );
|
PomClassicDomainModel parentDomainModel = new PomClassicDomainModel( artifactParent.getFile() );
|
||||||
|
|
||||||
if ( !parentDomainModel.matchesParentOf( domainModel ) )
|
if ( !parentDomainModel.matchesParentOf( domainModel ) )
|
||||||
{
|
{
|
||||||
logger.debug( "Parent pom ids do not match: Parent File = " + artifactParent.getFile().getAbsolutePath() +
|
//shane: what does this mean exactly and why does it occur
|
||||||
": Child ID = " + domainModel.getId() );
|
logger.debug( "Parent pom ids do not match: Parent File = " + artifactParent.getFile().getAbsolutePath() + ": Child ID = " + domainModel.getId() );
|
||||||
|
|
||||||
return domainModels;
|
return domainModels;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -96,6 +96,18 @@ public class LegacyMavenRepositorySystem
|
||||||
@Requirement
|
@Requirement
|
||||||
private Logger logger;
|
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>();
|
private static HashMap<String, Artifact> cache = new HashMap<String, Artifact>();
|
||||||
|
|
||||||
// Artifact Creation
|
// Artifact Creation
|
||||||
|
@ -454,7 +466,7 @@ public class LegacyMavenRepositorySystem
|
||||||
projectArtifact = artifactFactory.createProjectArtifact( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getScope() );
|
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();
|
File file = projectArtifact.getFile();
|
||||||
artifact.setFile( file );
|
artifact.setFile( file );
|
||||||
|
@ -518,35 +530,11 @@ public class LegacyMavenRepositorySystem
|
||||||
return ArtifactUtils.versionlessKey( gid, aid );
|
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 )
|
public ArtifactResolutionResult resolve( ArtifactResolutionRequest request )
|
||||||
{
|
{
|
||||||
return artifactResolver.resolve( 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 )
|
public void setOnline( boolean online )
|
||||||
{
|
{
|
||||||
this.online = online;
|
this.online = online;
|
||||||
|
|
|
@ -89,15 +89,11 @@ public interface MavenRepositorySystem
|
||||||
|
|
||||||
ArtifactResolutionResult resolve( ArtifactResolutionRequest request );
|
ArtifactResolutionResult resolve( ArtifactResolutionRequest request );
|
||||||
|
|
||||||
// This can be reduced to the request/result
|
// Metadata
|
||||||
void resolve( Artifact artifact, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories )
|
|
||||||
throws ArtifactResolutionException, ArtifactNotFoundException;
|
|
||||||
|
|
||||||
void findModelFromRepository( Artifact artifact, List remoteArtifactRepositories, ArtifactRepository localRepository )
|
void findModelFromRepository( Artifact artifact, List remoteArtifactRepositories, ArtifactRepository localRepository )
|
||||||
throws InvalidRepositoryException, ArtifactResolutionException, ArtifactNotFoundException;
|
throws InvalidRepositoryException, ArtifactResolutionException, ArtifactNotFoundException;
|
||||||
|
|
||||||
// Version retrieval or metadata operations
|
|
||||||
|
|
||||||
ResolutionGroup retrieve( Artifact artifact, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories )
|
ResolutionGroup retrieve( Artifact artifact, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories )
|
||||||
throws ArtifactMetadataRetrievalException;
|
throws ArtifactMetadataRetrievalException;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue