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 | 0 | 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 | 0 | 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 | 0 | 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 | 0 | for ( String category_ : CATEGORIES ) |
119 | |
{ |
120 | 0 | if ( category_.equalsIgnoreCase( category ) ) |
121 | |
{ |
122 | 0 | return category_; |
123 | |
} |
124 | |
} |
125 | |
|
126 | 0 | return null; |
127 | |
} |
128 | |
|
129 | |
|
130 | |
|
131 | |
|
132 | |
|
133 | |
|
134 | |
|
135 | |
public static String getProgrammingLanguageSupportedByASF( String programmingLanguage ) |
136 | |
{ |
137 | 0 | for ( String programmingLanguage_ : PROGRAMMING_LANGUAGES ) |
138 | |
{ |
139 | 0 | if ( programmingLanguage_.equalsIgnoreCase( programmingLanguage ) ) |
140 | |
{ |
141 | 0 | return programmingLanguage_; |
142 | |
} |
143 | |
} |
144 | |
|
145 | 0 | return null; |
146 | |
} |
147 | |
|
148 | |
|
149 | |
|
150 | |
|
151 | |
|
152 | |
|
153 | |
|
154 | |
public static Developer findChair( List<Developer> developers ) |
155 | |
{ |
156 | 0 | if ( developers == null || developers.isEmpty() ) |
157 | |
{ |
158 | 0 | return null; |
159 | |
} |
160 | |
|
161 | 0 | for ( Developer developer : developers ) |
162 | |
{ |
163 | 0 | List<String> roles = developer.getRoles(); |
164 | |
|
165 | 0 | for ( String role : roles ) |
166 | |
{ |
167 | 0 | if ( role.toLowerCase().contains( "chair" ) ) |
168 | |
{ |
169 | 0 | return developer; |
170 | |
} |
171 | |
} |
172 | 0 | } |
173 | |
|
174 | 0 | return null; |
175 | |
} |
176 | |
|
177 | |
|
178 | |
|
179 | |
|
180 | |
|
181 | |
|
182 | |
|
183 | |
public static List<Developer> findPMCMembers( List<Developer> developers ) |
184 | |
{ |
185 | 0 | if ( developers == null || developers.isEmpty() ) |
186 | |
{ |
187 | 0 | return null; |
188 | |
} |
189 | |
|
190 | 0 | List<Developer> pmcs = new ArrayList<Developer>(); |
191 | 0 | for ( Developer developer : developers ) |
192 | |
{ |
193 | 0 | List<String> roles = developer.getRoles(); |
194 | |
|
195 | 0 | for ( String role : roles ) |
196 | |
{ |
197 | 0 | if ( role.toLowerCase().contains( "pmc" ) ) |
198 | |
{ |
199 | 0 | pmcs.add( developer ); |
200 | |
} |
201 | |
} |
202 | 0 | } |
203 | |
|
204 | 0 | return pmcs; |
205 | |
} |
206 | |
|
207 | |
|
208 | |
|
209 | |
|
210 | |
|
211 | |
|
212 | |
|
213 | |
|
214 | |
|
215 | |
|
216 | |
public static boolean isASFProject( MavenProject project ) |
217 | |
{ |
218 | 0 | if ( project == null ) |
219 | |
{ |
220 | 0 | throw new IllegalArgumentException( "project is required" ); |
221 | |
} |
222 | |
|
223 | |
|
224 | 0 | if ( project.getOrganization() != null && StringUtils.isNotEmpty( project.getOrganization().getName() ) |
225 | |
&& project.getOrganization().getName().trim().equals( "The Apache Software Foundation" ) ) |
226 | |
|
227 | |
|
228 | |
{ |
229 | 0 | return true; |
230 | |
} |
231 | |
|
232 | |
|
233 | 0 | if ( project.getOrganization() != null && isHostedAtASF( project.getOrganization().getUrl() ) ) |
234 | |
{ |
235 | 0 | return true; |
236 | |
} |
237 | |
|
238 | 0 | if ( isHostedAtASF( project.getUrl() ) ) |
239 | |
{ |
240 | 0 | return true; |
241 | |
} |
242 | |
|
243 | 0 | if ( project.getScm() != null ) |
244 | |
{ |
245 | 0 | if ( StringUtils.isNotEmpty( project.getScm().getUrl() ) |
246 | |
&& project.getScm().getUrl().contains( APACHE_DOMAIN_NAME ) ) |
247 | |
{ |
248 | 0 | return true; |
249 | |
} |
250 | |
|
251 | 0 | if ( StringUtils.isNotEmpty( project.getScm().getConnection() ) |
252 | |
&& project.getScm().getConnection().contains( APACHE_DOMAIN_NAME ) ) |
253 | |
{ |
254 | 0 | return true; |
255 | |
} |
256 | |
|
257 | 0 | if ( StringUtils.isNotEmpty( project.getScm().getDeveloperConnection() ) |
258 | |
&& project.getScm().getDeveloperConnection().contains( APACHE_DOMAIN_NAME ) ) |
259 | |
{ |
260 | 0 | return true; |
261 | |
} |
262 | |
} |
263 | |
|
264 | 0 | if ( project.getDistributionManagement() != null ) |
265 | |
{ |
266 | 0 | if ( isHostedAtASF( project.getDistributionManagement().getDownloadUrl() ) ) |
267 | |
{ |
268 | 0 | return true; |
269 | |
} |
270 | |
|
271 | 0 | if ( project.getDistributionManagement().getRepository() != null |
272 | |
&& isHostedAtASF( project.getDistributionManagement().getRepository().getUrl() ) ) |
273 | |
{ |
274 | 0 | return true; |
275 | |
} |
276 | |
|
277 | 0 | if ( project.getDistributionManagement().getSnapshotRepository() != null |
278 | |
&& isHostedAtASF( project.getDistributionManagement().getSnapshotRepository().getUrl() ) ) |
279 | |
{ |
280 | 0 | return true; |
281 | |
} |
282 | |
|
283 | 0 | if ( project.getDistributionManagement().getSite() != null |
284 | |
&& isHostedAtASF( project.getDistributionManagement().getSite().getUrl() ) ) |
285 | |
{ |
286 | 0 | return true; |
287 | |
} |
288 | |
} |
289 | |
|
290 | 0 | return false; |
291 | |
} |
292 | |
|
293 | |
|
294 | |
|
295 | |
|
296 | |
|
297 | |
|
298 | |
private static boolean isHostedAtASF( String str ) |
299 | |
{ |
300 | 0 | if ( StringUtils.isEmpty( str ) ) |
301 | |
{ |
302 | 0 | return false; |
303 | |
} |
304 | |
|
305 | 0 | str = str.trim(); |
306 | |
try |
307 | |
{ |
308 | 0 | URL url = new URL( str ); |
309 | 0 | if ( url.getHost().endsWith( APACHE_DOMAIN_NAME ) ) |
310 | |
{ |
311 | 0 | return true; |
312 | |
} |
313 | |
} |
314 | 0 | catch ( MalformedURLException e ) |
315 | |
{ |
316 | 0 | } |
317 | |
|
318 | 0 | return false; |
319 | |
} |
320 | |
} |