o Dispatched repository events via dedicated component

git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@1180679 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2011-10-09 18:22:20 +00:00
parent 6a227fdf4c
commit be54d99d17
3 changed files with 69 additions and 39 deletions

View File

@ -47,7 +47,6 @@ import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement; import org.codehaus.plexus.component.annotations.Requirement;
import org.sonatype.aether.RepositoryEvent.EventType; 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.RepositorySystemSession; import org.sonatype.aether.RepositorySystemSession;
import org.sonatype.aether.RequestTrace; import org.sonatype.aether.RequestTrace;
import org.sonatype.aether.artifact.Artifact; import org.sonatype.aether.artifact.Artifact;
@ -58,6 +57,7 @@ import org.sonatype.aether.graph.Exclusion;
import org.sonatype.aether.impl.ArtifactDescriptorReader; import org.sonatype.aether.impl.ArtifactDescriptorReader;
import org.sonatype.aether.impl.ArtifactResolver; import org.sonatype.aether.impl.ArtifactResolver;
import org.sonatype.aether.impl.RemoteRepositoryManager; import org.sonatype.aether.impl.RemoteRepositoryManager;
import org.sonatype.aether.impl.RepositoryEventDispatcher;
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.DefaultRequestTrace;
@ -101,6 +101,9 @@ public class DefaultArtifactDescriptorReader
@Requirement @Requirement
private ArtifactResolver artifactResolver; private ArtifactResolver artifactResolver;
@Requirement
private RepositoryEventDispatcher repositoryEventDispatcher;
@Requirement @Requirement
private ModelBuilder modelBuilder; private ModelBuilder modelBuilder;
@ -110,6 +113,7 @@ public class DefaultArtifactDescriptorReader
setRemoteRepositoryManager( locator.getService( RemoteRepositoryManager.class ) ); setRemoteRepositoryManager( locator.getService( RemoteRepositoryManager.class ) );
setVersionResolver( locator.getService( VersionResolver.class ) ); setVersionResolver( locator.getService( VersionResolver.class ) );
setArtifactResolver( locator.getService( ArtifactResolver.class ) ); setArtifactResolver( locator.getService( ArtifactResolver.class ) );
setRepositoryEventDispatcher( locator.getService( RepositoryEventDispatcher.class ) );
modelBuilder = locator.getService( ModelBuilder.class ); modelBuilder = locator.getService( ModelBuilder.class );
if ( modelBuilder == null ) if ( modelBuilder == null )
{ {
@ -153,6 +157,16 @@ public class DefaultArtifactDescriptorReader
return this; return this;
} }
public DefaultArtifactDescriptorReader setRepositoryEventDispatcher( RepositoryEventDispatcher repositoryEventDispatcher )
{
if ( repositoryEventDispatcher == null )
{
throw new IllegalArgumentException( "repository event dispatcher has not been specified" );
}
this.repositoryEventDispatcher = repositoryEventDispatcher;
return this;
}
public DefaultArtifactDescriptorReader setModelBuilder( ModelBuilder modelBuilder ) public DefaultArtifactDescriptorReader setModelBuilder( ModelBuilder modelBuilder )
{ {
if ( modelBuilder == null ) if ( modelBuilder == null )
@ -407,29 +421,23 @@ public class DefaultArtifactDescriptorReader
private void missingDescriptor( RepositorySystemSession session, RequestTrace trace, Artifact artifact, private void missingDescriptor( RepositorySystemSession session, RequestTrace trace, Artifact artifact,
Exception exception ) Exception exception )
{ {
RepositoryListener listener = session.getRepositoryListener(); DefaultRepositoryEvent event =
if ( listener != null ) new DefaultRepositoryEvent( EventType.ARTIFACT_DESCRIPTOR_MISSING, session, trace );
{ event.setArtifact( artifact );
DefaultRepositoryEvent event = event.setException( exception );
new DefaultRepositoryEvent( EventType.ARTIFACT_DESCRIPTOR_MISSING, session, trace );
event.setArtifact( artifact ); repositoryEventDispatcher.dispatch( event );
event.setException( exception );
listener.artifactDescriptorMissing( event );
}
} }
private void invalidDescriptor( RepositorySystemSession session, RequestTrace trace, Artifact artifact, private void invalidDescriptor( RepositorySystemSession session, RequestTrace trace, Artifact artifact,
Exception exception ) Exception exception )
{ {
RepositoryListener listener = session.getRepositoryListener(); DefaultRepositoryEvent event =
if ( listener != null ) new DefaultRepositoryEvent( EventType.ARTIFACT_DESCRIPTOR_INVALID, session, trace );
{ event.setArtifact( artifact );
DefaultRepositoryEvent event = event.setException( exception );
new DefaultRepositoryEvent( EventType.ARTIFACT_DESCRIPTOR_INVALID, session, trace );
event.setArtifact( artifact ); repositoryEventDispatcher.dispatch( event );
event.setException( exception );
listener.artifactDescriptorInvalid( event );
}
} }
} }

View File

