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 |
|
|
40 |
|
|
41 |
|
public class DefaultMojoScanner |
42 |
|
extends AbstractLogEnabled |
43 |
|
implements MojoScanner |
44 |
|
{ |
45 |
|
|
46 |
|
private Map mojoDescriptorExtractors; |
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
private SetactiveExtractors; |
52 |
|
|
53 |
|
public DefaultMojoScanner( Map extractors ) |
54 |
5 |
{ |
55 |
5 |
this.mojoDescriptorExtractors = extractors; |
56 |
|
|
57 |
5 |
this.enableLogging( new ConsoleLogger( Logger.LEVEL_INFO, "standalone-scanner-logger" ) ); |
58 |
5 |
} |
59 |
|
|
60 |
|
public DefaultMojoScanner() |
61 |
0 |
{ |
62 |
0 |
} |
63 |
|
|
64 |
|
public void populatePluginDescriptor( MavenProject project, PluginDescriptor pluginDescriptor ) |
65 |
|
throws ExtractionException, InvalidPluginDescriptorException |
66 |
|
{ |
67 |
5 |
Logger logger = getLogger(); |
68 |
5 |
Set activeExtractors = getActiveExtractors(); |
69 |
|
|
70 |
5 |
logger.info( "Using " + activeExtractors.size() + " extractors." ); |
71 |
|
|
72 |
5 |
for ( Iterator it = activeExtractors.iterator(); it.hasNext(); ) |
73 |
|
{ |
74 |
9 |
String language = (String) it.next(); |
75 |
9 |
MojoDescriptorExtractor extractor = (MojoDescriptorExtractor) mojoDescriptorExtractors.get( language ); |
76 |
|
|
77 |
9 |
if ( extractor == null ) |
78 |
|
{ |
79 |
1 |
throw new ExtractionException( "No extractor for language: " + language ); |
80 |
|
} |
81 |
|
|
82 |
8 |
logger.info( "Applying extractor for language: " + language ); |
83 |
|
|
84 |
8 |
List extractorDescriptors = extractor.execute( project, pluginDescriptor ); |
85 |
|
|
86 |
8 |
logger.info( "Extractor for language: " + language + " found " + extractorDescriptors.size() + |
87 |
|
" mojo descriptors." ); |
88 |
|
|
89 |
8 |
for ( Iterator descriptorIt = extractorDescriptors.iterator(); descriptorIt.hasNext(); ) |
90 |
|
{ |
91 |
8 |
MojoDescriptor descriptor = (MojoDescriptor) descriptorIt.next(); |
92 |
|
|
93 |
8 |
logger.debug( "Adding mojo: " + descriptor + " to plugin descriptor." ); |
94 |
|
|
95 |
8 |
descriptor.setPluginDescriptor( pluginDescriptor ); |
96 |
|
|
97 |
8 |
pluginDescriptor.addMojo( descriptor ); |
98 |
8 |
} |
99 |
8 |
} |
100 |
4 |
} |
101 |
|
|
102 |
|
|
103 |
|
|
104 |
|
|
105 |
|
|
106 |
|
|
107 |
|
protected SetgetActiveExtractors() |
108 |
|
{ |
109 |
5 |
Setresult = activeExtractors; |
110 |
|
|
111 |
5 |
if ( result == null ) |
112 |
|
{ |
113 |
2 |
result = new HashSet( mojoDescriptorExtractors.keySet() ); |
114 |
|
} |
115 |
|
|
116 |
5 |
return result; |
117 |
|
} |
118 |
|
|
119 |
|
|
120 |
|
|
121 |
|
|
122 |
|
public void setActiveExtractors( Setextractors ) |
123 |
|
{ |
124 |
4 |
if ( extractors == null ) |
125 |
|
{ |
126 |
1 |
this.activeExtractors = null; |
127 |
1 |
} |
128 |
|
else |
129 |
|
{ |
130 |
3 |
this.activeExtractors = new HashSet(); |
131 |
|
|
132 |
3 |
for ( Iterator i = extractors.iterator(); i.hasNext(); ) |
133 |
|
{ |
134 |
5 |
String extractor = (String) i.next(); |
135 |
|
|
136 |
5 |
if ( extractor != null && extractor.length() > 0 ) |
137 |
|
{ |
138 |
3 |
this.activeExtractors.add( extractor ); |
139 |
|
} |
140 |
5 |
} |
141 |
|
} |
142 |
4 |
} |
143 |
|
} |