o Enabled request tracing for repository events to provide more context for event spies

git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@1074195 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2011-02-24 16:06:26 +00:00
parent b6ee02c3df
commit 3c37fb7071
12 changed files with 227 additions and 82 deletions

View File

@ -49,6 +49,7 @@ import org.sonatype.aether.RepositoryEvent.EventType;
import org.sonatype.aether.RepositoryException; import org.sonatype.aether.RepositoryException;
import org.sonatype.aether.RepositoryListener; import org.sonatype.aether.RepositoryListener;
import org.sonatype.aether.RepositorySystemSession; import org.sonatype.aether.RepositorySystemSession;
import org.sonatype.aether.RequestTrace;
import org.sonatype.aether.artifact.Artifact; import org.sonatype.aether.artifact.Artifact;
import org.sonatype.aether.artifact.ArtifactType; import org.sonatype.aether.artifact.ArtifactType;
import org.sonatype.aether.artifact.ArtifactTypeRegistry; import org.sonatype.aether.artifact.ArtifactTypeRegistry;
@ -59,6 +60,7 @@ import org.sonatype.aether.impl.ArtifactResolver;
import org.sonatype.aether.impl.RemoteRepositoryManager; import org.sonatype.aether.impl.RemoteRepositoryManager;
import org.sonatype.aether.impl.VersionResolver; import org.sonatype.aether.impl.VersionResolver;
import org.sonatype.aether.transfer.ArtifactNotFoundException; import org.sonatype.aether.transfer.ArtifactNotFoundException;
import org.sonatype.aether.util.DefaultRequestTrace;
import org.sonatype.aether.util.artifact.ArtifactProperties; import org.sonatype.aether.util.artifact.ArtifactProperties;
import org.sonatype.aether.util.artifact.DefaultArtifact; import org.sonatype.aether.util.artifact.DefaultArtifact;
import org.sonatype.aether.util.artifact.DefaultArtifactType; import org.sonatype.aether.util.artifact.DefaultArtifactType;
@ -224,6 +226,8 @@ public class DefaultArtifactDescriptorReader
ArtifactDescriptorResult result ) ArtifactDescriptorResult result )
throws ArtifactDescriptorException throws ArtifactDescriptorException
{ {
RequestTrace trace = DefaultRequestTrace.newChild( request.getTrace(), request );
Set<String> visited = new LinkedHashSet<String>(); Set<String> visited = new LinkedHashSet<String>();
for ( Artifact artifact = request.getArtifact();; ) for ( Artifact artifact = request.getArtifact();; )
{ {
@ -231,6 +235,7 @@ public class DefaultArtifactDescriptorReader
{ {
VersionRequest versionRequest = VersionRequest versionRequest =
new VersionRequest( artifact, request.getRepositories(), request.getRequestContext() ); new VersionRequest( artifact, request.getRepositories(), request.getRequestContext() );
versionRequest.setTrace( trace );
VersionResult versionResult = versionResolver.resolveVersion( session, versionRequest ); VersionResult versionResult = versionResolver.resolveVersion( session, versionRequest );
artifact = artifact.setVersion( versionResult.getVersion() ); artifact = artifact.setVersion( versionResult.getVersion() );
@ -245,7 +250,7 @@ public class DefaultArtifactDescriptorReader
{ {
RepositoryException exception = RepositoryException exception =
new RepositoryException( "Artifact relocations form a cycle: " + visited ); new RepositoryException( "Artifact relocations form a cycle: " + visited );
invalidDescriptor( session, artifact, exception ); invalidDescriptor( session, trace, artifact, exception );
if ( session.isIgnoreInvalidArtifactDescriptor() ) if ( session.isIgnoreInvalidArtifactDescriptor() )
{ {
return null; return null;
@ -265,6 +270,7 @@ public class DefaultArtifactDescriptorReader
{ {
ArtifactRequest resolveRequest = ArtifactRequest resolveRequest =
new ArtifactRequest( pomArtifact, request.getRepositories(), request.getRequestContext() ); new ArtifactRequest( pomArtifact, request.getRepositories(), request.getRequestContext() );
resolveRequest.setTrace( trace );
resolveResult = artifactResolver.resolveArtifact( session, resolveRequest ); resolveResult = artifactResolver.resolveArtifact( session, resolveRequest );
pomArtifact = resolveResult.getArtifact(); pomArtifact = resolveResult.getArtifact();
result.setRepository( resolveResult.getRepository() ); result.setRepository( resolveResult.getRepository() );
@ -273,7 +279,7 @@ public class DefaultArtifactDescriptorReader
{ {
if ( e.getCause() instanceof ArtifactNotFoundException ) if ( e.getCause() instanceof ArtifactNotFoundException )
{ {
missingDescriptor( session, artifact, (Exception) e.getCause() ); missingDescriptor( session, trace, artifact, (Exception) e.getCause() );
if ( session.isIgnoreMissingArtifactDescriptor() ) if ( session.isIgnoreMissingArtifactDescriptor() )
{ {
return null; return null;
@ -293,8 +299,9 @@ public class DefaultArtifactDescriptorReader
modelRequest.setSystemProperties( toProperties( session.getUserProperties(), modelRequest.setSystemProperties( toProperties( session.getUserProperties(),
session.getSystemProperties() ) ); session.getSystemProperties() ) );
modelRequest.setModelCache( DefaultModelCache.newInstance( session ) ); modelRequest.setModelCache( DefaultModelCache.newInstance( session ) );
modelRequest.setModelResolver( new DefaultModelResolver( session, request.getRequestContext(), modelRequest.setModelResolver( new DefaultModelResolver( session, trace.newChild( modelRequest ),
artifactResolver, remoteRepositoryManager, request.getRequestContext(), artifactResolver,
remoteRepositoryManager,
request.getRepositories() ) ); request.getRepositories() ) );
if ( resolveResult.getRepository() instanceof WorkspaceRepository ) if ( resolveResult.getRepository() instanceof WorkspaceRepository )
{ {
@ -317,7 +324,7 @@ public class DefaultArtifactDescriptorReader
throw new ArtifactDescriptorException( result ); throw new ArtifactDescriptorException( result );
} }
} }
invalidDescriptor( session, artifact, e ); invalidDescriptor( session, trace, artifact, e );
if ( session.isIgnoreInvalidArtifactDescriptor() ) if ( session.isIgnoreInvalidArtifactDescriptor() )
{ {
return null; return null;
@ -435,24 +442,28 @@ public class DefaultArtifactDescriptorReader
return new RepositoryPolicy( enabled, updates, checksums ); return new RepositoryPolicy( enabled, updates, checksums );
} }
private void missingDescriptor( RepositorySystemSession session, Artifact artifact, Exception exception ) private void missingDescriptor( RepositorySystemSession session, RequestTrace trace, Artifact artifact,
Exception exception )
{ {
RepositoryListener listener = session.getRepositoryListener(); RepositoryListener listener = session.getRepositoryListener();
if ( listener != null ) if ( listener != null )
{ {
DefaultRepositoryEvent event = new DefaultRepositoryEvent( EventType.ARTIFACT_DESCRIPTOR_MISSING, session ); DefaultRepositoryEvent event =
new DefaultRepositoryEvent( EventType.ARTIFACT_DESCRIPTOR_MISSING, session, trace );
event.setArtifact( artifact ); event.setArtifact( artifact );
event.setException( exception ); event.setException( exception );
listener.artifactDescriptorMissing( event ); listener.artifactDescriptorMissing( event );
} }
} }
private void invalidDescriptor( RepositorySystemSession session, Artifact artifact, Exception exception ) private void invalidDescriptor( RepositorySystemSession session, RequestTrace trace, Artifact artifact,
Exception exception )
{ {
RepositoryListener listener = session.getRepositoryListener(); RepositoryListener listener = session.getRepositoryListener();
if ( listener != null ) if ( listener != null )
{ {
DefaultRepositoryEvent event = new DefaultRepositoryEvent( EventType.ARTIFACT_DESCRIPTOR_INVALID, session ); DefaultRepositoryEvent event =
new DefaultRepositoryEvent( EventType.ARTIFACT_DESCRIPTOR_INVALID, session, trace );
event.setArtifact( artifact ); event.setArtifact( artifact );
event.setException( exception ); event.setException( exception );
listener.artifactDescriptorInvalid( event ); listener.artifactDescriptorInvalid( event );

View File

@ -32,6 +32,7 @@ import org.apache.maven.model.resolution.InvalidRepositoryException;
import org.apache.maven.model.resolution.ModelResolver; import org.apache.maven.model.resolution.ModelResolver;
import org.apache.maven.model.resolution.UnresolvableModelException; import org.apache.maven.model.resolution.UnresolvableModelException;
import org.sonatype.aether.RepositorySystemSession; import org.sonatype.aether.RepositorySystemSession;
import org.sonatype.aether.RequestTrace;
import org.sonatype.aether.artifact.Artifact; import org.sonatype.aether.artifact.Artifact;
import org.sonatype.aether.impl.ArtifactResolver; import org.sonatype.aether.impl.ArtifactResolver;
import org.sonatype.aether.impl.RemoteRepositoryManager; import org.sonatype.aether.impl.RemoteRepositoryManager;
@ -53,6 +54,8 @@ class DefaultModelResolver
private final RepositorySystemSession session; private final RepositorySystemSession session;
private final RequestTrace trace;
private final String context; private final String context;
private List<RemoteRepository> repositories; private List<RemoteRepository> repositories;
@ -63,10 +66,12 @@ class DefaultModelResolver
private final Set<String> repositoryIds; private final Set<String> repositoryIds;
public DefaultModelResolver( RepositorySystemSession session, String context, ArtifactResolver resolver, public DefaultModelResolver( RepositorySystemSession session, RequestTrace trace, String context,
RemoteRepositoryManager remoteRepositoryManager, List<RemoteRepository> repositories ) ArtifactResolver resolver, RemoteRepositoryManager remoteRepositoryManager,
List<RemoteRepository> repositories )
{ {
this.session = session; this.session = session;
this.trace = trace;
this.context = context; this.context = context;
this.resolver = resolver; this.resolver = resolver;
this.remoteRepositoryManager = remoteRepositoryManager; this.remoteRepositoryManager = remoteRepositoryManager;
@ -77,6 +82,7 @@ class DefaultModelResolver
private DefaultModelResolver( DefaultModelResolver original ) private DefaultModelResolver( DefaultModelResolver original )
{ {
this.session = original.session; this.session = original.session;
this.trace = original.trace;
this.context = original.context; this.context = original.context;
this.resolver = original.resolver; this.resolver = original.resolver;
this.remoteRepositoryManager = original.remoteRepositoryManager; this.remoteRepositoryManager = original.remoteRepositoryManager;
@ -112,6 +118,7 @@ class DefaultModelResolver
try try
{ {
ArtifactRequest request = new ArtifactRequest( pomArtifact, repositories, context ); ArtifactRequest request = new ArtifactRequest( pomArtifact, repositories, context );
request.setTrace( trace );
pomArtifact = resolver.resolveArtifact( session, request ).getArtifact(); pomArtifact = resolver.resolveArtifact( session, request ).getArtifact();
} }
catch ( ArtifactResolutionException e ) catch ( ArtifactResolutionException e )

View File

@ -34,6 +34,9 @@ import org.codehaus.plexus.util.IOUtil;
import org.sonatype.aether.RepositoryEvent.EventType; import org.sonatype.aether.RepositoryEvent.EventType;
import org.sonatype.aether.RepositoryListener; import org.sonatype.aether.RepositoryListener;
import org.sonatype.aether.RepositorySystemSession; import org.sonatype.aether.RepositorySystemSession;
import org.sonatype.aether.RequestTrace;
import org.sonatype.aether.SyncContext;
import org.sonatype.aether.util.DefaultRequestTrace;
import org.sonatype.aether.util.listener.DefaultRepositoryEvent; import org.sonatype.aether.util.listener.DefaultRepositoryEvent;
import org.sonatype.aether.util.metadata.DefaultMetadata; import org.sonatype.aether.util.metadata.DefaultMetadata;
import org.sonatype.aether.util.version.GenericVersionScheme; import org.sonatype.aether.util.version.GenericVersionScheme;
@ -42,6 +45,7 @@ import org.sonatype.aether.version.Version;
import org.sonatype.aether.version.VersionConstraint; import org.sonatype.aether.version.VersionConstraint;
import org.sonatype.aether.version.VersionScheme; import org.sonatype.aether.version.VersionScheme;
import org.sonatype.aether.impl.MetadataResolver; import org.sonatype.aether.impl.MetadataResolver;
import org.sonatype.aether.impl.SyncContextFactory;
import org.sonatype.aether.impl.VersionRangeResolver; import org.sonatype.aether.impl.VersionRangeResolver;
import org.sonatype.aether.metadata.Metadata; import org.sonatype.aether.metadata.Metadata;
import org.sonatype.aether.repository.ArtifactRepository; import org.sonatype.aether.repository.ArtifactRepository;
@ -67,16 +71,21 @@ public class DefaultVersionRangeResolver
private static final String MAVEN_METADATA_XML = "maven-metadata.xml"; private static final String MAVEN_METADATA_XML = "maven-metadata.xml";
@SuppressWarnings( "unused" )
@Requirement @Requirement
private Logger logger = NullLogger.INSTANCE; private Logger logger = NullLogger.INSTANCE;
@Requirement @Requirement
private MetadataResolver metadataResolver; private MetadataResolver metadataResolver;
@Requirement
private SyncContextFactory syncContextFactory;
public void initService( ServiceLocator locator ) public void initService( ServiceLocator locator )
{ {
setLogger( locator.getService( Logger.class ) ); setLogger( locator.getService( Logger.class ) );
setMetadataResolver( locator.getService( MetadataResolver.class ) ); setMetadataResolver( locator.getService( MetadataResolver.class ) );
setSyncContextFactory( locator.getService( SyncContextFactory.class ) );
} }
public DefaultVersionRangeResolver setLogger( Logger logger ) public DefaultVersionRangeResolver setLogger( Logger logger )
@ -95,6 +104,16 @@ public class DefaultVersionRangeResolver
return this; return this;
} }
public DefaultVersionRangeResolver setSyncContextFactory( SyncContextFactory syncContextFactory )
{
if ( syncContextFactory == null )
{
throw new IllegalArgumentException( "sync context factory has not been specified" );
}
this.syncContextFactory = syncContextFactory;
return this;
}
public VersionRangeResult resolveVersionRange( RepositorySystemSession session, VersionRangeRequest request ) public VersionRangeResult resolveVersionRange( RepositorySystemSession session, VersionRangeRequest request )
throws VersionRangeResolutionException throws VersionRangeResolutionException
{ {
@ -151,6 +170,8 @@ public class DefaultVersionRangeResolver
private Map<String, ArtifactRepository> getVersions( RepositorySystemSession session, VersionRangeResult result, private Map<String, ArtifactRepository> getVersions( RepositorySystemSession session, VersionRangeResult result,
VersionRangeRequest request ) VersionRangeRequest request )
{ {
RequestTrace trace = DefaultRequestTrace.newChild( request.getTrace(), request );
Map<String, ArtifactRepository> versionIndex = new HashMap<String, ArtifactRepository>(); Map<String, ArtifactRepository> versionIndex = new HashMap<String, ArtifactRepository>();
Metadata metadata = Metadata metadata =
@ -165,6 +186,7 @@ public class DefaultVersionRangeResolver
{ {
MetadataRequest metadataRequest = new MetadataRequest( metadata, repository, request.getRequestContext() ); MetadataRequest metadataRequest = new MetadataRequest( metadata, repository, request.getRequestContext() );
metadataRequest.setDeleteLocalCopyIfMissing( true ); metadataRequest.setDeleteLocalCopyIfMissing( true );
metadataRequest.setTrace( trace );
metadataRequests.add( metadataRequest ); metadataRequests.add( metadataRequest );
} }
@ -190,7 +212,7 @@ public class DefaultVersionRangeResolver
repository = session.getLocalRepository(); repository = session.getLocalRepository();
} }
Versioning versioning = readVersions( session, metadataResult.getMetadata(), repository, result ); Versioning versioning = readVersions( session, trace, metadataResult.getMetadata(), repository, result );
for ( String version : versioning.getVersions() ) for ( String version : versioning.getVersions() )
{ {
if ( !versionIndex.containsKey( version ) ) if ( !versionIndex.containsKey( version ) )
@ -203,24 +225,39 @@ public class DefaultVersionRangeResolver
return versionIndex; return versionIndex;
} }
private Versioning readVersions( RepositorySystemSession session, Metadata metadata, ArtifactRepository repository, private Versioning readVersions( RepositorySystemSession session, RequestTrace trace, Metadata metadata,
VersionRangeResult result ) ArtifactRepository repository, VersionRangeResult result )
{ {
Versioning versioning = null; Versioning versioning = null;
FileInputStream fis = null; FileInputStream fis = null;
try try
{ {
if ( metadata != null && metadata.getFile() != null && metadata.getFile().exists() ) if ( metadata != null )
{
SyncContext syncContext = syncContextFactory.newInstance( session, true );
try
{
syncContext.acquire( null, Collections.singleton( metadata ) );
if ( metadata.getFile() != null && metadata.getFile().exists() )
{ {
fis = new FileInputStream( metadata.getFile() ); fis = new FileInputStream( metadata.getFile() );
org.apache.maven.artifact.repository.metadata.Metadata m = new MetadataXpp3Reader().read( fis, false ); org.apache.maven.artifact.repository.metadata.Metadata m =
new MetadataXpp3Reader().read( fis, false );
versioning = m.getVersioning(); versioning = m.getVersioning();
} }
} }
finally
{
syncContext.release();
}
}
}
catch ( Exception e ) catch ( Exception e )
{ {
invalidMetadata( session, metadata, repository, e ); invalidMetadata( session, trace, metadata, repository, e );
result.addException( e ); result.addException( e );
} }
finally finally
@ -231,13 +268,13 @@ public class DefaultVersionRangeResolver
return ( versioning != null ) ? versioning : new Versioning(); return ( versioning != null ) ? versioning : new Versioning();
} }
private void invalidMetadata( RepositorySystemSession session, Metadata metadata, ArtifactRepository repository, private void invalidMetadata( RepositorySystemSession session, RequestTrace trace, Metadata metadata,
Exception exception ) ArtifactRepository repository, Exception exception )
{ {
RepositoryListener listener = session.getRepositoryListener(); RepositoryListener listener = session.getRepositoryListener();
if ( listener != null ) if ( listener != null )
{ {
DefaultRepositoryEvent event = new DefaultRepositoryEvent( EventType.METADATA_INVALID, session ); DefaultRepositoryEvent event = new DefaultRepositoryEvent( EventType.METADATA_INVALID, session, trace );
event.setMetadata( metadata ); event.setMetadata( metadata );
event.setException( exception ); event.setException( exception );
event.setRepository( repository ); event.setRepository( repository );

View File

@ -38,14 +38,18 @@ import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.StringUtils;
import org.sonatype.aether.ConfigurationProperties; import org.sonatype.aether.ConfigurationProperties;
import org.sonatype.aether.RepositoryCache; import org.sonatype.aether.RepositoryCache;
import org.sonatype.aether.RequestTrace;
import org.sonatype.aether.RepositoryEvent.EventType; import org.sonatype.aether.RepositoryEvent.EventType;
import org.sonatype.aether.RepositoryListener; import org.sonatype.aether.RepositoryListener;
import org.sonatype.aether.RepositorySystemSession; import org.sonatype.aether.RepositorySystemSession;
import org.sonatype.aether.SyncContext;
import org.sonatype.aether.util.DefaultRequestTrace;
import org.sonatype.aether.util.artifact.SubArtifact; import org.sonatype.aether.util.artifact.SubArtifact;
import org.sonatype.aether.util.listener.DefaultRepositoryEvent; import org.sonatype.aether.util.listener.DefaultRepositoryEvent;
import org.sonatype.aether.util.metadata.DefaultMetadata; import org.sonatype.aether.util.metadata.DefaultMetadata;
import org.sonatype.aether.artifact.Artifact; import org.sonatype.aether.artifact.Artifact;
import org.sonatype.aether.impl.MetadataResolver; import org.sonatype.aether.impl.MetadataResolver;
import org.sonatype.aether.impl.SyncContextFactory;
import org.sonatype.aether.impl.VersionResolver; import org.sonatype.aether.impl.VersionResolver;
import org.sonatype.aether.impl.internal.CacheUtils; import org.sonatype.aether.impl.internal.CacheUtils;
import org.sonatype.aether.metadata.Metadata; import org.sonatype.aether.metadata.Metadata;
@ -80,16 +84,21 @@ public class DefaultVersionResolver
private static final String SNAPSHOT = "SNAPSHOT"; private static final String SNAPSHOT = "SNAPSHOT";
@SuppressWarnings( "unused" )
@Requirement @Requirement
private Logger logger = NullLogger.INSTANCE; private Logger logger = NullLogger.INSTANCE;
@Requirement @Requirement
private MetadataResolver metadataResolver; private MetadataResolver metadataResolver;
@Requirement
private SyncContextFactory syncContextFactory;
public void initService( ServiceLocator locator ) public void initService( ServiceLocator locator )
{ {
setLogger( locator.getService( Logger.class ) ); setLogger( locator.getService( Logger.class ) );
setMetadataResolver( locator.getService( MetadataResolver.class ) ); setMetadataResolver( locator.getService( MetadataResolver.class ) );
setSyncContextFactory( locator.getService( SyncContextFactory.class ) );
} }
public DefaultVersionResolver setLogger( Logger logger ) public DefaultVersionResolver setLogger( Logger logger )
@ -108,9 +117,21 @@ public class DefaultVersionResolver
return this; return this;
} }
public DefaultVersionResolver setSyncContextFactory( SyncContextFactory syncContextFactory )
{
if ( syncContextFactory == null )
{
throw new IllegalArgumentException( "sync context factory has not been specified" );
}
this.syncContextFactory = syncContextFactory;
return this;
}
public VersionResult resolveVersion( RepositorySystemSession session, VersionRequest request ) public VersionResult resolveVersion( RepositorySystemSession session, VersionRequest request )
throws VersionResolutionException throws VersionResolutionException
{ {
RequestTrace trace = DefaultRequestTrace.newChild( request.getTrace(), request );
Artifact artifact = request.getArtifact(); Artifact artifact = request.getArtifact();
String version = artifact.getVersion(); String version = artifact.getVersion();
@ -184,6 +205,7 @@ public class DefaultVersionResolver
new MetadataRequest( metadata, repository, request.getRequestContext() ); new MetadataRequest( metadata, repository, request.getRequestContext() );
metadataRequest.setDeleteLocalCopyIfMissing( true ); metadataRequest.setDeleteLocalCopyIfMissing( true );
metadataRequest.setFavorLocalRepository( true ); metadataRequest.setFavorLocalRepository( true );
metadataRequest.setTrace( trace );
metadataRequests.add( metadataRequest ); metadataRequests.add( metadataRequest );
} }
@ -201,7 +223,7 @@ public class DefaultVersionResolver
repository = session.getLocalRepository(); repository = session.getLocalRepository();
} }
Versioning versioning = readVersions( session, metadataResult.getMetadata(), repository, result ); Versioning versioning = readVersions( session, trace, metadataResult.getMetadata(), repository, result );
merge( artifact, infos, versioning, repository ); merge( artifact, infos, versioning, repository );
} }
@ -272,24 +294,33 @@ public class DefaultVersionResolver
return info != null; return info != null;
} }
private Versioning readVersions( RepositorySystemSession session, Metadata metadata, ArtifactRepository repository, private Versioning readVersions( RepositorySystemSession session, RequestTrace trace, Metadata metadata,
VersionResult result ) ArtifactRepository repository, VersionResult result )
{ {
Versioning versioning = null; Versioning versioning = null;
FileInputStream fis = null; FileInputStream fis = null;
try try
{ {
if ( metadata != null && metadata.getFile() != null && metadata.getFile().exists() ) if ( metadata != null )
{
SyncContext syncContext = syncContextFactory.newInstance( session, true );
try
{
syncContext.acquire( null, Collections.singleton( metadata ) );
if ( metadata.getFile() != null && metadata.getFile().exists() )
{ {
fis = new FileInputStream( metadata.getFile() ); fis = new FileInputStream( metadata.getFile() );
org.apache.maven.artifact.repository.metadata.Metadata m = new MetadataXpp3Reader().read( fis, false ); org.apache.maven.artifact.repository.metadata.Metadata m =
new MetadataXpp3Reader().read( fis, false );
versioning = m.getVersioning(); versioning = m.getVersioning();
/* /*
* NOTE: Users occasionally misuse the id "local" for remote repos which screws up the metadata of the * NOTE: Users occasionally misuse the id "local" for remote repos which screws up the metadata
* local repository. This is especially troublesome during snapshot resolution so we try to handle that * of the local repository. This is especially troublesome during snapshot resolution so we try
* gracefully. * to handle that gracefully.
*/ */
if ( versioning != null && repository instanceof LocalRepository ) if ( versioning != null && repository instanceof LocalRepository )
{ {
@ -303,14 +334,21 @@ public class DefaultVersionResolver
versioning = repaired; versioning = repaired;
throw new IOException( "Snapshot information corrupted with remote repository data" throw new IOException( "Snapshot information corrupted with remote repository data"
+ ", please verify that no remote repository uses the id '" + repository.getId() + "'" ); + ", please verify that no remote repository uses the id '" + repository.getId()
+ "'" );
} }
} }
} }
} }
finally
{
syncContext.release();
}
}
}
catch ( Exception e ) catch ( Exception e )
{ {
invalidMetadata( session, metadata, repository, e ); invalidMetadata( session, trace, metadata, repository, e );
result.addException( e ); result.addException( e );
} }
finally finally
@ -321,13 +359,13 @@ public class DefaultVersionResolver
return ( versioning != null ) ? versioning : new Versioning(); return ( versioning != null ) ? versioning : new Versioning();
} }
private void invalidMetadata( RepositorySystemSession session, Metadata metadata, ArtifactRepository repository, private void invalidMetadata( RepositorySystemSession session, RequestTrace trace, Metadata metadata,
Exception exception ) ArtifactRepository repository, Exception exception )
{ {
RepositoryListener listener = session.getRepositoryListener(); RepositoryListener listener = session.getRepositoryListener();
if ( listener != null ) if ( listener != null )
{ {
DefaultRepositoryEvent event = new DefaultRepositoryEvent( EventType.METADATA_INVALID, session ); DefaultRepositoryEvent event = new DefaultRepositoryEvent( EventType.METADATA_INVALID, session, trace );
event.setMetadata( metadata ); event.setMetadata( metadata );
event.setException( exception ); event.setException( exception );
event.setRepository( repository ); event.setRepository( repository );

View File

@ -44,6 +44,7 @@ import org.sonatype.aether.deployment.DeployResult;
import org.sonatype.aether.deployment.DeploymentException; import org.sonatype.aether.deployment.DeploymentException;
import org.sonatype.aether.metadata.MergeableMetadata; import org.sonatype.aether.metadata.MergeableMetadata;
import org.sonatype.aether.repository.RemoteRepository; import org.sonatype.aether.repository.RemoteRepository;
import org.sonatype.aether.util.DefaultRequestTrace;
import org.sonatype.aether.util.artifact.SubArtifact; import org.sonatype.aether.util.artifact.SubArtifact;
@Component( role = ArtifactDeployer.class, instantiationStrategy = "per-lookup" ) @Component( role = ArtifactDeployer.class, instantiationStrategy = "per-lookup" )
@ -83,6 +84,8 @@ public class DefaultArtifactDeployer
DeployRequest request = new DeployRequest(); DeployRequest request = new DeployRequest();
request.setTrace( DefaultRequestTrace.newChild( null, legacySupport.getSession().getCurrentProject() ) );
org.sonatype.aether.artifact.Artifact mainArtifact = RepositoryUtils.toArtifact( artifact ); org.sonatype.aether.artifact.Artifact mainArtifact = RepositoryUtils.toArtifact( artifact );
mainArtifact = mainArtifact.setFile( source ); mainArtifact = mainArtifact.setFile( source );
request.addArtifact( mainArtifact ); request.addArtifact( mainArtifact );

View File

@ -40,6 +40,7 @@ import org.sonatype.aether.RepositorySystem;
import org.sonatype.aether.RepositorySystemSession; import org.sonatype.aether.RepositorySystemSession;
import org.sonatype.aether.installation.InstallRequest; import org.sonatype.aether.installation.InstallRequest;
import org.sonatype.aether.installation.InstallationException; import org.sonatype.aether.installation.InstallationException;
import org.sonatype.aether.util.DefaultRequestTrace;
import org.sonatype.aether.util.artifact.SubArtifact; import org.sonatype.aether.util.artifact.SubArtifact;
/** /**
@ -76,6 +77,8 @@ public class DefaultArtifactInstaller
InstallRequest request = new InstallRequest(); InstallRequest request = new InstallRequest();
request.setTrace( DefaultRequestTrace.newChild( null, legacySupport.getSession().getCurrentProject() ) );
org.sonatype.aether.artifact.Artifact mainArtifact = RepositoryUtils.toArtifact( artifact ); org.sonatype.aether.artifact.Artifact mainArtifact = RepositoryUtils.toArtifact( artifact );
mainArtifact = mainArtifact.setFile( source ); mainArtifact = mainArtifact.setFile( source );
request.addArtifact( mainArtifact ); request.addArtifact( mainArtifact );

View File

@ -33,6 +33,7 @@ import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.logging.Logger; import org.codehaus.plexus.logging.Logger;
import org.sonatype.aether.RepositorySystem; import org.sonatype.aether.RepositorySystem;
import org.sonatype.aether.RepositorySystemSession; import org.sonatype.aether.RepositorySystemSession;
import org.sonatype.aether.RequestTrace;
import org.sonatype.aether.artifact.Artifact; import org.sonatype.aether.artifact.Artifact;
import org.sonatype.aether.collection.CollectRequest; import org.sonatype.aether.collection.CollectRequest;
import org.sonatype.aether.collection.DependencyCollectionException; import org.sonatype.aether.collection.DependencyCollectionException;
@ -47,7 +48,10 @@ import org.sonatype.aether.resolution.ArtifactDescriptorRequest;
import org.sonatype.aether.resolution.ArtifactDescriptorResult; import org.sonatype.aether.resolution.ArtifactDescriptorResult;
import org.sonatype.aether.resolution.ArtifactRequest; import org.sonatype.aether.resolution.ArtifactRequest;
import org.sonatype.aether.resolution.ArtifactResolutionException; import org.sonatype.aether.resolution.ArtifactResolutionException;
import org.sonatype.aether.resolution.DependencyRequest;
import org.sonatype.aether.resolution.DependencyResolutionException;
import org.sonatype.aether.util.DefaultRepositorySystemSession; import org.sonatype.aether.util.DefaultRepositorySystemSession;
import org.sonatype.aether.util.DefaultRequestTrace;
import org.sonatype.aether.util.FilterRepositorySystemSession; import org.sonatype.aether.util.FilterRepositorySystemSession;
import org.sonatype.aether.util.artifact.DefaultArtifact; import org.sonatype.aether.util.artifact.DefaultArtifact;
import org.sonatype.aether.util.artifact.JavaScopes; import org.sonatype.aether.util.artifact.JavaScopes;
@ -90,6 +94,8 @@ public class DefaultPluginDependenciesResolver
public Artifact resolve( Plugin plugin, List<RemoteRepository> repositories, RepositorySystemSession session ) public Artifact resolve( Plugin plugin, List<RemoteRepository> repositories, RepositorySystemSession session )
throws PluginResolutionException throws PluginResolutionException
{ {
RequestTrace trace = DefaultRequestTrace.newChild( null, plugin );
Artifact pluginArtifact = toArtifact( plugin, session ); Artifact pluginArtifact = toArtifact( plugin, session );
try try
@ -105,6 +111,7 @@ public class DefaultPluginDependenciesResolver
ArtifactDescriptorRequest request = ArtifactDescriptorRequest request =
new ArtifactDescriptorRequest( pluginArtifact, repositories, REPOSITORY_CONTEXT ); new ArtifactDescriptorRequest( pluginArtifact, repositories, REPOSITORY_CONTEXT );
request.setTrace( trace );
ArtifactDescriptorResult result = repoSystem.readArtifactDescriptor( pluginSession, request ); ArtifactDescriptorResult result = repoSystem.readArtifactDescriptor( pluginSession, request );
pluginArtifact = result.getArtifact(); pluginArtifact = result.getArtifact();
@ -125,6 +132,7 @@ public class DefaultPluginDependenciesResolver
try try
{ {
ArtifactRequest request = new ArtifactRequest( pluginArtifact, repositories, REPOSITORY_CONTEXT ); ArtifactRequest request = new ArtifactRequest( pluginArtifact, repositories, REPOSITORY_CONTEXT );
request.setTrace( trace );
pluginArtifact = repoSystem.resolveArtifact( session, request ).getArtifact(); pluginArtifact = repoSystem.resolveArtifact( session, request ).getArtifact();
} }
catch ( ArtifactResolutionException e ) catch ( ArtifactResolutionException e )
@ -139,6 +147,8 @@ public class DefaultPluginDependenciesResolver
List<RemoteRepository> repositories, RepositorySystemSession session ) List<RemoteRepository> repositories, RepositorySystemSession session )
throws PluginResolutionException throws PluginResolutionException
{ {
RequestTrace trace = DefaultRequestTrace.newChild( null, plugin );
if ( pluginArtifact == null ) if ( pluginArtifact == null )
{ {
pluginArtifact = toArtifact( plugin, session ); pluginArtifact = toArtifact( plugin, session );
@ -181,6 +191,11 @@ public class DefaultPluginDependenciesResolver
request.addDependency( pluginDep ); request.addDependency( pluginDep );
} }
DependencyRequest depRequest = new DependencyRequest( request, resolutionFilter );
depRequest.setTrace( trace );
request.setTrace( DefaultRequestTrace.newChild( trace, depRequest ) );
node = repoSystem.collectDependencies( pluginSession, request ).getRoot(); node = repoSystem.collectDependencies( pluginSession, request ).getRoot();
if ( logger.isDebugEnabled() ) if ( logger.isDebugEnabled() )
@ -188,15 +203,16 @@ public class DefaultPluginDependenciesResolver
node.accept( new GraphLogger() ); node.accept( new GraphLogger() );
} }
repoSystem.resolveDependencies( session, node, resolutionFilter ); depRequest.setRoot( node );
repoSystem.resolveDependencies( session, depRequest );
} }
catch ( DependencyCollectionException e ) catch ( DependencyCollectionException e )
{ {
throw new PluginResolutionException( plugin, e ); throw new PluginResolutionException( plugin, e );
} }
catch ( ArtifactResolutionException e ) catch ( DependencyResolutionException e )
{ {
throw new PluginResolutionException( plugin, e ); throw new PluginResolutionException( plugin, e.getCause() );
} }
return node; return node;

View File

@ -42,12 +42,14 @@ import org.sonatype.aether.RepositoryEvent.EventType;
import org.sonatype.aether.RepositoryListener; import org.sonatype.aether.RepositoryListener;
import org.sonatype.aether.RepositorySystem; import org.sonatype.aether.RepositorySystem;
import org.sonatype.aether.RepositorySystemSession; import org.sonatype.aether.RepositorySystemSession;
import org.sonatype.aether.RequestTrace;
import org.sonatype.aether.repository.ArtifactRepository; import org.sonatype.aether.repository.ArtifactRepository;
import org.sonatype.aether.repository.RemoteRepository; import org.sonatype.aether.repository.RemoteRepository;
import org.sonatype.aether.repository.RepositoryPolicy; import org.sonatype.aether.repository.RepositoryPolicy;
import org.sonatype.aether.resolution.MetadataRequest; import org.sonatype.aether.resolution.MetadataRequest;
import org.sonatype.aether.resolution.MetadataResult; import org.sonatype.aether.resolution.MetadataResult;
import org.sonatype.aether.util.DefaultRepositorySystemSession; import org.sonatype.aether.util.DefaultRepositorySystemSession;
import org.sonatype.aether.util.DefaultRequestTrace;
import org.sonatype.aether.util.listener.DefaultRepositoryEvent; import org.sonatype.aether.util.listener.DefaultRepositoryEvent;
import org.sonatype.aether.util.metadata.DefaultMetadata; import org.sonatype.aether.util.metadata.DefaultMetadata;
@ -161,6 +163,8 @@ public class DefaultPluginPrefixResolver
private PluginPrefixResult resolveFromRepository( PluginPrefixRequest request ) private PluginPrefixResult resolveFromRepository( PluginPrefixRequest request )
{ {
RequestTrace trace = DefaultRequestTrace.newChild( null, request );
List<MetadataRequest> requests = new ArrayList<MetadataRequest>(); List<MetadataRequest> requests = new ArrayList<MetadataRequest>();
for ( String pluginGroup : request.getPluginGroups() ) for ( String pluginGroup : request.getPluginGroups() )
@ -168,11 +172,11 @@ public class DefaultPluginPrefixResolver
org.sonatype.aether.metadata.Metadata metadata = org.sonatype.aether.metadata.Metadata metadata =
new DefaultMetadata( pluginGroup, "maven-metadata.xml", DefaultMetadata.Nature.RELEASE_OR_SNAPSHOT ); new DefaultMetadata( pluginGroup, "maven-metadata.xml", DefaultMetadata.Nature.RELEASE_OR_SNAPSHOT );
requests.add( new MetadataRequest( metadata, null, REPOSITORY_CONTEXT ) ); requests.add( new MetadataRequest( metadata, null, REPOSITORY_CONTEXT ).setTrace( trace ) );
for ( RemoteRepository repository : request.getRepositories() ) for ( RemoteRepository repository : request.getRepositories() )
{ {
requests.add( new MetadataRequest( metadata, repository, REPOSITORY_CONTEXT ) ); requests.add( new MetadataRequest( metadata, repository, REPOSITORY_CONTEXT ).setTrace( trace ) );
} }
} }
@ -181,7 +185,7 @@ public class DefaultPluginPrefixResolver
List<MetadataResult> results = repositorySystem.resolveMetadata( request.getRepositorySession(), requests ); List<MetadataResult> results = repositorySystem.resolveMetadata( request.getRepositorySession(), requests );
requests.clear(); requests.clear();
PluginPrefixResult result = processResults( request, results, requests ); PluginPrefixResult result = processResults( request, trace, results, requests );
if ( result != null ) if ( result != null )
{ {
@ -198,14 +202,14 @@ public class DefaultPluginPrefixResolver
results = repositorySystem.resolveMetadata( session, requests ); results = repositorySystem.resolveMetadata( session, requests );
return processResults( request, results, null ); return processResults( request, trace, results, null );
} }
return null; return null;
} }
private PluginPrefixResult processResults( PluginPrefixRequest request, List<MetadataResult> results, private PluginPrefixResult processResults( PluginPrefixRequest request, RequestTrace trace,
List<MetadataRequest> requests ) List<MetadataResult> results, List<MetadataRequest> requests )
{ {
for ( MetadataResult res : results ) for ( MetadataResult res : results )
{ {
@ -220,7 +224,7 @@ public class DefaultPluginPrefixResolver
} }
PluginPrefixResult result = PluginPrefixResult result =
resolveFromRepository( request, metadata.getGroupId(), metadata, repository ); resolveFromRepository( request, trace, metadata.getGroupId(), metadata, repository );
if ( result != null ) if ( result != null )
{ {
@ -237,7 +241,8 @@ public class DefaultPluginPrefixResolver
return null; return null;
} }
private PluginPrefixResult resolveFromRepository( PluginPrefixRequest request, String pluginGroup, private PluginPrefixResult resolveFromRepository( PluginPrefixRequest request, RequestTrace trace,
String pluginGroup,
org.sonatype.aether.metadata.Metadata metadata, org.sonatype.aether.metadata.Metadata metadata,
ArtifactRepository repository ) ArtifactRepository repository )
{ {
@ -264,20 +269,21 @@ public class DefaultPluginPrefixResolver
} }
catch ( IOException e ) catch ( IOException e )
{ {
invalidMetadata( request.getRepositorySession(), metadata, repository, e ); invalidMetadata( request.getRepositorySession(), trace, metadata, repository, e );
} }
} }
return null; return null;
} }
private void invalidMetadata( RepositorySystemSession session, org.sonatype.aether.metadata.Metadata metadata, private void invalidMetadata( RepositorySystemSession session, RequestTrace trace,
ArtifactRepository repository, Exception exception ) org.sonatype.aether.metadata.Metadata metadata, ArtifactRepository repository,
Exception exception )
{ {
RepositoryListener listener = session.getRepositoryListener(); RepositoryListener listener = session.getRepositoryListener();
if ( listener != null ) if ( listener != null )
{ {
DefaultRepositoryEvent event = new DefaultRepositoryEvent( EventType.METADATA_INVALID, session ); DefaultRepositoryEvent event = new DefaultRepositoryEvent( EventType.METADATA_INVALID, session, trace );
event.setMetadata( metadata ); event.setMetadata( metadata );
event.setException( exception ); event.setException( exception );
event.setRepository( repository ); event.setRepository( repository );

View File

@ -47,10 +47,12 @@ import org.sonatype.aether.RepositoryEvent.EventType;
import org.sonatype.aether.RepositoryListener; import org.sonatype.aether.RepositoryListener;
import org.sonatype.aether.RepositorySystem; import org.sonatype.aether.RepositorySystem;
import org.sonatype.aether.RepositorySystemSession; import org.sonatype.aether.RepositorySystemSession;
import org.sonatype.aether.RequestTrace;
import org.sonatype.aether.repository.ArtifactRepository; import org.sonatype.aether.repository.ArtifactRepository;
import org.sonatype.aether.repository.RemoteRepository; import org.sonatype.aether.repository.RemoteRepository;
import org.sonatype.aether.resolution.MetadataRequest; import org.sonatype.aether.resolution.MetadataRequest;
import org.sonatype.aether.resolution.MetadataResult; import org.sonatype.aether.resolution.MetadataResult;
import org.sonatype.aether.util.DefaultRequestTrace;
import org.sonatype.aether.util.listener.DefaultRepositoryEvent; import org.sonatype.aether.util.listener.DefaultRepositoryEvent;
import org.sonatype.aether.util.metadata.DefaultMetadata; import org.sonatype.aether.util.metadata.DefaultMetadata;
import org.sonatype.aether.util.version.GenericVersionScheme; import org.sonatype.aether.util.version.GenericVersionScheme;
@ -112,6 +114,8 @@ public class DefaultPluginVersionResolver
private PluginVersionResult resolveFromRepository( PluginVersionRequest request ) private PluginVersionResult resolveFromRepository( PluginVersionRequest request )
throws PluginVersionResolutionException throws PluginVersionResolutionException
{ {
RequestTrace trace = DefaultRequestTrace.newChild( null, request );
DefaultPluginVersionResult result = new DefaultPluginVersionResult(); DefaultPluginVersionResult result = new DefaultPluginVersionResult();
org.sonatype.aether.metadata.Metadata metadata = org.sonatype.aether.metadata.Metadata metadata =
@ -120,11 +124,11 @@ public class DefaultPluginVersionResolver
List<MetadataRequest> requests = new ArrayList<MetadataRequest>(); List<MetadataRequest> requests = new ArrayList<MetadataRequest>();
requests.add( new MetadataRequest( metadata, null, REPOSITORY_CONTEXT ) ); requests.add( new MetadataRequest( metadata, null, REPOSITORY_CONTEXT ).setTrace( trace ) );
for ( RemoteRepository repository : request.getRepositories() ) for ( RemoteRepository repository : request.getRepositories() )
{ {
requests.add( new MetadataRequest( metadata, repository, REPOSITORY_CONTEXT ) ); requests.add( new MetadataRequest( metadata, repository, REPOSITORY_CONTEXT ).setTrace( trace ) );
} }
List<MetadataResult> results = repositorySystem.resolveMetadata( request.getRepositorySession(), requests ); List<MetadataResult> results = repositorySystem.resolveMetadata( request.getRepositorySession(), requests );
@ -139,7 +143,7 @@ public class DefaultPluginVersionResolver
repository = request.getRepositorySession().getLocalRepository(); repository = request.getRepositorySession().getLocalRepository();
} }
mergeMetadata( request.getRepositorySession(), versions, res.getMetadata(), repository ); mergeMetadata( request.getRepositorySession(), trace, versions, res.getMetadata(), repository );
} }
selectVersion( result, request, versions ); selectVersion( result, request, versions );
@ -275,7 +279,7 @@ public class DefaultPluginVersionResolver
return true; return true;
} }
private void mergeMetadata( RepositorySystemSession session, Versions versions, private void mergeMetadata( RepositorySystemSession session, RequestTrace trace, Versions versions,
org.sonatype.aether.metadata.Metadata metadata, ArtifactRepository repository ) org.sonatype.aether.metadata.Metadata metadata, ArtifactRepository repository )
{ {
if ( metadata != null && metadata.getFile() != null && metadata.getFile().isFile() ) if ( metadata != null && metadata.getFile() != null && metadata.getFile().isFile() )
@ -290,18 +294,19 @@ public class DefaultPluginVersionResolver
} }
catch ( IOException e ) catch ( IOException e )
{ {
invalidMetadata( session, metadata, repository, e ); invalidMetadata( session, trace, metadata, repository, e );
} }
} }
} }
private void invalidMetadata( RepositorySystemSession session, org.sonatype.aether.metadata.Metadata metadata, private void invalidMetadata( RepositorySystemSession session, RequestTrace trace,
ArtifactRepository repository, Exception exception ) org.sonatype.aether.metadata.Metadata metadata, ArtifactRepository repository,
Exception exception )
{ {
RepositoryListener listener = session.getRepositoryListener(); RepositoryListener listener = session.getRepositoryListener();
if ( listener != null ) if ( listener != null )
{ {
DefaultRepositoryEvent event = new DefaultRepositoryEvent( EventType.METADATA_INVALID, session ); DefaultRepositoryEvent event = new DefaultRepositoryEvent( EventType.METADATA_INVALID, session, trace );
event.setMetadata( metadata ); event.setMetadata( metadata );
event.setException( exception ); event.setException( exception );
event.setRepository( repository ); event.setRepository( repository );

View File

@ -50,12 +50,14 @@ import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.util.Os; import org.codehaus.plexus.util.Os;
import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.StringUtils;
import org.sonatype.aether.RepositorySystemSession; import org.sonatype.aether.RepositorySystemSession;
import org.sonatype.aether.RequestTrace;
import org.sonatype.aether.impl.RemoteRepositoryManager; import org.sonatype.aether.impl.RemoteRepositoryManager;
import org.sonatype.aether.repository.LocalRepositoryManager; import org.sonatype.aether.repository.LocalRepositoryManager;
import org.sonatype.aether.repository.RemoteRepository; import org.sonatype.aether.repository.RemoteRepository;
import org.sonatype.aether.repository.WorkspaceRepository; import org.sonatype.aether.repository.WorkspaceRepository;
import org.sonatype.aether.resolution.ArtifactRequest; import org.sonatype.aether.resolution.ArtifactRequest;
import org.sonatype.aether.resolution.ArtifactResult; import org.sonatype.aether.resolution.ArtifactResult;
import org.sonatype.aether.util.DefaultRequestTrace;
import org.sonatype.aether.util.artifact.SubArtifact; import org.sonatype.aether.util.artifact.SubArtifact;
/** /**
@ -213,12 +215,14 @@ public class DefaultProjectBuilder
{ {
ProjectBuildingRequest configuration = config.request; ProjectBuildingRequest configuration = config.request;
ModelResolver resolver =
new ProjectModelResolver( config.session, repoSystem, repositoryManager, config.repositories,
configuration.getRepositoryMerging(), config.modelPool );
ModelBuildingRequest request = new DefaultModelBuildingRequest(); ModelBuildingRequest request = new DefaultModelBuildingRequest();
RequestTrace trace = DefaultRequestTrace.newChild( null, configuration ).newChild( request );
ModelResolver resolver =
new ProjectModelResolver( config.session, trace, repoSystem, repositoryManager, config.repositories,
configuration.getRepositoryMerging(), config.modelPool );
request.setValidationLevel( configuration.getValidationLevel() ); request.setValidationLevel( configuration.getValidationLevel() );
request.setProcessPlugins( configuration.isProcessPlugins() ); request.setProcessPlugins( configuration.isProcessPlugins() );
request.setProfiles( configuration.getProfiles() ); request.setProfiles( configuration.getProfiles() );

View File

@ -33,14 +33,16 @@ import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.logging.Logger; import org.codehaus.plexus.logging.Logger;
import org.sonatype.aether.RepositorySystem; import org.sonatype.aether.RepositorySystem;
import org.sonatype.aether.RepositorySystemSession; import org.sonatype.aether.RepositorySystemSession;
import org.sonatype.aether.RequestTrace;
import org.sonatype.aether.artifact.ArtifactTypeRegistry; import org.sonatype.aether.artifact.ArtifactTypeRegistry;
import org.sonatype.aether.collection.CollectRequest; import org.sonatype.aether.collection.CollectRequest;
import org.sonatype.aether.collection.DependencyCollectionException; import org.sonatype.aether.collection.DependencyCollectionException;
import org.sonatype.aether.graph.DependencyFilter; import org.sonatype.aether.graph.DependencyFilter;
import org.sonatype.aether.graph.DependencyNode; import org.sonatype.aether.graph.DependencyNode;
import org.sonatype.aether.graph.DependencyVisitor; import org.sonatype.aether.graph.DependencyVisitor;
import org.sonatype.aether.resolution.ArtifactResolutionException;
import org.sonatype.aether.resolution.ArtifactResult; import org.sonatype.aether.resolution.ArtifactResult;
import org.sonatype.aether.resolution.DependencyRequest;
import org.sonatype.aether.util.DefaultRequestTrace;
import org.sonatype.aether.util.artifact.JavaScopes; import org.sonatype.aether.util.artifact.JavaScopes;
/** /**
@ -60,6 +62,8 @@ public class DefaultProjectDependenciesResolver
public DependencyResolutionResult resolve( DependencyResolutionRequest request ) public DependencyResolutionResult resolve( DependencyResolutionRequest request )
throws DependencyResolutionException throws DependencyResolutionException
{ {
RequestTrace trace = DefaultRequestTrace.newChild( null, request );
DefaultDependencyResolutionResult result = new DefaultDependencyResolutionResult(); DefaultDependencyResolutionResult result = new DefaultDependencyResolutionResult();
MavenProject project = request.getMavenProject(); MavenProject project = request.getMavenProject();
@ -113,9 +117,13 @@ public class DefaultProjectDependenciesResolver
} }
} }
DependencyRequest depRequest = new DependencyRequest( collect, filter );
depRequest.setTrace( trace );
DependencyNode node; DependencyNode node;
try try
{ {
collect.setTrace( DefaultRequestTrace.newChild( trace, depRequest ) );
node = repoSystem.collectDependencies( session, collect ).getRoot(); node = repoSystem.collectDependencies( session, collect ).getRoot();
result.setDependencyGraph( node ); result.setDependencyGraph( node );
} }
@ -128,6 +136,8 @@ public class DefaultProjectDependenciesResolver
+ project.getId() + ": " + e.getMessage(), e ); + project.getId() + ": " + e.getMessage(), e );
} }
depRequest.setRoot( node );
if ( logger.isWarnEnabled() ) if ( logger.isWarnEnabled() )
{ {
for ( DependencyNode child : node.getChildren() ) for ( DependencyNode child : node.getChildren() )
@ -147,11 +157,11 @@ public class DefaultProjectDependenciesResolver
try try
{ {
process( result, repoSystem.resolveDependencies( session, node, filter ) ); process( result, repoSystem.resolveDependencies( session, depRequest ).getArtifactResults() );
} }
catch ( ArtifactResolutionException e ) catch ( org.sonatype.aether.resolution.DependencyResolutionException e )
{ {
process( result, e.getResults() ); process( result, e.getResult().getArtifactResults() );
throw new DependencyResolutionException( result, "Could not resolve dependencies for project " throw new DependencyResolutionException( result, "Could not resolve dependencies for project "
+ project.getId() + ": " + e.getMessage(), e ); + project.getId() + ": " + e.getMessage(), e );
@ -167,7 +177,6 @@ public class DefaultProjectDependenciesResolver
DependencyNode node = ar.getRequest().getDependencyNode(); DependencyNode node = ar.getRequest().getDependencyNode();
if ( ar.isResolved() ) if ( ar.isResolved() )
{ {
node.setArtifact( ar.getArtifact() );
result.addResolvedDependency( node.getDependency() ); result.addResolvedDependency( node.getDependency() );
} }
else else

View File

@ -34,6 +34,7 @@ import org.apache.maven.model.resolution.ModelResolver;
import org.apache.maven.model.resolution.UnresolvableModelException; import org.apache.maven.model.resolution.UnresolvableModelException;
import org.sonatype.aether.RepositorySystem; import org.sonatype.aether.RepositorySystem;
import org.sonatype.aether.RepositorySystemSession; import org.sonatype.aether.RepositorySystemSession;
import org.sonatype.aether.RequestTrace;
import org.sonatype.aether.artifact.Artifact; import org.sonatype.aether.artifact.Artifact;
import org.sonatype.aether.impl.RemoteRepositoryManager; import org.sonatype.aether.impl.RemoteRepositoryManager;
import org.sonatype.aether.repository.RemoteRepository; import org.sonatype.aether.repository.RemoteRepository;
@ -54,6 +55,8 @@ class ProjectModelResolver
private final RepositorySystemSession session; private final RepositorySystemSession session;
private final RequestTrace trace;
private final String context = "project"; private final String context = "project";
private List<RemoteRepository> repositories; private List<RemoteRepository> repositories;
@ -72,11 +75,12 @@ class ProjectModelResolver
private final ProjectBuildingRequest.RepositoryMerging repositoryMerging; private final ProjectBuildingRequest.RepositoryMerging repositoryMerging;
public ProjectModelResolver( RepositorySystemSession session, RepositorySystem resolver, public ProjectModelResolver( RepositorySystemSession session, RequestTrace trace, RepositorySystem resolver,
RemoteRepositoryManager remoteRepositoryManager, List<RemoteRepository> repositories, RemoteRepositoryManager remoteRepositoryManager, List<RemoteRepository> repositories,
ProjectBuildingRequest.RepositoryMerging repositoryMerging, ReactorModelPool modelPool ) ProjectBuildingRequest.RepositoryMerging repositoryMerging, ReactorModelPool modelPool )
{ {
this.session = session; this.session = session;
this.trace = trace;
this.resolver = resolver; this.resolver = resolver;
this.remoteRepositoryManager = remoteRepositoryManager; this.remoteRepositoryManager = remoteRepositoryManager;
this.pomRepositories = new ArrayList<RemoteRepository>(); this.pomRepositories = new ArrayList<RemoteRepository>();
@ -90,6 +94,7 @@ class ProjectModelResolver
private ProjectModelResolver( ProjectModelResolver original ) private ProjectModelResolver( ProjectModelResolver original )
{ {
this.session = original.session; this.session = original.session;
this.trace = original.trace;
this.resolver = original.resolver; this.resolver = original.resolver;
this.remoteRepositoryManager = original.remoteRepositoryManager; this.remoteRepositoryManager = original.remoteRepositoryManager;
this.pomRepositories = original.pomRepositories; this.pomRepositories = original.pomRepositories;
@ -176,6 +181,7 @@ class ProjectModelResolver
try try
{ {
ArtifactRequest request = new ArtifactRequest( pomArtifact, repositories, context ); ArtifactRequest request = new ArtifactRequest( pomArtifact, repositories, context );
request.setTrace( trace );
pomArtifact = resolver.resolveArtifact( session, request ).getArtifact(); pomArtifact = resolver.resolveArtifact( session, request ).getArtifact();
} }
catch ( ArtifactResolutionException e ) catch ( ArtifactResolutionException e )