1 package org.apache.maven.tools.plugin.scanner; 2 3 18 19 import org.apache.maven.plugin.descriptor.InvalidPluginDescriptorException; 20 import org.apache.maven.plugin.descriptor.MojoDescriptor; 21 import org.apache.maven.plugin.descriptor.PluginDescriptor; 22 import org.apache.maven.project.MavenProject; 23 import org.apache.maven.tools.plugin.extractor.ExtractionException; 24 import org.apache.maven.tools.plugin.extractor.MojoDescriptorExtractor; 25 import org.codehaus.plexus.logging.AbstractLogEnabled; 26 import org.codehaus.plexus.logging.Logger; 27 import org.codehaus.plexus.logging.console.ConsoleLogger; 28 29 import java.util.Iterator ; 30 import java.util.List ; 31 import java.util.Map ; 32 33 36 public class DefaultMojoScanner 37 extends AbstractLogEnabled 38 implements MojoScanner 39 { 40 41 private Map mojoDescriptorExtractors; 42 43 public DefaultMojoScanner( Map extractors ) 44 { 45 this.mojoDescriptorExtractors = extractors; 46 47 this.enableLogging( new ConsoleLogger( Logger.LEVEL_INFO, "standalone-scanner-logger" ) ); 48 } 49 50 public DefaultMojoScanner() 51 { 52 } 53 54 public void populatePluginDescriptor( MavenProject project, PluginDescriptor pluginDescriptor ) 55 throws ExtractionException, InvalidPluginDescriptorException 56 { 57 Logger logger = getLogger(); 58 59 logger.info( "Using " + mojoDescriptorExtractors.size() + " extractors." ); 60 61 for ( Iterator it = mojoDescriptorExtractors.entrySet().iterator(); it.hasNext(); ) 62 { 63 Map.Entry entry = (Map.Entry ) it.next(); 64 String language = (String ) entry.getKey(); 65 MojoDescriptorExtractor extractor = (MojoDescriptorExtractor) entry.getValue(); 66 67 logger.info( "Applying extractor for language: " + language ); 68 69 List extractorDescriptors = extractor.execute( project, pluginDescriptor ); 70 71 logger.info( "Extractor for language: " + language + " found " + extractorDescriptors.size() 72 + " mojo descriptors." ); 73 74 for ( Iterator descriptorIt = extractorDescriptors.iterator(); descriptorIt.hasNext(); ) 75 { 76 MojoDescriptor descriptor = (MojoDescriptor) descriptorIt.next(); 77 78 logger.debug( "Adding mojo: " + descriptor + " to plugin descriptor." ); 79 80 descriptor.setPluginDescriptor( pluginDescriptor ); 81 82 pluginDescriptor.addMojo( descriptor ); 83 } 84 } 85 } 86 87 } | Popular Tags |