1 | |
package org.apache.maven.plugin; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
import org.apache.maven.artifact.repository.ArtifactRepository; |
23 | |
import org.apache.maven.artifact.repository.metadata.GroupRepositoryMetadata; |
24 | |
import org.apache.maven.artifact.repository.metadata.Metadata; |
25 | |
import org.apache.maven.artifact.repository.metadata.Plugin; |
26 | |
import org.apache.maven.artifact.repository.metadata.RepositoryMetadata; |
27 | |
import org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager; |
28 | |
import org.apache.maven.artifact.repository.metadata.RepositoryMetadataResolutionException; |
29 | |
import org.codehaus.plexus.logging.AbstractLogEnabled; |
30 | |
|
31 | |
import java.util.ArrayList; |
32 | |
import java.util.Collections; |
33 | |
import java.util.HashMap; |
34 | |
import java.util.Iterator; |
35 | |
import java.util.List; |
36 | |
import java.util.Map; |
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | 0 | public class DefaultPluginMappingManager |
46 | |
extends AbstractLogEnabled |
47 | |
implements PluginMappingManager |
48 | |
{ |
49 | |
protected RepositoryMetadataManager repositoryMetadataManager; |
50 | |
|
51 | 0 | private Map pluginDefinitionsByPrefix = new HashMap(); |
52 | |
|
53 | |
public org.apache.maven.model.Plugin getByPrefix( String pluginPrefix, List groupIds, List pluginRepositories, |
54 | |
ArtifactRepository localRepository ) |
55 | |
{ |
56 | |
|
57 | 0 | if ( !pluginDefinitionsByPrefix.containsKey( pluginPrefix ) ) |
58 | |
{ |
59 | 0 | getLogger().info( "Searching repository for plugin with prefix: \'" + pluginPrefix + "\'." ); |
60 | |
|
61 | 0 | loadPluginMappings( groupIds, pluginRepositories, localRepository ); |
62 | |
} |
63 | |
|
64 | 0 | return (org.apache.maven.model.Plugin) pluginDefinitionsByPrefix.get( pluginPrefix ); |
65 | |
} |
66 | |
|
67 | |
private void loadPluginMappings( List groupIds, List pluginRepositories, ArtifactRepository localRepository ) |
68 | |
{ |
69 | 0 | List pluginGroupIds = new ArrayList( groupIds ); |
70 | |
|
71 | |
|
72 | 0 | if ( !pluginGroupIds.contains( "org.apache.maven.plugins" ) ) |
73 | |
{ |
74 | 0 | pluginGroupIds.add( "org.apache.maven.plugins" ); |
75 | |
} |
76 | 0 | if ( !pluginGroupIds.contains( "org.codehaus.mojo" ) ) |
77 | |
{ |
78 | 0 | pluginGroupIds.add( "org.codehaus.mojo" ); |
79 | |
} |
80 | |
|
81 | 0 | for ( Iterator it = pluginGroupIds.iterator(); it.hasNext(); ) |
82 | |
{ |
83 | 0 | String groupId = (String) it.next(); |
84 | 0 | getLogger().debug( "Loading plugin prefixes from group: " + groupId ); |
85 | |
try |
86 | |
{ |
87 | 0 | loadPluginMappings( groupId, pluginRepositories, localRepository ); |
88 | |
} |
89 | 0 | catch ( RepositoryMetadataResolutionException e ) |
90 | |
{ |
91 | 0 | getLogger().warn( "Cannot resolve plugin-mapping metadata for groupId: " + groupId + " - IGNORING." ); |
92 | |
|
93 | 0 | getLogger().debug( "Error resolving plugin-mapping metadata for groupId: " + groupId + ".", e ); |
94 | 0 | } |
95 | 0 | } |
96 | 0 | } |
97 | |
|
98 | |
private void loadPluginMappings( String groupId, List pluginRepositories, ArtifactRepository localRepository ) |
99 | |
throws RepositoryMetadataResolutionException |
100 | |
{ |
101 | 0 | RepositoryMetadata metadata = new GroupRepositoryMetadata( groupId ); |
102 | |
|
103 | 0 | repositoryMetadataManager.resolve( metadata, pluginRepositories, localRepository ); |
104 | |
|
105 | 0 | Metadata repoMetadata = metadata.getMetadata(); |
106 | 0 | if ( repoMetadata != null ) |
107 | |
{ |
108 | 0 | for ( Iterator pluginIterator = repoMetadata.getPlugins().iterator(); pluginIterator.hasNext(); ) |
109 | |
{ |
110 | 0 | Plugin mapping = (Plugin) pluginIterator.next(); |
111 | |
|
112 | 0 | String prefix = mapping.getPrefix(); |
113 | |
|
114 | |
|
115 | |
|
116 | 0 | if ( !pluginDefinitionsByPrefix.containsKey( prefix ) ) |
117 | |
{ |
118 | 0 | String artifactId = mapping.getArtifactId(); |
119 | |
|
120 | 0 | org.apache.maven.model.Plugin plugin = new org.apache.maven.model.Plugin(); |
121 | |
|
122 | 0 | plugin.setGroupId( metadata.getGroupId() ); |
123 | |
|
124 | 0 | plugin.setArtifactId( artifactId ); |
125 | |
|
126 | 0 | pluginDefinitionsByPrefix.put( prefix, plugin ); |
127 | |
} |
128 | 0 | } |
129 | |
} |
130 | 0 | } |
131 | |
} |