1
2
3
4
5 package org.apache.maven.api.model;
6
7 import java.io.Serializable;
8 import java.util.Collections;
9 import java.util.HashMap;
10 import java.util.Map;
11 import java.util.Objects;
12 import java.util.Optional;
13 import java.util.Set;
14 import java.util.stream.Collectors;
15 import java.util.stream.Stream;
16 import org.apache.maven.api.annotations.Experimental;
17 import org.apache.maven.api.annotations.Generated;
18 import org.apache.maven.api.annotations.Immutable;
19 import org.apache.maven.api.annotations.Nonnull;
20 import org.apache.maven.api.annotations.NotThreadSafe;
21 import org.apache.maven.api.annotations.ThreadSafe;
22
23
24
25
26
27 @Experimental
28 @Generated @ThreadSafe @Immutable
29 public class DistributionManagement
30 implements Serializable, InputLocationTracker
31 {
32
33
34
35
36 final DeploymentRepository repository;
37
38
39
40
41 final DeploymentRepository snapshotRepository;
42
43
44
45 final Site site;
46
47
48
49
50
51
52 final String downloadUrl;
53
54
55
56
57 final Relocation relocation;
58
59
60
61
62
63
64
65
66
67 final String status;
68
69 final Map<Object, InputLocation> locations;
70
71 final InputLocation importedFrom;
72
73
74
75
76
77 protected DistributionManagement(Builder builder) {
78 this.repository = builder.repository != null ? builder.repository : (builder.base != null ? builder.base.repository : null);
79 this.snapshotRepository = builder.snapshotRepository != null ? builder.snapshotRepository : (builder.base != null ? builder.base.snapshotRepository : null);
80 this.site = builder.site != null ? builder.site : (builder.base != null ? builder.base.site : null);
81 this.downloadUrl = builder.downloadUrl != null ? builder.downloadUrl : (builder.base != null ? builder.base.downloadUrl : null);
82 this.relocation = builder.relocation != null ? builder.relocation : (builder.base != null ? builder.base.relocation : null);
83 this.status = builder.status != null ? builder.status : (builder.base != null ? builder.base.status : null);
84 this.locations = builder.computeLocations();
85 this.importedFrom = builder.importedFrom;
86 }
87
88
89
90
91
92
93
94 public DeploymentRepository getRepository() {
95 return this.repository;
96 }
97
98
99
100
101
102
103
104 public DeploymentRepository getSnapshotRepository() {
105 return this.snapshotRepository;
106 }
107
108
109
110
111
112
113 public Site getSite() {
114 return this.site;
115 }
116
117
118
119
120
121
122
123
124
125 public String getDownloadUrl() {
126 return this.downloadUrl;
127 }
128
129
130
131
132
133
134
135 public Relocation getRelocation() {
136 return this.relocation;
137 }
138
139
140
141
142
143
144
145
146
147
148
149
150 public String getStatus() {
151 return this.status;
152 }
153
154
155
156
157 public InputLocation getLocation(Object key) {
158 return locations.get(key);
159 }
160
161
162
163
164 public Set<Object> getLocationKeys() {
165 return locations.keySet();
166 }
167
168 protected Stream<Object> getLocationKeyStream() {
169 return locations.keySet().stream();
170 }
171
172
173
174
175 public InputLocation getImportedFrom() {
176 return importedFrom;
177 }
178
179
180
181
182
183
184 @Nonnull
185 public Builder with() {
186 return newBuilder(this);
187 }
188
189
190
191
192
193
194 @Nonnull
195 public DistributionManagement withRepository(DeploymentRepository repository) {
196 return newBuilder(this, true).repository(repository).build();
197 }
198
199
200
201
202
203
204 @Nonnull
205 public DistributionManagement withSnapshotRepository(DeploymentRepository snapshotRepository) {
206 return newBuilder(this, true).snapshotRepository(snapshotRepository).build();
207 }
208
209
210
211
212
213
214 @Nonnull
215 public DistributionManagement withSite(Site site) {
216 return newBuilder(this, true).site(site).build();
217 }
218
219
220
221
222
223
224 @Nonnull
225 public DistributionManagement withDownloadUrl(String downloadUrl) {
226 return newBuilder(this, true).downloadUrl(downloadUrl).build();
227 }
228
229
230
231
232
233
234 @Nonnull
235 public DistributionManagement withRelocation(Relocation relocation) {
236 return newBuilder(this, true).relocation(relocation).build();
237 }
238
239
240
241
242
243
244 @Nonnull
245 public DistributionManagement withStatus(String status) {
246 return newBuilder(this, true).status(status).build();
247 }
248
249
250
251
252
253
254
255
256 @Nonnull
257 public static DistributionManagement newInstance() {
258 return newInstance(true);
259 }
260
261
262
263
264
265
266
267
268 @Nonnull
269 public static DistributionManagement newInstance(boolean withDefaults) {
270 return newBuilder(withDefaults).build();
271 }
272
273
274
275
276
277
278
279
280 @Nonnull
281 public static Builder newBuilder() {
282 return newBuilder(true);
283 }
284
285
286
287
288
289
290
291 @Nonnull
292 public static Builder newBuilder(boolean withDefaults) {
293 return new Builder(withDefaults);
294 }
295
296
297
298
299
300
301
302
303 @Nonnull
304 public static Builder newBuilder(DistributionManagement from) {
305 return newBuilder(from, false);
306 }
307
308
309
310
311
312
313
314
315 @Nonnull
316 public static Builder newBuilder(DistributionManagement from, boolean forceCopy) {
317 return new Builder(from, forceCopy);
318 }
319
320
321
322
323
324
325 @NotThreadSafe
326 public static class Builder
327 {
328 DistributionManagement base;
329 DeploymentRepository repository;
330 DeploymentRepository snapshotRepository;
331 Site site;
332 String downloadUrl;
333 Relocation relocation;
334 String status;
335 Map<Object, InputLocation> locations;
336 InputLocation importedFrom;
337
338 protected Builder(boolean withDefaults) {
339 if (withDefaults) {
340 }
341 }
342
343 protected Builder(DistributionManagement base, boolean forceCopy) {
344 if (forceCopy) {
345 this.repository = base.repository;
346 this.snapshotRepository = base.snapshotRepository;
347 this.site = base.site;
348 this.downloadUrl = base.downloadUrl;
349 this.relocation = base.relocation;
350 this.status = base.status;
351 this.locations = base.locations;
352 this.importedFrom = base.importedFrom;
353 } else {
354 this.base = base;
355 }
356 }
357
358 @Nonnull
359 public Builder repository(DeploymentRepository repository) {
360 this.repository = repository;
361 return this;
362 }
363
364 @Nonnull
365 public Builder snapshotRepository(DeploymentRepository snapshotRepository) {
366 this.snapshotRepository = snapshotRepository;
367 return this;
368 }
369
370 @Nonnull
371 public Builder site(Site site) {
372 this.site = site;
373 return this;
374 }
375
376 @Nonnull
377 public Builder downloadUrl(String downloadUrl) {
378 this.downloadUrl = downloadUrl;
379 return this;
380 }
381
382 @Nonnull
383 public Builder relocation(Relocation relocation) {
384 this.relocation = relocation;
385 return this;
386 }
387
388 @Nonnull
389 public Builder status(String status) {
390 this.status = status;
391 return this;
392 }
393
394
395 @Nonnull
396 public Builder location(Object key, InputLocation location) {
397 if (location != null) {
398 if (!(this.locations instanceof HashMap)) {
399 this.locations = this.locations != null ? new HashMap<>(this.locations) : new HashMap<>();
400 }
401 this.locations.put(key, location);
402 }
403 return this;
404 }
405
406 @Nonnull
407 public Builder importedFrom(InputLocation importedFrom) {
408 this.importedFrom = importedFrom;
409 return this;
410 }
411
412 @Nonnull
413 public DistributionManagement build() {
414
415 if (base != null
416 && (repository == null || repository == base.repository)
417 && (snapshotRepository == null || snapshotRepository == base.snapshotRepository)
418 && (site == null || site == base.site)
419 && (downloadUrl == null || downloadUrl == base.downloadUrl)
420 && (relocation == null || relocation == base.relocation)
421 && (status == null || status == base.status)
422 ) {
423 return base;
424 }
425 return new DistributionManagement(this);
426 }
427
428 Map<Object, InputLocation> computeLocations() {
429 Map<Object, InputLocation> newlocs = locations != null ? locations : Map.of();
430 Map<Object, InputLocation> oldlocs = base != null ? base.locations : Map.of();
431 if (newlocs.isEmpty()) {
432 return Map.copyOf(oldlocs);
433 }
434 if (oldlocs.isEmpty()) {
435 return Map.copyOf(newlocs);
436 }
437 return Stream.concat(newlocs.entrySet().stream(), oldlocs.entrySet().stream())
438
439 .collect(Collectors.toUnmodifiableMap(Map.Entry::getKey, Map.Entry::getValue, (v1, v2) -> v1));
440 }
441 }
442
443 }