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