1 package org.apache.maven.plugin.doap.options;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.net.MalformedURLException;
23 import java.net.URL;
24 import java.util.ArrayList;
25 import java.util.List;
26
27 import org.apache.maven.model.Developer;
28 import org.apache.maven.project.MavenProject;
29 import org.codehaus.plexus.util.StringUtils;
30
31
32
33
34
35
36
37
38 public class ASFExtOptionsUtil
39 {
40
41 private static final String APACHE_DOMAIN_NAME = "apache.org";
42
43
44
45
46
47
48 public static final String CATEGORY_RESOURCE = "http://projects.apache.org/category/";
49
50
51 public static final String BUILD_MANAGEMENT_CATEGORY = "build-management";
52
53
54 public static final String DATABASE_CATEGORY = "database";
55
56
57 public static final String HTTP_CATEGORY = "http";
58
59
60 public static final String HTTP_MODULES_CATEGORY = "httpd-modules";
61
62
63 public static final String LIBRARY_CATEGORY = "library";
64
65
66 public static final String MAIL_CATEGORY = "mail";
67
68
69 public static final String NETWORK_CLIENT_CATEGORY = "network-client";
70
71
72 public static final String NETWORK_SERVER_CATEGORY = "network-server";
73
74
75 public static final String TESTING_CATEGORY = "testing";
76
77
78 public static final String WEB_FRAMEWORK_CATEGORY = "web-framework";
79
80
81 public static final String XML_CATEGORY = "xml";
82
83
84 public static final String[] CATEGORIES = { BUILD_MANAGEMENT_CATEGORY, DATABASE_CATEGORY, HTTP_CATEGORY,
85 HTTP_MODULES_CATEGORY, LIBRARY_CATEGORY, MAIL_CATEGORY, NETWORK_CLIENT_CATEGORY, NETWORK_SERVER_CATEGORY,
86 TESTING_CATEGORY, WEB_FRAMEWORK_CATEGORY, XML_CATEGORY };
87
88
89 public static final String C_PROGRAMMING_LANGUAGE = "C";
90
91
92 public static final String JAVA_PROGRAMMING_LANGUAGE = "Java";
93
94
95 public static final String PERL_PROGRAMMING_LANGUAGE = "Perl";
96
97
98 public static final String PYTHON_PROGRAMMING_LANGUAGE = "Python";
99
100
101 public static final String SVG_PROGRAMMING_LANGUAGE = "SVG";
102
103
104 public static final String TCL_PROGRAMMING_LANGUAGE = "Tcl";
105
106
107 public static final String[] PROGRAMMING_LANGUAGES = { C_PROGRAMMING_LANGUAGE, JAVA_PROGRAMMING_LANGUAGE,
108 PERL_PROGRAMMING_LANGUAGE, PYTHON_PROGRAMMING_LANGUAGE, SVG_PROGRAMMING_LANGUAGE, TCL_PROGRAMMING_LANGUAGE };
109
110
111
112
113
114
115
116 public static String getCategorySupportedByASF( String category )
117 {
118 for ( String supportedCategory : CATEGORIES )
119 {
120 if ( supportedCategory.equalsIgnoreCase( category ) )
121 {
122 return supportedCategory;
123 }
124 }
125
126 return null;
127 }
128
129
130
131
132
133
134
135 public static String getProgrammingLanguageSupportedByASF( String programmingLanguage )
136 {
137 for ( String supportedProgrammingLanguage : PROGRAMMING_LANGUAGES )
138 {
139 if ( supportedProgrammingLanguage.equalsIgnoreCase( programmingLanguage ) )
140 {
141 return supportedProgrammingLanguage;
142 }
143 }
144
145 return null;
146 }
147
148
149
150
151
152
153
154 public static Developer findChair( List<Developer> developers )
155 {
156 if ( developers == null || developers.isEmpty() )
157 {
158 return null;
159 }
160
161 for ( Developer developer : developers )
162 {
163 List<String> roles = developer.getRoles();
164
165 for ( String role : roles )
166 {
167 if ( role.toLowerCase().contains( "chair" ) )
168 {
169 return developer;
170 }
171 }
172 }
173
174 return null;
175 }
176
177
178
179
180
181
182
183 public static List<Developer> findPMCMembers( List<Developer> developers )
184 {
185 if ( developers == null || developers.isEmpty() )
186 {
187 return null;
188 }
189
190 List<Developer> pmcs = new ArrayList<Developer>();
191 for ( Developer developer : developers )
192 {
193 List<String> roles = developer.getRoles();
194
195 for ( String role : roles )
196 {
197 if ( role.toLowerCase().contains( "pmc" ) )
198 {
199 pmcs.add( developer );
200 }
201 }
202 }
203
204 return pmcs;
205 }
206
207
208
209
210
211
212
213
214
215
216 public static boolean isASFProject( MavenProject project )
217 {
218 if ( project == null )
219 {
220 throw new IllegalArgumentException( "project is required" );
221 }
222
223
224 if ( project.getOrganization() != null && StringUtils.isNotEmpty( project.getOrganization().getName() )
225 && project.getOrganization().getName().trim().equals( "The Apache Software Foundation" ) )
226
227 {
228 return true;
229 }
230
231
232 if ( project.getOrganization() != null && isHostedAtASF( project.getOrganization().getUrl() ) )
233 {
234 return true;
235 }
236
237 if ( isHostedAtASF( project.getUrl() ) )
238 {
239 return true;
240 }
241
242 if ( project.getScm() != null )
243 {
244 if ( StringUtils.isNotEmpty( project.getScm().getUrl() )
245 && project.getScm().getUrl().contains( APACHE_DOMAIN_NAME ) )
246 {
247 return true;
248 }
249
250 if ( StringUtils.isNotEmpty( project.getScm().getConnection() )
251 && project.getScm().getConnection().contains( APACHE_DOMAIN_NAME ) )
252 {
253 return true;
254 }
255
256 if ( StringUtils.isNotEmpty( project.getScm().getDeveloperConnection() )
257 && project.getScm().getDeveloperConnection().contains( APACHE_DOMAIN_NAME ) )
258 {
259 return true;
260 }
261 }
262
263 if ( project.getDistributionManagement() != null )
264 {
265 if ( isHostedAtASF( project.getDistributionManagement().getDownloadUrl() ) )
266 {
267 return true;
268 }
269
270 if ( project.getDistributionManagement().getRepository() != null
271 && isHostedAtASF( project.getDistributionManagement().getRepository().getUrl() ) )
272 {
273 return true;
274 }
275
276 if ( project.getDistributionManagement().getSnapshotRepository() != null
277 && isHostedAtASF( project.getDistributionManagement().getSnapshotRepository().getUrl() ) )
278 {
279 return true;
280 }
281
282 if ( project.getDistributionManagement().getSite() != null
283 && isHostedAtASF( project.getDistributionManagement().getSite().getUrl() ) )
284 {
285 return true;
286 }
287 }
288
289 return false;
290 }
291
292
293
294
295
296
297 private static boolean isHostedAtASF( String str )
298 {
299 if ( StringUtils.isEmpty( str ) )
300 {
301 return false;
302 }
303
304 str = str.trim();
305 try
306 {
307 URL url = new URL( str );
308 if ( url.getHost().endsWith( APACHE_DOMAIN_NAME ) )
309 {
310 return true;
311 }
312 }
313 catch ( MalformedURLException e )
314 {
315
316 }
317
318 return false;
319 }
320 }