1 package org.apache.maven.extension; 2 3 18 19 import org.apache.maven.artifact.Artifact; 20 import org.apache.maven.artifact.ArtifactUtils; 21 import org.apache.maven.artifact.metadata.ArtifactMetadataSource; 22 import org.apache.maven.artifact.repository.ArtifactRepository; 23 import org.apache.maven.artifact.resolver.ArtifactNotFoundException; 24 import org.apache.maven.artifact.resolver.ArtifactResolutionException; 25 import org.apache.maven.artifact.resolver.ArtifactResolutionResult; 26 import org.apache.maven.artifact.resolver.ArtifactResolver; 27 import org.apache.maven.artifact.resolver.filter.ArtifactFilter; 28 import org.apache.maven.model.Extension; 29 import org.apache.maven.project.MavenProject; 30 import org.apache.maven.MavenArtifactFilterManager; 31 import org.codehaus.plexus.PlexusConstants; 32 import org.codehaus.plexus.PlexusContainer; 33 import org.codehaus.plexus.PlexusContainerException; 34 import org.codehaus.plexus.context.Context; 35 import org.codehaus.plexus.context.ContextException; 36 import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable; 37 38 import java.util.Collections ; 39 import java.util.Iterator ; 40 41 48 public class DefaultExtensionManager 49 implements ExtensionManager, Contextualizable 50 { 51 private ArtifactResolver artifactResolver; 52 53 private ArtifactMetadataSource artifactMetadataSource; 54 55 private PlexusContainer container; 56 57 private ArtifactFilter artifactFilter = MavenArtifactFilterManager.createStandardFilter(); 58 59 public void addExtension( Extension extension, MavenProject project, ArtifactRepository localRepository ) 60 throws ArtifactResolutionException, PlexusContainerException, ArtifactNotFoundException 61 { 62 String extensionId = ArtifactUtils.versionlessKey( extension.getGroupId(), extension.getArtifactId() ); 63 64 Artifact artifact = (Artifact) project.getExtensionArtifactMap().get( extensionId ); 65 66 if ( artifact != null ) 67 { 68 ArtifactResolutionResult result = artifactResolver.resolveTransitively( Collections.singleton( artifact ), 69 project.getArtifact(), 70 localRepository, 71 project.getRemoteArtifactRepositories(), 72 artifactMetadataSource, 73 artifactFilter ); 74 for ( Iterator i = result.getArtifacts().iterator(); i.hasNext(); ) 75 { 76 Artifact a = (Artifact) i.next(); 77 78 a = project.replaceWithActiveArtifact( a ); 79 80 container.addJarResource( a.getFile() ); 81 } 82 } 83 } 84 85 public void contextualize( Context context ) 86 throws ContextException 87 { 88 this.container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY ); 89 } 90 } 91 | Popular Tags |