@ -32,7 +32,6 @@ import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement; import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.util.IOUtil; 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.RepositorySystemSession; import org.sonatype.aether.RepositorySystemSession;
import org.sonatype.aether.RequestTrace; import org.sonatype.aether.RequestTrace;
import org.sonatype.aether.SyncContext; import org.sonatype.aether.SyncContext;
@ -45,6 +44,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.RepositoryEventDispatcher;
import org.sonatype.aether.impl.SyncContextFactory; 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;
@ -81,11 +81,15 @@ public class DefaultVersionRangeResolver
@Requirement @Requirement
private SyncContextFactory syncContextFactory; private SyncContextFactory syncContextFactory;
@Requirement
private RepositoryEventDispatcher repositoryEventDispatcher;
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 ) ); setSyncContextFactory( locator.getService( SyncContextFactory.class ) );
setRepositoryEventDispatcher( locator.getService( RepositoryEventDispatcher.class ) );
} }
public DefaultVersionRangeResolver setLogger( Logger logger ) public DefaultVersionRangeResolver setLogger( Logger logger )
@ -114,6 +118,16 @@ public class DefaultVersionRangeResolver
return this; return this;
} }
public DefaultVersionRangeResolver setRepositoryEventDispatcher( RepositoryEventDispatcher repositoryEventDispatcher )
{
if ( repositoryEventDispatcher == null )
{
throw new IllegalArgumentException( "repository event dispatcher has not been specified" );
}
this.repositoryEventDispatcher = repositoryEventDispatcher;
return this;
}
public VersionRangeResult resolveVersionRange( RepositorySystemSession session, VersionRangeRequest request ) public VersionRangeResult resolveVersionRange( RepositorySystemSession session, VersionRangeRequest request )
throws VersionRangeResolutionException throws VersionRangeResolutionException
{ {
@ -271,15 +285,12 @@ public class DefaultVersionRangeResolver
private void invalidMetadata( RepositorySystemSession session, RequestTrace trace, Metadata metadata, private void invalidMetadata( RepositorySystemSession session, RequestTrace trace, Metadata metadata,
ArtifactRepository repository, Exception exception ) ArtifactRepository repository, Exception exception )
{ {
RepositoryListener listener = session.getRepositoryListener(); DefaultRepositoryEvent event = new DefaultRepositoryEvent( EventType.METADATA_INVALID, session, trace );
if ( listener != null ) event.setMetadata( metadata );
{ event.setException( exception );
DefaultRepositoryEvent event = new DefaultRepositoryEvent( EventType.METADATA_INVALID, session, trace ); event.setRepository( repository );
event.setMetadata( metadata );
event.setException( exception ); repositoryEventDispatcher.dispatch( event );
event.setRepository( repository );
listener.metadataInvalid( event );
}
} }
} }

View File

@ -40,7 +40,6 @@ import org.sonatype.aether.ConfigurationProperties;
import org.sonatype.aether.RepositoryCache; import org.sonatype.aether.RepositoryCache;
import org.sonatype.aether.RequestTrace; 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.RepositorySystemSession; import org.sonatype.aether.RepositorySystemSession;
import org.sonatype.aether.SyncContext; import org.sonatype.aether.SyncContext;
import org.sonatype.aether.util.DefaultRequestTrace; import org.sonatype.aether.util.DefaultRequestTrace;
@ -48,6 +47,7 @@ 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.RepositoryEventDispatcher;
import org.sonatype.aether.impl.SyncContextFactory; 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;
@ -93,11 +93,15 @@ public class DefaultVersionResolver
@Requirement @Requirement
private SyncContextFactory syncContextFactory; private SyncContextFactory syncContextFactory;
@Requirement
private RepositoryEventDispatcher repositoryEventDispatcher;
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 ) ); setSyncContextFactory( locator.getService( SyncContextFactory.class ) );
setRepositoryEventDispatcher( locator.getService( RepositoryEventDispatcher.class ) );
} }
public DefaultVersionResolver setLogger( Logger logger ) public DefaultVersionResolver setLogger( Logger logger )
@ -126,6 +130,16 @@ public class DefaultVersionResolver
return this; return this;
} }
public DefaultVersionResolver setRepositoryEventDispatcher( RepositoryEventDispatcher repositoryEventDispatcher )
{
if ( repositoryEventDispatcher == null )
{
throw new IllegalArgumentException( "repository event dispatcher has not been specified" );
}
this.repositoryEventDispatcher = repositoryEventDispatcher;
return this;
}
public VersionResult resolveVersion( RepositorySystemSession session, VersionRequest request ) public VersionResult resolveVersion( RepositorySystemSession session, VersionRequest request )
throws VersionResolutionException throws VersionResolutionException
{ {
@ -361,15 +375,12 @@ public class DefaultVersionResolver
private void invalidMetadata( RepositorySystemSession session, RequestTrace trace, Metadata metadata, private void invalidMetadata( RepositorySystemSession session, RequestTrace trace, Metadata metadata,
ArtifactRepository repository, Exception exception ) ArtifactRepository repository, Exception exception )
{ {
RepositoryListener listener = session.getRepositoryListener(); DefaultRepositoryEvent event = new DefaultRepositoryEvent( EventType.METADATA_INVALID, session, trace );
if ( listener != null ) event.setMetadata( metadata );
{ event.setException( exception );
DefaultRepositoryEvent event = new DefaultRepositoryEvent( EventType.METADATA_INVALID, session, trace ); event.setRepository( repository );
event.setMetadata( metadata );
event.setException( exception ); repositoryEventDispatcher.dispatch( event );
event.setRepository( repository );
listener.metadataInvalid( event );
}
} }
private void merge( Artifact artifact, Map<String, VersionInfo> infos, Versioning versioning, private void merge( Artifact artifact, Map<String, VersionInfo> infos, Versioning versioning,