[MNG-4398] Provide an extension point to track artifact additions to the local repository

o Applied patch from Igor Fedorenko to actually associate events with the originating local repo

git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@829805 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2009-10-26 14:03:49 +00:00
parent 777bae36e8
commit 6e7ef4a045
5 changed files with 33 additions and 15 deletions

View File

@ -97,7 +97,7 @@ public class DefaultArtifactInstaller
if ( localRepositoryMaintainer != null ) if ( localRepositoryMaintainer != null )
{ {
LocalRepositoryMaintainerEvent event = LocalRepositoryMaintainerEvent event =
new DefaultLocalRepositoryMaintainerEvent( artifact, destination ); new DefaultLocalRepositoryMaintainerEvent( localRepository, artifact, destination );
localRepositoryMaintainer.artifactInstalled( event ); localRepositoryMaintainer.artifactInstalled( event );
} }
} }

View File

@ -38,6 +38,9 @@ import org.apache.maven.artifact.repository.metadata.Snapshot;
import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata; import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata;
import org.apache.maven.artifact.repository.metadata.Versioning; import org.apache.maven.artifact.repository.metadata.Versioning;
import org.apache.maven.artifact.resolver.filter.ArtifactFilter; import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
import org.apache.maven.repository.DefaultLocalRepositoryMaintainerEvent;
import org.apache.maven.repository.LocalRepositoryMaintainer;
import org.apache.maven.repository.LocalRepositoryMaintainerEvent;
import org.apache.maven.repository.legacy.TransferListenerAdapter; import org.apache.maven.repository.legacy.TransferListenerAdapter;
import org.apache.maven.repository.legacy.WagonManager; import org.apache.maven.repository.legacy.WagonManager;
import org.apache.maven.repository.legacy.metadata.ArtifactMetadata; import org.apache.maven.repository.legacy.metadata.ArtifactMetadata;
@ -86,6 +89,9 @@ public class DefaultArtifactResolver
@Requirement @Requirement
private PlexusContainer container; private PlexusContainer container;
@Requirement( optional = true )
private LocalRepositoryMaintainer localRepositoryMaintainer;
public void resolve( Artifact artifact, List<ArtifactRepository> remoteRepositories, ArtifactRepository localRepository, TransferListener resolutionListener ) public void resolve( Artifact artifact, List<ArtifactRepository> remoteRepositories, ArtifactRepository localRepository, TransferListener resolutionListener )
throws ArtifactResolutionException, ArtifactNotFoundException throws ArtifactResolutionException, ArtifactNotFoundException
{ {
@ -176,6 +182,14 @@ public class DefaultArtifactResolver
{ {
wagonManager.getArtifact( artifact, remoteRepositories, downloadMonitor, request.isForceUpdate() ); wagonManager.getArtifact( artifact, remoteRepositories, downloadMonitor, request.isForceUpdate() );
} }
if ( localRepositoryMaintainer != null )
{
LocalRepositoryMaintainerEvent event =
new DefaultLocalRepositoryMaintainerEvent( localRepository, artifact, null );
localRepositoryMaintainer.artifactDownloaded( event );
}
} }
catch ( ResourceDoesNotExistException e ) catch ( ResourceDoesNotExistException e )
{ {

View File

@ -22,6 +22,7 @@ package org.apache.maven.repository;
import java.io.File; import java.io.File;
import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository;
/** /**
* Describes an event to be consumed by {@link LocalRepositoryMaintainer}. * Describes an event to be consumed by {@link LocalRepositoryMaintainer}.
@ -31,17 +32,24 @@ import org.apache.maven.artifact.Artifact;
public class DefaultLocalRepositoryMaintainerEvent public class DefaultLocalRepositoryMaintainerEvent
implements LocalRepositoryMaintainerEvent implements LocalRepositoryMaintainerEvent
{ {
private ArtifactRepository localRepository;
private Artifact artifact; private Artifact artifact;
private File file; private File file;
public DefaultLocalRepositoryMaintainerEvent( Artifact artifact, File file ) public DefaultLocalRepositoryMaintainerEvent( ArtifactRepository localRepository, Artifact artifact, File file )
{ {
this.localRepository = localRepository;
this.artifact = artifact; this.artifact = artifact;
this.file = ( file != null ) ? file : artifact.getFile(); this.file = ( file != null ) ? file : artifact.getFile();
} }
public ArtifactRepository getLocalRepository()
{
return localRepository;
}
public String getGroupId() public String getGroupId()
{ {
return artifact.getGroupId(); return artifact.getGroupId();

View File

@ -21,6 +21,8 @@ package org.apache.maven.repository;
import java.io.File; import java.io.File;
import org.apache.maven.artifact.repository.ArtifactRepository;
/** /**
* Describes an event to be consumed by {@link LocalRepositoryMaintainer}. * Describes an event to be consumed by {@link LocalRepositoryMaintainer}.
* *
@ -29,6 +31,13 @@ import java.io.File;
public interface LocalRepositoryMaintainerEvent public interface LocalRepositoryMaintainerEvent
{ {
/**
* The local ArtifactRepository instance that generated the event.
*
* @return Source artifact repository, never {@code null}.
*/
ArtifactRepository getLocalRepository();
/** /**
* The group id of the artifact. * The group id of the artifact.
* *

View File

@ -30,9 +30,6 @@ import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.metadata.ArtifactMetadata; import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy; import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
import org.apache.maven.repository.DefaultLocalRepositoryMaintainerEvent;
import org.apache.maven.repository.LocalRepositoryMaintainer;
import org.apache.maven.repository.LocalRepositoryMaintainerEvent;
import org.apache.maven.wagon.ConnectionException; import org.apache.maven.wagon.ConnectionException;
import org.apache.maven.wagon.ResourceDoesNotExistException; import org.apache.maven.wagon.ResourceDoesNotExistException;
import org.apache.maven.wagon.TransferFailedException; import org.apache.maven.wagon.TransferFailedException;
@ -76,9 +73,6 @@ public class DefaultWagonManager
@Requirement @Requirement
private UpdateCheckManager updateCheckManager; private UpdateCheckManager updateCheckManager;
@Requirement( optional = true )
private LocalRepositoryMaintainer localRepositoryMaintainer;
// //
// Retriever // Retriever
// //
@ -105,13 +99,6 @@ public class DefaultWagonManager
{ {
getRemoteFile( repository, artifact.getFile(), remotePath, downloadMonitor, getRemoteFile( repository, artifact.getFile(), remotePath, downloadMonitor,
policy.getChecksumPolicy(), false ); policy.getChecksumPolicy(), false );
if ( localRepositoryMaintainer != null )
{
LocalRepositoryMaintainerEvent event =
new DefaultLocalRepositoryMaintainerEvent( artifact, null );
localRepositoryMaintainer.artifactDownloaded( event );
}
} }
finally finally
{ {