Coverage Report - org.apache.maven.tools.plugin.util.PluginUtils
 
Classes in this File Line Coverage Branch Coverage Complexity
PluginUtils
66% 
75% 
1.667
 
 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 org.apache.maven.model.Dependency;
 23  
 import org.apache.maven.plugin.descriptor.PluginDescriptor;
 24  
 import org.codehaus.plexus.component.repository.ComponentDependency;
 25  
 import org.codehaus.plexus.util.DirectoryScanner;
 26  
 import org.codehaus.plexus.util.StringUtils;
 27  
 import org.codehaus.plexus.util.xml.XMLWriter;
 28  
 
 29  
 import java.util.Iterator;
 30  
 import java.util.LinkedList;
 31  
 import java.util.List;
 32  
 
 33  
 /**
 34  
  * @author jdcasey
 35  
  */
 36  
 public final class PluginUtils
 37  
 {
 38  
 
 39  
     private PluginUtils()
 40  0
     {
 41  0
     }
 42  
 
 43  
     public static String[] findSources( String basedir, String include )
 44  
     {
 45  1
         return PluginUtils.findSources( basedir, include, null );
 46  
     }
 47  
 
 48  
     public static String[] findSources( String basedir, String include, String exclude )
 49  
     {
 50  2
         DirectoryScanner scanner = new DirectoryScanner();
 51  2
         scanner.setBasedir( basedir );
 52  2
         scanner.setIncludes( new String[]{include} );
 53  2
         if ( !StringUtils.isEmpty( exclude ) )
 54  
         {
 55  
             // TODO: need default excludes in scanner
 56  1
             scanner.setExcludes( new String[]{exclude, "**/.svn/**"} );
 57  1
         }
 58  
         else
 59  
         {
 60  1
             scanner.setExcludes( new String[]{"**/.svn/**"} );
 61  
         }
 62  
 
 63  2
         scanner.scan();
 64  
 
 65  2
         return scanner.getIncludedFiles();
 66  
     }
 67  
 
 68  
     public static void writeDependencies( XMLWriter w, PluginDescriptor pluginDescriptor )
 69  
     {
 70  
 
 71  2
         w.startElement( "dependencies" );
 72  
 
 73  2
         for ( Iterator it = pluginDescriptor.getDependencies().iterator(); it.hasNext(); )
 74  
         {
 75  2
             ComponentDependency dep = (ComponentDependency) it.next();
 76  
 
 77  2
             w.startElement( "dependency" );
 78  
 
 79  2
             PluginUtils.element( w, "groupId", dep.getGroupId() );
 80  
 
 81  2
             PluginUtils.element( w, "artifactId", dep.getArtifactId() );
 82  
 
 83  2
             PluginUtils.element( w, "type", dep.getType() );
 84  
 
 85  2
             PluginUtils.element( w, "version", dep.getVersion() );
 86  
 
 87  2
             w.endElement();
 88  2
         }
 89  
 
 90  2
         w.endElement();
 91  2
     }
 92  
 
 93  
     public static List toComponentDependencies( List dependencies )
 94  
     {
 95  0
         List componentDeps = new LinkedList();
 96  
 
 97  0
         for ( Iterator it = dependencies.iterator(); it.hasNext(); )
 98  
         {
 99  0
             Dependency dependency = (Dependency) it.next();
 100  
 
 101  0
             ComponentDependency cd = new ComponentDependency();
 102  
 
 103  0
             cd.setArtifactId( dependency.getArtifactId() );
 104  0
             cd.setGroupId( dependency.getGroupId() );
 105  0
             cd.setVersion( dependency.getVersion() );
 106  0
             cd.setType( dependency.getType() );
 107  
 
 108  0
             componentDeps.add( cd );
 109  0
         }
 110  
 
 111  0
         return componentDeps;
 112  
     }
 113  
 
 114  
     private static void element( XMLWriter w, String name, String value )
 115  
     {
 116  8
         w.startElement( name );
 117  
 
 118  8
         if ( value == null )
 119  
         {
 120  0
             value = "";
 121  
         }
 122  
 
 123  8
         w.writeText( value );
 124  
 
 125  8
         w.endElement();
 126  8
     }
 127  
 
 128  
 }