-
Notifications
You must be signed in to change notification settings - Fork 69
/
Developer.java
174 lines (154 loc) · 6.22 KB
/
Developer.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/********************************************************************************
* Copyright (c) 2016, 2018 GK Software SE and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Stephan Herrmann - initial implementation
********************************************************************************/
package org.eclipse.platform.releng.maven.pom;
import static org.eclipse.platform.releng.maven.pom.ArtifactInfo.element;
import static org.eclipse.platform.releng.maven.pom.ArtifactInfo.subElement;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public abstract class Developer {
static final String PLATFORM_GIT_REPO = "https://git.eclipse.org/c/platform";
static final String[] ROLE_LEAD = { "Project Lead" };
public static final HashMap<String, List<Developer>> developersPerRepo = new HashMap<>();
public static final Set<String> projects = new HashSet<>();
static {
// currently unused:
Developer dani = new IndividualDeveloper("Dani Megert");
developersPerRepo.put(PLATFORM_GIT_REPO,
Arrays.asList(dani));
developersPerRepo.put("https://git.eclipse.org/c/equinox",
Arrays.asList(new IndividualDeveloper("Ian Bull"), new IndividualDeveloper("Pascal Rapicault"), new IndividualDeveloper("Thomas Watson")));
developersPerRepo.put("https://git.eclipse.org/c/jdt",
Arrays.asList(dani));
developersPerRepo.put("https://git.eclipse.org/c/pde",
Arrays.asList(new IndividualDeveloper("Curtis Windatt"), new IndividualDeveloper("Vikas Chandra")));
//
projects.add("eclipse.platform");
projects.add("eclipse.jdt");
projects.add("eclipse.pde");
projects.add("rt.equinox");
}
public static void addIndividualDevelopers(String projRepo, String bsn, String indent, StringBuilder buf) {
List<Developer> devs = getDevelopers(projRepo, bsn);
if (devs == null)
System.err.println("No developers for project repo "+projRepo+" ("+bsn+")");
else
element("developers", indent, buf, Developer.pomSubElements(devs));
}
public static void addUrlDevelopers(String gitUrl, String bsn, String indent, StringBuilder buf) {
String whoSInvolved = gitRepoToWhoSInvolved(gitUrl);
if (whoSInvolved == null)
System.err.println("No developers for project repo "+gitUrl+" ("+bsn+")");
else
element("developers", indent, buf, Developer.pomSubElements(Collections.singletonList(new UrlDeveloper(whoSInvolved))));
}
private static String gitRepoToWhoSInvolved(String gitUrl) {
if ((gitUrl == null) || (gitUrl.trim() == "")) {
return "https://projects.eclipse.org/projects/eclipse.platform/who";
}
String[] tokens = gitUrl.split("/");
if (tokens.length >= 6) {
String token = tokens[5]; // https://git.eclipse.org/c/equinox/rt.equinox.framework.git => start with rt.equinox.framework
int end = token.endsWith(".git") ? token.length()-".git".length() : token.length();
String project = token.substring(0, end);
// Special case for e4 projects
if (project.contains("org.eclipse.e4")) {
project = "eclipse.platform";
} else {
while (!projects.contains(project)) {
end = project.lastIndexOf('.');
if (end == -1)
return null;
project = project.substring(0, end); // cut off non-matching tail segment
}
}
return "https://projects.eclipse.org/projects/"+project+"/who";
} else if (tokens.length >= 5) {
String token = tokens[4]; // https://github.com/eclipse-platform/eclipse.platform.releng.git => start with eclipse.platform.releng
int end = token.endsWith(".git") ? token.length()-".git".length() : token.length();
String project = token.substring(0, end);
// Special case for e4 projects
if (project.contains("org.eclipse.e4")) {
project = "eclipse.platform";
} else {
while (!projects.contains(project)) {
end = project.lastIndexOf('.');
if (end == -1)
return null;
project = project.substring(0, end); // cut off non-matching tail segment
}
}
return "https://projects.eclipse.org/projects/"+project+"/who";
}
return null;
}
private static List<Developer> getDevelopers(String projRepo, String bsn) {
// "platform" artifacts in pde repos:
if ("org.eclipse.ui.views.log".equals(bsn) || "org.eclipse.ui.trace".equals(bsn))
return developersPerRepo.get(PLATFORM_GIT_REPO);
// "platform" artifacts in jdt repos:
if ("org.eclipse.ltk.core.refactoring".equals(bsn) || "org.eclipse.ltk.ui.refactoring".equals(bsn))
return developersPerRepo.get(PLATFORM_GIT_REPO);
return developersPerRepo.get(projRepo);
}
private static String pomSubElements(List<Developer> devs) {
StringBuilder buf = new StringBuilder();
for (Developer developer : devs)
developer.toPom(buf, "");
return buf.toString();
}
protected abstract void toPom(StringBuilder buf, String string);
/** Represent project leads as individual developers. */
static class IndividualDeveloper extends Developer {
String name;
String[] roles;
public IndividualDeveloper(String name) {
this.name = name;
this.roles = ROLE_LEAD;
}
protected void toPom(StringBuilder buf, String indent) {
element("developer", indent, buf,
subElement("name", this.name),
getRolesElement());
}
String getRolesElement() {
StringBuilder rolesElement = new StringBuilder();
element("roles", "", rolesElement, String.join("\n", getRoleElements()));
return rolesElement.toString();
}
String[] getRoleElements() {
String[] roleElements = new String[this.roles.length];
for (int i = 0; i < this.roles.length; i++) {
StringBuilder subBuf = new StringBuilder();
element("role", "", subBuf, this.roles[i]);
roleElements[i] = subBuf.toString();
}
return roleElements;
}
}
/** Represent developers using the "Who's Involved" web page. */
static class UrlDeveloper extends Developer {
String url;
public UrlDeveloper(String url) {
this.url = url;
}
protected void toPom(StringBuilder buf, String indent) {
element("developer", indent, buf,
subElement("url", this.url));
}
}
}