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