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