1 package org.apache.maven.tools.plugin.scanner;
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.plugin.descriptor.InvalidPluginDescriptorException;
23 import org.apache.maven.plugin.descriptor.MojoDescriptor;
24 import org.apache.maven.plugin.descriptor.PluginDescriptor;
25 import org.apache.maven.project.MavenProject;
26 import org.apache.maven.tools.plugin.extractor.ExtractionException;
27 import org.apache.maven.tools.plugin.extractor.MojoDescriptorExtractor;
28 import org.codehaus.plexus.logging.AbstractLogEnabled;
29 import org.codehaus.plexus.logging.Logger;
30 import org.codehaus.plexus.logging.console.ConsoleLogger;
31
32 import java.util.HashSet;
33 import java.util.Iterator;
34 import java.util.List;
35 import java.util.Map;
36 import java.util.Set;
37
38 /**
39 * @author jdcasey
40 */
41 public class DefaultMojoScanner
42 extends AbstractLogEnabled
43 implements MojoScanner
44 {
45
46 private Map mojoDescriptorExtractors;
47
48 /**
49 * The names of the active extractors
50 */
51 private Set
52
53 public DefaultMojoScanner( Map extractors )
54 {
55 this.mojoDescriptorExtractors = extractors;
56
57 this.enableLogging( new ConsoleLogger( Logger.LEVEL_INFO, "standalone-scanner-logger" ) );
58 }
59
60 public DefaultMojoScanner()
61 {
62 }
63
64 public void populatePluginDescriptor( MavenProject project, PluginDescriptor pluginDescriptor )
65 throws ExtractionException, InvalidPluginDescriptorException
66 {
67 Logger logger = getLogger();
68 Set activeExtractors = getActiveExtractors();
69
70 logger.info( "Using " + activeExtractors.size() + " extractors." );
71
72 for ( Iterator it = activeExtractors.iterator(); it.hasNext(); )
73 {
74 String language = (String) it.next();
75 MojoDescriptorExtractor extractor = (MojoDescriptorExtractor) mojoDescriptorExtractors.get( language );
76
77 if ( extractor == null )
78 {
79 throw new ExtractionException( "No extractor for language: " + language );
80 }
81
82 logger.info( "Applying extractor for language: " + language );
83
84 List extractorDescriptors = extractor.execute( project, pluginDescriptor );
85
86 logger.info( "Extractor for language: " + language + " found " + extractorDescriptors.size() +
87 " mojo descriptors." );
88
89 for ( Iterator descriptorIt = extractorDescriptors.iterator(); descriptorIt.hasNext(); )
90 {
91 MojoDescriptor descriptor = (MojoDescriptor) descriptorIt.next();
92
93 logger.debug( "Adding mojo: " + descriptor + " to plugin descriptor." );
94
95 descriptor.setPluginDescriptor( pluginDescriptor );
96
97 pluginDescriptor.addMojo( descriptor );
98 }
99 }
100 }
101
102 /**
103 * Gets the name of the active extractors.
104 *
105 * @return A Set containing the names of the active extractors.
106 */
107 protected Set
108 {
109 Set
110
111 if ( result == null )
112 {
113 result = new HashSet
114 }
115
116 return result;
117 }
118
119 /**
120 * @see org.apache.maven.tools.plugin.scanner.ExtendedMojoScanner#setActiveExtractors(java.util.Set)
121 */
122 public void setActiveExtractors( Set
123 {
124 if ( extractors == null )
125 {
126 this.activeExtractors = null;
127 }
128 else
129 {
130 this.activeExtractors = new HashSet
131
132 for ( Iterator i = extractors.iterator(); i.hasNext(); )
133 {
134 String extractor = (String) i.next();
135
136 if ( extractor != null && extractor.length() > 0 )
137 {
138 this.activeExtractors.add( extractor );
139 }
140 }
141 }
142 }
143 }