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.model.Plugin; |
23 | |
import org.apache.maven.plugin.descriptor.PluginDescriptor; |
24 | |
import org.codehaus.plexus.component.discovery.ComponentDiscoveryEvent; |
25 | |
import org.codehaus.plexus.component.discovery.ComponentDiscoveryListener; |
26 | |
import org.codehaus.plexus.component.repository.ComponentSetDescriptor; |
27 | |
import org.codehaus.plexus.logging.AbstractLogEnabled; |
28 | |
|
29 | |
import java.util.HashMap; |
30 | |
import java.util.HashSet; |
31 | |
import java.util.Iterator; |
32 | |
import java.util.Map; |
33 | |
import java.util.Set; |
34 | |
|
35 | 0 | public class MavenPluginCollector |
36 | |
extends AbstractLogEnabled |
37 | |
implements ComponentDiscoveryListener |
38 | |
{ |
39 | |
|
40 | 0 | private Set pluginsInProcess = new HashSet(); |
41 | |
|
42 | 0 | private Map pluginDescriptors = new HashMap(); |
43 | |
|
44 | 0 | private Map pluginIdsByPrefix = new HashMap(); |
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
public void componentDiscovered( ComponentDiscoveryEvent event ) |
50 | |
{ |
51 | 0 | ComponentSetDescriptor componentSetDescriptor = event.getComponentSetDescriptor(); |
52 | |
|
53 | 0 | if ( componentSetDescriptor instanceof PluginDescriptor ) |
54 | |
{ |
55 | 0 | PluginDescriptor pluginDescriptor = (PluginDescriptor) componentSetDescriptor; |
56 | |
|
57 | |
|
58 | 0 | String key = Plugin.constructKey( pluginDescriptor.getGroupId(), pluginDescriptor.getArtifactId() ); |
59 | |
|
60 | 0 | if ( !pluginsInProcess.contains( key ) ) |
61 | |
{ |
62 | 0 | pluginsInProcess.add( key ); |
63 | |
|
64 | 0 | pluginDescriptors.put( key, pluginDescriptor ); |
65 | |
|
66 | |
|
67 | |
|
68 | 0 | if ( !pluginIdsByPrefix.containsKey( pluginDescriptor.getGoalPrefix() ) ) |
69 | |
{ |
70 | 0 | pluginIdsByPrefix.put( pluginDescriptor.getGoalPrefix(), pluginDescriptor ); |
71 | |
} |
72 | |
} |
73 | |
} |
74 | 0 | } |
75 | |
|
76 | |
public PluginDescriptor getPluginDescriptor( Plugin plugin ) |
77 | |
{ |
78 | |
|
79 | |
|
80 | |
|
81 | 0 | return (PluginDescriptor) pluginDescriptors.get( plugin.getKey() ); |
82 | |
} |
83 | |
|
84 | |
public boolean isPluginInstalled( Plugin plugin ) |
85 | |
{ |
86 | |
|
87 | 0 | return pluginDescriptors.containsKey( plugin.getKey() ); |
88 | |
} |
89 | |
|
90 | |
public PluginDescriptor getPluginDescriptorForPrefix( String prefix ) |
91 | |
{ |
92 | 0 | return (PluginDescriptor) pluginIdsByPrefix.get( prefix ); |
93 | |
} |
94 | |
|
95 | |
public void flushPluginDescriptor( Plugin plugin ) |
96 | |
{ |
97 | 0 | pluginsInProcess.remove( plugin.getKey() ); |
98 | 0 | pluginDescriptors.remove( plugin.getKey() ); |
99 | |
|
100 | 0 | for ( Iterator it = pluginIdsByPrefix.entrySet().iterator(); it.hasNext(); ) |
101 | |
{ |
102 | 0 | Map.Entry entry = (Map.Entry) it.next(); |
103 | |
|
104 | 0 | if ( plugin.getKey().equals( entry.getValue() ) ) |
105 | |
{ |
106 | 0 | it.remove(); |
107 | |
} |
108 | 0 | } |
109 | 0 | } |
110 | |
|
111 | |
} |