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 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 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
public final class PluginUtils |
41 | |
{ |
42 | |
private PluginUtils() |
43 | 0 | { |
44 | |
|
45 | 0 | } |
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
public static final Map<String, String> MAVEN_COMPONENTS; |
54 | |
static |
55 | |
{ |
56 | 1 | Map<String, String> mavenComponents = new HashMap<String, String>(); |
57 | |
|
58 | 1 | mavenComponents.put( "org.apache.maven.execution.MavenSession", "${session}" ); |
59 | 1 | mavenComponents.put( "org.apache.maven.project.MavenProject", "${project}" ); |
60 | 1 | mavenComponents.put( "org.apache.maven.plugin.MojoExecution", "${mojo}" ); |
61 | 1 | mavenComponents.put( "org.apache.maven.plugin.descriptor.PluginDescriptor", "${plugin}" ); |
62 | 1 | mavenComponents.put( "org.apache.maven.settings.Settings", "${settings}" ); |
63 | |
|
64 | 1 | MAVEN_COMPONENTS = Collections.unmodifiableMap( mavenComponents ); |
65 | 1 | } |
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
public static String[] findSources( String basedir, String include ) |
73 | |
{ |
74 | 1 | return PluginUtils.findSources( basedir, include, null ); |
75 | |
} |
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
public static String[] findSources( String basedir, String include, String exclude ) |
84 | |
{ |
85 | 2 | DirectoryScanner scanner = new DirectoryScanner(); |
86 | 2 | scanner.setBasedir( basedir ); |
87 | 2 | scanner.setIncludes( new String[] { include } ); |
88 | 2 | if ( !StringUtils.isEmpty( exclude ) ) |
89 | |
{ |
90 | 1 | scanner.setExcludes( new String[] { exclude, StringUtils.join( FileUtils.getDefaultExcludes(), "," ) } ); |
91 | |
} |
92 | |
else |
93 | |
{ |
94 | 1 | scanner.setExcludes( FileUtils.getDefaultExcludes() ); |
95 | |
} |
96 | |
|
97 | 2 | scanner.scan(); |
98 | |
|
99 | 2 | return scanner.getIncludedFiles(); |
100 | |
} |
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | |
|
107 | |
|
108 | |
public static void sortMojos( List<MojoDescriptor> mojoDescriptors ) |
109 | |
{ |
110 | 0 | if ( mojoDescriptors != null ) |
111 | |
{ |
112 | 0 | Collections.sort( mojoDescriptors, new Comparator<MojoDescriptor>() |
113 | 0 | { |
114 | |
|
115 | |
public int compare( MojoDescriptor mojo0, MojoDescriptor mojo1 ) |
116 | |
{ |
117 | 0 | return mojo0.getGoal().compareToIgnoreCase( mojo1.getGoal() ); |
118 | |
} |
119 | |
} ); |
120 | |
} |
121 | 0 | } |
122 | |
|
123 | |
|
124 | |
|
125 | |
|
126 | |
|
127 | |
|
128 | |
|
129 | |
|
130 | |
public static void sortMojoParameters( List<Parameter> parameters ) |
131 | |
{ |
132 | 0 | if ( parameters != null ) |
133 | |
{ |
134 | 0 | Collections.sort( parameters, new Comparator<Parameter>() |
135 | 0 | { |
136 | |
|
137 | |
public int compare( Parameter parameter1, Parameter parameter2 ) |
138 | |
{ |
139 | 0 | return parameter1.getName().compareToIgnoreCase( parameter2.getName() ); |
140 | |
} |
141 | |
} ); |
142 | |
} |
143 | 0 | } |
144 | |
} |