KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > maven > extension > DefaultExtensionManager


1 package org.apache.maven.extension;
2
3 /*
4  * Copyright 2001-2005 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

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 JavaDoc;
39 import java.util.Iterator JavaDoc;
40
41 /**
42  * Used to locate extensions.
43  *
44  * @author <a HREF="mailto:brett@apache.org">Brett Porter</a>
45  * @author Jason van Zyl
46  * @version $Id: DefaultExtensionManager.java 368221 2006-01-12 02:04:38Z jvanzyl $
47  */

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 JavaDoc 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 JavaDoc 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