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