Coverage Report - org.apache.maven.tools.plugin.scanner.DefaultMojoScanner
 
Classes in this File Line Coverage Branch Coverage Complexity
DefaultMojoScanner
95% 
100% 
2.6
 
 1  
 package org.apache.maven.tools.plugin.scanner;
 2  
 
 3  
 /*
 4  
  * Licensed to the Apache Software Foundation (ASF) under one
 5  
  * or more contributor license agreements.  See the NOTICE file
 6  
  * distributed with this work for additional information
 7  
  * regarding copyright ownership.  The ASF licenses this file
 8  
  * to you under the Apache License, Version 2.0 (the
 9  
  * "License"); you may not use this file except in compliance
 10  
  * with the License.  You may obtain a copy of the License at
 11  
  *
 12  
  *   http://www.apache.org/licenses/LICENSE-2.0
 13  
  *
 14  
  * Unless required by applicable law or agreed to in writing,
 15  
  * software distributed under the License is distributed on an
 16  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 17  
  * KIND, either express or implied.  See the License for the
 18  
  * specific language governing permissions and limitations
 19  
  * under the License.
 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/* <String> */activeExtractors;
 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  
      * Gets the name of the active extractors.
 104  
      *
 105  
      * @return A Set containing the names of the active extractors.
 106  
      */
 107  
     protected Set/* <String> */getActiveExtractors()
 108  
     {
 109  5
         Set/* <String> */result = activeExtractors;
 110  
 
 111  5
         if ( result == null )
 112  
         {
 113  2
             result = new HashSet/* <String> */( mojoDescriptorExtractors.keySet() );
 114  
         }
 115  
 
 116  5
         return result;
 117  
     }
 118  
 
 119  
     /**
 120  
      * @see org.apache.maven.tools.plugin.scanner.ExtendedMojoScanner#setActiveExtractors(java.util.Set)
 121  
      */
 122  
     public void setActiveExtractors( Set/* <String> */extractors )
 123  
     {
 124  4
         if ( extractors == null )
 125  
         {
 126  1
             this.activeExtractors = null;
 127  1
         }
 128  
         else
 129  
         {
 130  3
             this.activeExtractors = new HashSet/* <String> */();
 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  
 }