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.RepositoryListener;
import org.sonatype.aether.RepositorySystemSession;
import org.sonatype.aether.RequestTrace;
import org.sonatype.aether.artifact.Artifact;
import org.sonatype.aether.artifact.ArtifactType;
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.VersionResolver;
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.DefaultArtifact;
import org.sonatype.aether.util.artifact.DefaultArtifactType;
@ -224,6 +226,8 @@ public class DefaultArtifactDescriptorReader
ArtifactDescriptorResult result )
throws ArtifactDescriptorException
{
RequestTrace trace = DefaultRequestTrace.newChild( request.getTrace(), request );
Set<String> visited = new LinkedHashSet<String>();
for ( Artifact artifact = request.getArtifact();; )
{
@ -231,6 +235,7 @@ public class DefaultArtifactDescriptorReader
{
VersionRequest versionRequest =
new VersionRequest( artifact, request.getRepositories(), request.getRequestContext() );
versionRequest.setTrace( trace );
VersionResult versionResult = versionResolver.resolveVersion( session, versionRequest );
artifact = artifact.setVersion( versionResult.getVersion() );
@ -245,7 +250,7 @@ public class DefaultArtifactDescriptorReader
{
RepositoryException exception =
new RepositoryException( "Artifact relocations form a cycle: " + visited );
invalidDescriptor( session, artifact, exception );
invalidDescriptor( session, trace, artifact, exception );
if ( session.isIgnoreInvalidArtifactDescriptor() )
{
return null;
@ -265,6 +270,7 @@ public class DefaultArtifactDescriptorReader
{
ArtifactRequest resolveRequest =
new ArtifactRequest( pomArtifact, request.getRepositories(), request.getRequestContext() );
resolveRequest.setTrace( trace );
resolveResult = artifactResolver.resolveArtifact( session, resolveRequest );
pomArtifact = resolveResult.getArtifact();
result.setRepository( resolveResult.getRepository() );
@ -273,7 +279,7 @@ public class DefaultArtifactDescriptorReader
{
if ( e.getCause() instanceof ArtifactNotFoundException )
{
missingDescriptor( session, artifact, (Exception) e.getCause() );
missingDescriptor( session, trace, artifact, (Exception) e.getCause() );
if ( session.isIgnoreMissingArtifactDescriptor() )
{
return null;
@ -293,8 +299,9 @@ public class DefaultArtifactDescriptorReader
modelRequest.setSystemProperties( toProperties( session.getUserProperties(),
session.getSystemProperties() ) );
modelRequest.setModelCache( DefaultModelCache.newInstance( session ) );
modelRequest.setModelResolver( new DefaultModelResolver( session, request.getRequestContext(),
artifactResolver, remoteRepositoryManager,
modelRequest.setModelResolver( new DefaultModelResolver( session, trace.newChild( modelRequest ),
request.getRequestContext(), artifactResolver,
remoteRepositoryManager,
request.getRepositories() ) );
if ( resolveResult.getRepository() instanceof WorkspaceRepository )
{
@ -317,7 +324,7 @@ public class DefaultArtifactDescriptorReader
throw new ArtifactDescriptorException( result );
}
}
invalidDescriptor( session, artifact, e );
invalidDescriptor( session, trace, artifact, e );
if ( session.isIgnoreInvalidArtifactDescriptor() )
{
return null;
@ -435,24 +442,28 @@ public class DefaultArtifactDescriptorReader
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();
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.setException( exception );
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();
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.setException( exception );
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.UnresolvableModelException;
import org.sonatype.aether.RepositorySystemSession;
import org.sonatype.aether.RequestTrace;
import org.sonatype.aether.artifact.Artifact;
import org.sonatype.aether.impl.ArtifactResolver;
import org.sonatype.aether.impl.RemoteRepositoryManager;
@ -53,6 +54,8 @@ class DefaultModelResolver
private final RepositorySystemSession session;
private final RequestTrace trace;
private final String context;
private List<RemoteRepository> repositories;
@ -63,10 +66,12 @@ class DefaultModelResolver
private final Set<String> repositoryIds;
public DefaultModelResolver( RepositorySystemSession session, String context, ArtifactResolver resolver,
RemoteRepositoryManager remoteRepositoryManager, List<RemoteRepository> repositories )
public DefaultModelResolver( RepositorySystemSession session, RequestTrace trace, String context,
ArtifactResolver resolver, RemoteRepositoryManager remoteRepositoryManager,
List<RemoteRepository> repositories )
{
this.session = session;
this.trace = trace;
this.context = context;
this.resolver = resolver;
this.remoteRepositoryManager = remoteRepositoryManager;
@ -77,6 +82,7 @@ class DefaultModelResolver
private DefaultModelResolver( DefaultModelResolver original )
{
this.session = original.session;
this.trace = original.trace;
this.context = original.context;
this.resolver = original.resolver;
this.remoteRepositoryManager = original.remoteRepositoryManager;
@ -112,6 +118,7 @@ class DefaultModelResolver
try
{
ArtifactRequest request = new ArtifactRequest( pomArtifact, repositories, context );
request.setTrace( trace );
pomArtifact = resolver.resolveArtifact( session, request ).getArtifact();
}
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.RepositoryListener;
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.metadata.DefaultMetadata;
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.VersionScheme;
import org.sonatype.aether.impl.MetadataResolver;
import org.sonatype.aether.impl.SyncContextFactory;
import org.sonatype.aether.impl.VersionRangeResolver;
import org.sonatype.aether.metadata.Metadata;
import org.sonatype.aether.repository.ArtifactRepository;
@ -67,16 +71,21 @@ public class DefaultVersionRangeResolver
private static final String MAVEN_METADATA_XML = "maven-metadata.xml";
@SuppressWarnings( "unused" )
@Requirement
private Logger logger = NullLogger.INSTANCE;
@Requirement
private MetadataResolver metadataResolver;
@Requirement
private SyncContextFactory syncContextFactory;
public void initService( ServiceLocator locator )
{
setLogger( locator.getService( Logger.class ) );
setMetadataResolver( locator.getService( MetadataResolver.class ) );
setSyncContextFactory( locator.getService( SyncContextFactory.class ) );
}
public DefaultVersionRangeResolver setLogger( Logger logger )
@ -95,6 +104,16 @@ public class DefaultVersionRangeResolver
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 )
throws VersionRangeResolutionException
{
@ -151,6 +170,8 @@ public class DefaultVersionRangeResolver
private Map<String, ArtifactRepository> getVersions( RepositorySystemSession session, VersionRangeResult result,
VersionRangeRequest request )
{
RequestTrace trace = DefaultRequestTrace.newChild( request.getTrace(), request );
Map<String, ArtifactRepository> versionIndex = new HashMap<String, ArtifactRepository>();
Metadata metadata =
@ -165,6 +186,7 @@ public class DefaultVersionRangeResolver
{
MetadataRequest metadataRequest = new MetadataRequest( metadata, repository, request.getRequestContext() );
metadataRequest.setDeleteLocalCopyIfMissing( true );
metadataRequest.setTrace( trace );
metadataRequests.add( metadataRequest );
}
@ -190,7 +212,7 @@ public class DefaultVersionRangeResolver
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() )
{
if ( !versionIndex.containsKey( version ) )
@ -203,24 +225,39 @@ public class DefaultVersionRangeResolver
return versionIndex;
}
private Versioning readVersions( RepositorySystemSession session, Metadata metadata, ArtifactRepository repository,
VersionRangeResult result )
private Versioning readVersions( RepositorySystemSession session, RequestTrace trace, Metadata metadata,
ArtifactRepository repository, VersionRangeResult result )
{
Versioning versioning = null;
FileInputStream fis = null;
try
{
if ( metadata != null && metadata.getFile() != null && metadata.getFile().exists() )
if ( metadata != null )
{
fis = new FileInputStream( metadata.getFile() );
org.apache.maven.artifact.repository.metadata.Metadata m = new MetadataXpp3Reader().read( fis, false );
versioning = m.getVersioning();
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() );
org.apache.maven.artifact.repository.metadata.Metadata m =
new MetadataXpp3Reader().read( fis, false );
versioning = m.getVersioning();
}
}
finally
{
syncContext.release();
}
}
}
catch ( Exception e )
{
invalidMetadata( session, metadata, repository, e );
invalidMetadata( session, trace, metadata, repository, e );
result.addException( e );
}
finally
@ -231,13 +268,13 @@ public class DefaultVersionRangeResolver
return ( versioning != null ) ? versioning : new Versioning();
}
private void invalidMetadata( RepositorySystemSession session, Metadata metadata, ArtifactRepository repository,
Exception exception )
private void invalidMetadata( RepositorySystemSession session, RequestTrace trace, Metadata metadata,
ArtifactRepository repository, Exception exception )
{
RepositoryListener listener = session.getRepositoryListener();
if ( listener != null )
{
DefaultRepositoryEvent event = new DefaultRepositoryEvent( EventType.METADATA_INVALID, session );
DefaultRepositoryEvent event = new DefaultRepositoryEvent( EventType.METADATA_INVALID, session, trace );
event.setMetadata( metadata );
event.setException( exception );
event.setRepository( repository );

View File

@ -38,14 +38,18 @@ import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.StringUtils;
import org.sonatype.aether.ConfigurationProperties;
import org.sonatype.aether.RepositoryCache;
import org.sonatype.aether.RequestTrace;
import org.sonatype.aether.RepositoryEvent.EventType;
import org.sonatype.aether.RepositoryListener;
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.listener.DefaultRepositoryEvent;
import org.sonatype.aether.util.metadata.DefaultMetadata;
import org.sonatype.aether.artifact.Artifact;
import org.sonatype.aether.impl.MetadataResolver;
import org.sonatype.aether.impl.SyncContextFactory;
import org.sonatype.aether.impl.VersionResolver;
import org.sonatype.aether.impl.internal.CacheUtils;
import org.sonatype.aether.metadata.Metadata;
@ -80,16 +84,21 @@ public class DefaultVersionResolver
private static final String SNAPSHOT = "SNAPSHOT";
@SuppressWarnings( "unused" )
@Requirement
private Logger logger = NullLogger.INSTANCE;
@Requirement
private MetadataResolver metadataResolver;
@Requirement
private SyncContextFactory syncContextFactory;
public void initService( ServiceLocator locator )
{
setLogger( locator.getService( Logger.class ) );
setMetadataResolver( locator.getService( MetadataResolver.class ) );
setSyncContextFactory( locator.getService( SyncContextFactory.class ) );
}
public DefaultVersionResolver setLogger( Logger logger )
@ -108,9 +117,21 @@ public class DefaultVersionResolver
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 )
throws VersionResolutionException
{
RequestTrace trace = DefaultRequestTrace.newChild( request.getTrace(), request );
Artifact artifact = request.getArtifact();
String version = artifact.getVersion();
@ -184,6 +205,7 @@ public class DefaultVersionResolver
new MetadataRequest( metadata, repository, request.getRequestContext() );
metadataRequest.setDeleteLocalCopyIfMissing( true );
metadataRequest.setFavorLocalRepository( true );
metadataRequest.setTrace( trace );
metadataRequests.add( metadataRequest );
}
@ -201,7 +223,7 @@ public class DefaultVersionResolver
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 );
}
@ -272,45 +294,61 @@ public class DefaultVersionResolver
return info != null;
}
private Versioning readVersions( RepositorySystemSession session, Metadata metadata, ArtifactRepository repository,
VersionResult result )
private Versioning readVersions( RepositorySystemSession session, RequestTrace trace, Metadata metadata,
ArtifactRepository repository, VersionResult result )
{
Versioning versioning = null;
FileInputStream fis = null;
try
{
if ( metadata != null && metadata.getFile() != null && metadata.getFile().exists() )
if ( metadata != null )
{
fis = new FileInputStream( metadata.getFile() );
org.apache.maven.artifact.repository.metadata.Metadata m = new MetadataXpp3Reader().read( fis, false );
versioning = m.getVersioning();
SyncContext syncContext = syncContextFactory.newInstance( session, true );
/*
* NOTE: Users occasionally misuse the id "local" for remote repos which screws up the metadata of the
* local repository. This is especially troublesome during snapshot resolution so we try to handle that
* gracefully.
*/
if ( versioning != null && repository instanceof LocalRepository )
try
{
if ( versioning.getSnapshot() != null && versioning.getSnapshot().getBuildNumber() > 0 )
{
Versioning repaired = new Versioning();
repaired.setLastUpdated( versioning.getLastUpdated() );
Snapshot snapshot = new Snapshot();
snapshot.setLocalCopy( true );
repaired.setSnapshot( snapshot );
versioning = repaired;
syncContext.acquire( null, Collections.singleton( metadata ) );
throw new IOException( "Snapshot information corrupted with remote repository data"
+ ", please verify that no remote repository uses the id '" + repository.getId() + "'" );
if ( metadata.getFile() != null && metadata.getFile().exists() )
{
fis = new FileInputStream( metadata.getFile() );
org.apache.maven.artifact.repository.metadata.Metadata m =
new MetadataXpp3Reader().read( fis, false );
versioning = m.getVersioning();
/*
* NOTE: Users occasionally misuse the id "local" for remote repos which screws up the metadata
* of the local repository. This is especially troublesome during snapshot resolution so we try
* to handle that gracefully.
*/
if ( versioning != null && repository instanceof LocalRepository )
{
if ( versioning.getSnapshot() != null && versioning.getSnapshot().getBuildNumber() > 0 )
{
Versioning repaired = new Versioning();
repaired.setLastUpdated( versioning.getLastUpdated() );
Snapshot snapshot = new Snapshot();
snapshot.setLocalCopy( true );
repaired.setSnapshot( snapshot );
versioning = repaired;
throw new IOException( "Snapshot information corrupted with remote repository data"
+ ", please verify that no remote repository uses the id '" + repository.getId()
+ "'" );
}
}
}
}
finally
{
syncContext.release();
}
}
}
catch ( Exception e )
{
invalidMetadata( session, metadata, repository, e );
invalidMetadata( session, trace, metadata, repository, e );
result.addException( e );
}
finally
@ -321,13 +359,13 @@ public class DefaultVersionResolver
return ( versioning != null ) ? versioning : new Versioning();
}
private void invalidMetadata( RepositorySystemSession session, Metadata metadata, ArtifactRepository repository,
Exception exception )
private void invalidMetadata( RepositorySystemSession session, RequestTrace trace, Metadata metadata,
ArtifactRepository repository, Exception exception )
{
RepositoryListener listener = session.getRepositoryListener();
if ( listener != null )
{
DefaultRepositoryEvent event = new DefaultRepositoryEvent( EventType.METADATA_INVALID, session );
DefaultRepositoryEvent event = new DefaultRepositoryEvent( EventType.METADATA_INVALID, session, trace );
event.setMetadata( metadata );
event.setException( exception );
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.metadata.MergeableMetadata;
import org.sonatype.aether.repository.RemoteRepository;
import org.sonatype.aether.util.DefaultRequestTrace;
import org.sonatype.aether.util.artifact.SubArtifact;
@Component( role = ArtifactDeployer.class, instantiationStrategy = "per-lookup" )
@ -83,6 +84,8 @@ public class DefaultArtifactDeployer
DeployRequest request = new DeployRequest();
request.setTrace( DefaultRequestTrace.newChild( null, legacySupport.getSession().getCurrentProject() ) );
org.sonatype.aether.artifact.Artifact mainArtifact = RepositoryUtils.toArtifact( artifact );
mainArtifact = mainArtifact.setFile( source );
request.addArtifact( mainArtifact );

View File

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

View File

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

View File

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

View File

@ -47,10 +47,12 @@ import org.sonatype.aether.RepositoryEvent.EventType;
import org.sonatype.aether.RepositoryListener;
import org.sonatype.aether.RepositorySystem;
import org.sonatype.aether.RepositorySystemSession;
import org.sonatype.aether.RequestTrace;
import org.sonatype.aether.repository.ArtifactRepository;
import org.sonatype.aether.repository.RemoteRepository;
import org.sonatype.aether.resolution.MetadataRequest;
import org.sonatype.aether.resolution.MetadataResult;
import org.sonatype.aether.util.DefaultRequestTrace;
import org.sonatype.aether.util.listener.DefaultRepositoryEvent;
import org.sonatype.aether.util.metadata.DefaultMetadata;
import org.sonatype.aether.util.version.GenericVersionScheme;
@ -112,6 +114,8 @@ public class DefaultPluginVersionResolver
private PluginVersionResult resolveFromRepository( PluginVersionRequest request )
throws PluginVersionResolutionException
{
RequestTrace trace = DefaultRequestTrace.newChild( null, request );
DefaultPluginVersionResult result = new DefaultPluginVersionResult();
org.sonatype.aether.metadata.Metadata metadata =
@ -120,11 +124,11 @@ public class DefaultPluginVersionResolver
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() )
{
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 );
@ -139,7 +143,7 @@ public class DefaultPluginVersionResolver
repository = request.getRepositorySession().getLocalRepository();
}
mergeMetadata( request.getRepositorySession(), versions, res.getMetadata(), repository );
mergeMetadata( request.getRepositorySession(), trace, versions, res.getMetadata(), repository );
}
selectVersion( result, request, versions );
@ -275,7 +279,7 @@ public class DefaultPluginVersionResolver
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 )
{
if ( metadata != null && metadata.getFile() != null && metadata.getFile().isFile() )
@ -290,18 +294,19 @@ public class DefaultPluginVersionResolver
}
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,
ArtifactRepository repository, Exception exception )
private void invalidMetadata( RepositorySystemSession session, RequestTrace trace,
org.sonatype.aether.metadata.Metadata metadata, ArtifactRepository repository,
Exception exception )
{
RepositoryListener listener = session.getRepositoryListener();
if ( listener != null )
{
DefaultRepositoryEvent event = new DefaultRepositoryEvent( EventType.METADATA_INVALID, session );
DefaultRepositoryEvent event = new DefaultRepositoryEvent( EventType.METADATA_INVALID, session, trace );
event.setMetadata( metadata );
event.setException( exception );
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.StringUtils;
import org.sonatype.aether.RepositorySystemSession;
import org.sonatype.aether.RequestTrace;
import org.sonatype.aether.impl.RemoteRepositoryManager;
import org.sonatype.aether.repository.LocalRepositoryManager;
import org.sonatype.aether.repository.RemoteRepository;
import org.sonatype.aether.repository.WorkspaceRepository;
import org.sonatype.aether.resolution.ArtifactRequest;
import org.sonatype.aether.resolution.ArtifactResult;
import org.sonatype.aether.util.DefaultRequestTrace;
import org.sonatype.aether.util.artifact.SubArtifact;
/**
@ -213,12 +215,14 @@ public class DefaultProjectBuilder
{
ProjectBuildingRequest configuration = config.request;
ModelResolver resolver =
new ProjectModelResolver( config.session, repoSystem, repositoryManager, config.repositories,
configuration.getRepositoryMerging(), config.modelPool );
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.setProcessPlugins( configuration.isProcessPlugins() );
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.sonatype.aether.RepositorySystem;
import org.sonatype.aether.RepositorySystemSession;
import org.sonatype.aether.RequestTrace;
import org.sonatype.aether.artifact.ArtifactTypeRegistry;
import org.sonatype.aether.collection.CollectRequest;
import org.sonatype.aether.collection.DependencyCollectionException;
import org.sonatype.aether.graph.DependencyFilter;
import org.sonatype.aether.graph.DependencyNode;
import org.sonatype.aether.graph.DependencyVisitor;
import org.sonatype.aether.resolution.ArtifactResolutionException;
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;
/**
@ -60,6 +62,8 @@ public class DefaultProjectDependenciesResolver
public DependencyResolutionResult resolve( DependencyResolutionRequest request )
throws DependencyResolutionException
{
RequestTrace trace = DefaultRequestTrace.newChild( null, request );
DefaultDependencyResolutionResult result = new DefaultDependencyResolutionResult();
MavenProject project = request.getMavenProject();
@ -113,9 +117,13 @@ public class DefaultProjectDependenciesResolver
}
}
DependencyRequest depRequest = new DependencyRequest( collect, filter );
depRequest.setTrace( trace );
DependencyNode node;
try
{
collect.setTrace( DefaultRequestTrace.newChild( trace, depRequest ) );
node = repoSystem.collectDependencies( session, collect ).getRoot();
result.setDependencyGraph( node );
}
@ -128,6 +136,8 @@ public class DefaultProjectDependenciesResolver
+ project.getId() + ": " + e.getMessage(), e );
}
depRequest.setRoot( node );
if ( logger.isWarnEnabled() )
{
for ( DependencyNode child : node.getChildren() )
@ -147,11 +157,11 @@ public class DefaultProjectDependenciesResolver
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 "
+ project.getId() + ": " + e.getMessage(), e );
@ -167,7 +177,6 @@ public class DefaultProjectDependenciesResolver
DependencyNode node = ar.getRequest().getDependencyNode();
if ( ar.isResolved() )
{
node.setArtifact( ar.getArtifact() );
result.addResolvedDependency( node.getDependency() );
}
else

View File

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