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 |
|
|
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 |
|
|
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 |
|
} |