1
2
3
4
5 package org.apache.maven.api.model;
6
7 import java.io.Serializable;
8 import java.util.ArrayList;
9 import java.util.Collection;
10 import java.util.Collections;
11 import java.util.HashMap;
12 import java.util.List;
13 import java.util.Map;
14 import java.util.Objects;
15 import java.util.Optional;
16 import java.util.Set;
17 import java.util.stream.Collectors;
18 import java.util.stream.Stream;
19 import org.apache.maven.api.annotations.Experimental;
20 import org.apache.maven.api.annotations.Generated;
21 import org.apache.maven.api.annotations.Immutable;
22 import org.apache.maven.api.annotations.Nonnull;
23 import org.apache.maven.api.annotations.NotThreadSafe;
24 import org.apache.maven.api.annotations.ThreadSafe;
25
26
27
28
29
30 @Experimental
31 @Generated @ThreadSafe @Immutable
32 public class CiManagement
33 implements Serializable, InputLocationTracker
34 {
35
36
37
38 final String system;
39
40
41
42 final String url;
43
44
45
46
47 final List<Notifier> notifiers;
48
49 final Map<Object, InputLocation> locations;
50
51 final InputLocation importedFrom;
52
53
54
55
56
57 protected CiManagement(Builder builder) {
58 this.system = builder.system != null ? builder.system : (builder.base != null ? builder.base.system : null);
59 this.url = builder.url != null ? builder.url : (builder.base != null ? builder.base.url : null);
60 this.notifiers = ImmutableCollections.copy(builder.notifiers != null ? builder.notifiers : (builder.base != null ? builder.base.notifiers : null));
61 this.locations = builder.computeLocations();
62 this.importedFrom = builder.importedFrom;
63 }
64
65
66
67
68
69
70 public String getSystem() {
71 return this.system;
72 }
73
74
75
76
77
78
79 public String getUrl() {
80 return this.url;
81 }
82
83
84
85
86
87
88
89 @Nonnull
90 public List<Notifier> getNotifiers() {
91 return this.notifiers;
92 }
93
94
95
96
97
98
99
100
101 public InputLocation getLocation(Object key) {
102 Objects.requireNonNull(key, "key");
103 return locations.get(key);
104 }
105
106
107
108
109 public Set<Object> getLocationKeys() {
110 return locations.keySet();
111 }
112
113 protected Stream<Object> getLocationKeyStream() {
114 return locations.keySet().stream();
115 }
116
117
118
119
120 public InputLocation getImportedFrom() {
121 return importedFrom;
122 }
123
124
125
126
127
128
129 @Nonnull
130 public Builder with() {
131 return newBuilder(this);
132 }
133
134
135
136
137
138
139 @Nonnull
140 public CiManagement withSystem(String system) {
141 return newBuilder(this, true).system(system).build();
142 }
143
144
145
146
147
148
149 @Nonnull
150 public CiManagement withUrl(String url) {
151 return newBuilder(this, true).url(url).build();
152 }
153
154
155
156
157
158
159 @Nonnull
160 public CiManagement withNotifiers(Collection<Notifier> notifiers) {
161 return newBuilder(this, true).notifiers(notifiers).build();
162 }
163
164
165
166
167
168
169
170
171 @Nonnull
172 public static CiManagement newInstance() {
173 return newInstance(true);
174 }
175
176
177
178
179
180
181
182
183 @Nonnull
184 public static CiManagement newInstance(boolean withDefaults) {
185 return newBuilder(withDefaults).build();
186 }
187
188
189
190
191
192
193
194
195 @Nonnull
196 public static Builder newBuilder() {
197 return newBuilder(true);
198 }
199
200
201
202
203
204
205
206 @Nonnull
207 public static Builder newBuilder(boolean withDefaults) {
208 return new Builder(withDefaults);
209 }
210
211
212
213
214
215
216
217
218 @Nonnull
219 public static Builder newBuilder(CiManagement from) {
220 return newBuilder(from, false);
221 }
222
223
224
225
226
227
228
229
230 @Nonnull
231 public static Builder newBuilder(CiManagement from, boolean forceCopy) {
232 return new Builder(from, forceCopy);
233 }
234
235
236
237
238
239
240 @NotThreadSafe
241 public static class Builder
242 {
243 CiManagement base;
244 String system;
245 String url;
246 Collection<Notifier> notifiers;
247 Map<Object, InputLocation> locations;
248 InputLocation importedFrom;
249
250 protected Builder(boolean withDefaults) {
251 if (withDefaults) {
252 }
253 }
254
255 protected Builder(CiManagement base, boolean forceCopy) {
256 if (forceCopy) {
257 this.system = base.system;
258 this.url = base.url;
259 this.notifiers = base.notifiers;
260 this.locations = base.locations;
261 this.importedFrom = base.importedFrom;
262 } else {
263 this.base = base;
264 }
265 }
266
267 @Nonnull
268 public Builder system(String system) {
269 this.system = system;
270 return this;
271 }
272
273 @Nonnull
274 public Builder url(String url) {
275 this.url = url;
276 return this;
277 }
278
279 @Nonnull
280 public Builder notifiers(Collection<Notifier> notifiers) {
281 this.notifiers = notifiers;
282 return this;
283 }
284
285
286 @Nonnull
287 public Builder location(Object key, InputLocation location) {
288 if (location != null) {
289 if (!(this.locations instanceof HashMap)) {
290 this.locations = this.locations != null ? new HashMap<>(this.locations) : new HashMap<>();
291 }
292 this.locations.put(key, location);
293 }
294 return this;
295 }
296
297 @Nonnull
298 public Builder importedFrom(InputLocation importedFrom) {
299 this.importedFrom = importedFrom;
300 return this;
301 }
302
303 @Nonnull
304 public CiManagement build() {
305
306 if (base != null
307 && (system == null || system == base.system)
308 && (url == null || url == base.url)
309 && (notifiers == null || notifiers == base.notifiers)
310 ) {
311 return base;
312 }
313 return new CiManagement(this);
314 }
315
316 Map<Object, InputLocation> computeLocations() {
317 Map<Object, InputLocation> newlocs = locations != null ? locations : Map.of();
318 Map<Object, InputLocation> oldlocs = base != null ? base.locations : Map.of();
319 if (newlocs.isEmpty()) {
320 return Map.copyOf(oldlocs);
321 }
322 if (oldlocs.isEmpty()) {
323 return Map.copyOf(newlocs);
324 }
325 return Stream.concat(newlocs.entrySet().stream(), oldlocs.entrySet().stream())
326
327 .collect(Collectors.toUnmodifiableMap(Map.Entry::getKey, Map.Entry::getValue, (v1, v2) -> v1));
328 }
329 }
330
331 }