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