1 package org.apache.maven.tools.plugin.util;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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 {
41 }
42
43 public static String[] findSources( String basedir, String include )
44 {
45 return PluginUtils.findSources( basedir, include, null );
46 }
47
48 public static String[] findSources( String basedir, String include, String exclude )
49 {
50 DirectoryScanner scanner = new DirectoryScanner();
51 scanner.setBasedir( basedir );
52 scanner.setIncludes( new String[]{include} );
53 if ( !StringUtils.isEmpty( exclude ) )
54 {
55
56 scanner.setExcludes( new String[]{exclude, "**/.svn/**"} );
57 }
58 else
59 {
60 scanner.setExcludes( new String[]{"**/.svn/**"} );
61 }
62
63 scanner.scan();
64
65 return scanner.getIncludedFiles();
66 }
67
68 public static void writeDependencies( XMLWriter w, PluginDescriptor pluginDescriptor )
69 {
70
71 w.startElement( "dependencies" );
72
73 for ( Iterator it = pluginDescriptor.getDependencies().iterator(); it.hasNext(); )
74 {
75 ComponentDependency dep = (ComponentDependency) it.next();
76
77 w.startElement( "dependency" );
78
79 PluginUtils.element( w, "groupId", dep.getGroupId() );
80
81 PluginUtils.element( w, "artifactId", dep.getArtifactId() );
82
83 PluginUtils.element( w, "type", dep.getType() );
84
85 PluginUtils.element( w, "version", dep.getVersion() );
86
87 w.endElement();
88 }
89
90 w.endElement();
91 }
92
93 public static List toComponentDependencies( List dependencies )
94 {
95 List componentDeps = new LinkedList();
96
97 for ( Iterator it = dependencies.iterator(); it.hasNext(); )
98 {
99 Dependency dependency = (Dependency) it.next();
100
101 ComponentDependency cd = new ComponentDependency();
102
103 cd.setArtifactId( dependency.getArtifactId() );
104 cd.setGroupId( dependency.getGroupId() );
105 cd.setVersion( dependency.getVersion() );
106 cd.setType( dependency.getType() );
107
108 componentDeps.add( cd );
109 }
110
111 return componentDeps;
112 }
113
114 private static void element( XMLWriter w, String name, String value )
115 {
116 w.startElement( name );
117
118 if ( value == null )
119 {
120 value = "";
121 }
122
123 w.writeText( value );
124
125 w.endElement();
126 }
127
128 }