Coverage Report - org.apache.maven.tools.plugin.util.PluginUtils
 
Classes in this File Line Coverage Branch Coverage Complexity
PluginUtils
68 %
17/25
33 %
2/6
1,429
PluginUtils$1
0 %
0/2
N/A
1,429
PluginUtils$2
0 %
0/2
N/A
1,429
 
 1  
 package org.apache.maven.tools.plugin.util;
 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 java.util.Collections;
 23  
 import java.util.Comparator;
 24  
 import java.util.HashMap;
 25  
 import java.util.List;
 26  
 import java.util.Map;
 27  
 
 28  
 import org.apache.maven.plugin.descriptor.MojoDescriptor;
 29  
 import org.apache.maven.plugin.descriptor.Parameter;
 30  
 import org.codehaus.plexus.util.DirectoryScanner;
 31  
 import org.codehaus.plexus.util.FileUtils;
 32  
 import org.codehaus.plexus.util.StringUtils;
 33  
 
 34  
 /**
 35  
  * Convenience methods to play with Maven plugins.
 36  
  *
 37  
  * @author jdcasey
 38  
  * @version $Id: PluginUtils.java 1343086 2012-05-27 20:21:15Z hboutemy $
 39  
  */
 40  
 public final class PluginUtils
 41  
 {
 42  
     private PluginUtils()
 43  0
     {
 44  
         // nop
 45  0
     }
 46  
 
 47  
     /**
 48  
      * Expression associated with class types to recognize Maven objects as components.
 49  
      */
 50  
     public static final Map<String, String> MAVEN_COMPONENTS;
 51  
     static
 52  
     {
 53  1
         Map<String, String> mavenComponents = new HashMap<String, String>();
 54  
 
 55  1
         mavenComponents.put( "org.apache.maven.execution.MavenSession", "${session}" );
 56  1
         mavenComponents.put( "org.apache.maven.project.MavenProject", "${project}" );
 57  1
         mavenComponents.put( "org.apache.maven.plugin.MojoExecution", "${mojo}" );
 58  1
         mavenComponents.put( "org.apache.maven.plugin.descriptor.PluginDescriptor", "${plugin}" );
 59  1
         mavenComponents.put( "org.apache.maven.settings.Settings", "${settings}" );
 60  
         
 61  1
         MAVEN_COMPONENTS = Collections.unmodifiableMap( mavenComponents );
 62  1
     }
 63  
 
 64  
     /**
 65  
      * @param basedir not null
 66  
      * @param include not null
 67  
      * @return list of included files with default SCM excluded files
 68  
      */
 69  
     public static String[] findSources( String basedir, String include )
 70  
     {
 71  1
         return PluginUtils.findSources( basedir, include, null );
 72  
     }
 73  
 
 74  
     /**
 75  
      * @param basedir not null
 76  
      * @param include not null
 77  
      * @param exclude could be null
 78  
      * @return list of included files
 79  
      */
 80  
     public static String[] findSources( String basedir, String include, String exclude )
 81  
     {
 82  2
         DirectoryScanner scanner = new DirectoryScanner();
 83  2
         scanner.setBasedir( basedir );
 84  2
         scanner.setIncludes( new String[] { include } );
 85  2
         if ( !StringUtils.isEmpty( exclude ) )
 86  
         {
 87  1
             scanner.setExcludes( new String[] { exclude, StringUtils.join( FileUtils.getDefaultExcludes(), "," ) } );
 88  
         }
 89  
         else
 90  
         {
 91  1
             scanner.setExcludes( FileUtils.getDefaultExcludes() );
 92  
         }
 93  
 
 94  2
         scanner.scan();
 95  
 
 96  2
         return scanner.getIncludedFiles();
 97  
     }
 98  
 
 99  
     /**
 100  
      * Sorts the specified mojo descriptors by goal name.
 101  
      *
 102  
      * @param mojoDescriptors The mojo descriptors to sort, may be <code>null</code>.
 103  
      * @see MojoDescriptor#getGoal()
 104  
      */
 105  
     public static void sortMojos( List<MojoDescriptor> mojoDescriptors )
 106  
     {
 107  0
         if ( mojoDescriptors != null )
 108  
         {
 109  0
             Collections.sort( mojoDescriptors, new Comparator<MojoDescriptor>()
 110  0
             {
 111  
                 /** {@inheritDoc} */
 112  
                 public int compare( MojoDescriptor mojo0, MojoDescriptor mojo1 )
 113  
                 {
 114  0
                     return mojo0.getGoal().compareToIgnoreCase( mojo1.getGoal() );
 115  
                 }
 116  
             } );
 117  
         }
 118  0
     }
 119  
 
 120  
     /**
 121  
      * Sorts the specified mojo parameters by name.
 122  
      *
 123  
      * @param parameters The mojo parameters to sort, may be <code>null</code>.
 124  
      * @see Parameter#getName()
 125  
      * @since 2.4.4
 126  
      */
 127  
     public static void sortMojoParameters( List<Parameter> parameters )
 128  
     {
 129  0
         if ( parameters != null )
 130  
         {
 131  0
             Collections.sort( parameters, new Comparator<Parameter>()
 132  0
             {
 133  
                 /** {@inheritDoc} */
 134  
                 public int compare( Parameter parameter1, Parameter parameter2 )
 135  
                 {
 136  0
                     return parameter1.getName().compareToIgnoreCase( parameter2.getName() );
 137  
                 }
 138  
             } );
 139  
         }
 140  0
     }
 141  
 }