KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > maven > tools > plugin > scanner > DefaultMojoScanner


1 package org.apache.maven.tools.plugin.scanner;
2
3 /*
4  * Copyright 2001-2004 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

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 JavaDoc;
30 import java.util.List JavaDoc;
31 import java.util.Map JavaDoc;
32
33 /**
34  * @author jdcasey
35  */

36 public class DefaultMojoScanner
37     extends AbstractLogEnabled
38     implements MojoScanner
39 {
40
41     private Map JavaDoc mojoDescriptorExtractors;
42
43     public DefaultMojoScanner( Map JavaDoc 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 JavaDoc it = mojoDescriptorExtractors.entrySet().iterator(); it.hasNext(); )
62         {
63             Map.Entry JavaDoc entry = (Map.Entry JavaDoc) it.next();
64             String JavaDoc language = (String JavaDoc) entry.getKey();
65             MojoDescriptorExtractor extractor = (MojoDescriptorExtractor) entry.getValue();
66
67             logger.info( "Applying extractor for language: " + language );
68
69             List JavaDoc extractorDescriptors = extractor.execute( project, pluginDescriptor );
70
71             logger.info( "Extractor for language: " + language + " found " + extractorDescriptors.size()
72                 + " mojo descriptors." );
73
74             for ( Iterator JavaDoc 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