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 {
177 return importedFrom;
178 }
179
180
181
182
183
184
185 @Nonnull
186 public Builder with() {
187 return newBuilder(this);
188 }
189
190
191
192
193
194
195 @Nonnull
196 public DistributionManagement withRepository(DeploymentRepository repository) {
197 return newBuilder(this, true).repository(repository).build();
198 }
199
200
201
202
203
204
205 @Nonnull
206 public DistributionManagement withSnapshotRepository(DeploymentRepository snapshotRepository) {
207 return newBuilder(this, true).snapshotRepository(snapshotRepository).build();
208 }
209
210
211
212
213
214
215 @Nonnull
216 public DistributionManagement withSite(Site site) {
217 return newBuilder(this, true).site(site).build();
218 }
219
220
221
222
223
224
225 @Nonnull
226 public DistributionManagement withDownloadUrl(String downloadUrl) {
227 return newBuilder(this, true).downloadUrl(downloadUrl).build();
228 }
229
230
231
232
233
234
235 @Nonnull
236 public DistributionManagement withRelocation(Relocation relocation) {
237 return newBuilder(this, true).relocation(relocation).build();
238 }
239
240
241
242
243
244
245 @Nonnull
246 public DistributionManagement withStatus(String status) {
247 return newBuilder(this, true).status(status).build();
248 }
249
250
251
252
253
254
255
256
257 @Nonnull
258 public static DistributionManagement newInstance() {
259 return newInstance(true);
260 }
261
262
263
264
265
266
267
268
269 @Nonnull
270 public static DistributionManagement newInstance(boolean withDefaults) {
271 return newBuilder(withDefaults).build();
272 }
273
274
275
276
277
278
279
280
281 @Nonnull
282 public static Builder newBuilder() {
283 return newBuilder(true);
284 }
285
286
287
288
289
290
291
292 @Nonnull
293 public static Builder newBuilder(boolean withDefaults) {
294 return new Builder(withDefaults);
295 }
296
297
298
299
300
301
302
303
304 @Nonnull
305 public static Builder newBuilder(DistributionManagement from) {
306 return newBuilder(from, false);
307 }
308
309
310
311
312
313
314
315
316 @Nonnull
317 public static Builder newBuilder(DistributionManagement from, boolean forceCopy) {
318 return new Builder(from, forceCopy);
319 }
320
321
322
323
324
325
326 @NotThreadSafe
327 public static class Builder
328 {
329 DistributionManagement base;
330 DeploymentRepository repository;
331 DeploymentRepository snapshotRepository;
332 Site site;
333 String downloadUrl;
334 Relocation relocation;
335 String status;
336 Map<Object, InputLocation> locations;
337 InputLocation importedFrom;
338
339 protected Builder(boolean withDefaults) {
340 if (withDefaults) {
341 }
342 }
343
344 protected Builder(DistributionManagement base, boolean forceCopy) {
345 if (forceCopy) {
346 this.repository = base.repository;
347 this.snapshotRepository = base.snapshotRepository;
348 this.site = base.site;
349 this.downloadUrl = base.downloadUrl;
350 this.relocation = base.relocation;
351 this.status = base.status;
352 this.locations = base.locations;
353 this.importedFrom = base.importedFrom;
354 } else {
355 this.base = base;
356 }
357 }
358
359 @Nonnull
360 public Builder repository(DeploymentRepository repository) {
361 this.repository = repository;
362 return this;
363 }
364
365 @Nonnull
366 public Builder snapshotRepository(DeploymentRepository snapshotRepository) {
367 this.snapshotRepository = snapshotRepository;
368 return this;
369 }
370
371 @Nonnull
372 public Builder site(Site site) {
373 this.site = site;
374 return this;
375 }
376
377 @Nonnull
378 public Builder downloadUrl(String downloadUrl) {
379 this.downloadUrl = downloadUrl;
380 return this;
381 }
382
383 @Nonnull
384 public Builder relocation(Relocation relocation) {
385 this.relocation = relocation;
386 return this;
387 }
388
389 @Nonnull
390 public Builder status(String status) {
391 this.status = status;
392 return this;
393 }
394
395
396 @Nonnull
397 public Builder location(Object key, InputLocation location) {
398 if (location != null) {
399 if (!(this.locations instanceof HashMap)) {
400 this.locations = this.locations != null ? new HashMap<>(this.locations) : new HashMap<>();
401 }
402 this.locations.put(key, location);
403 }
404 return this;
405 }
406
407 @Nonnull
408 public Builder importedFrom(InputLocation importedFrom) {
409 this.importedFrom = importedFrom;
410 return this;
411 }
412
413 @Nonnull
414 public DistributionManagement build() {
415
416 if (base != null
417 && (repository == null || repository == base.repository)
418 && (snapshotRepository == null || snapshotRepository == base.snapshotRepository)
419 && (site == null || site == base.site)
420 && (downloadUrl == null || downloadUrl == base.downloadUrl)
421 && (relocation == null || relocation == base.relocation)
422 && (status == null || status == base.status)
423 ) {
424 return base;
425 }
426 return new DistributionManagement(this);
427 }
428
429 Map<Object, InputLocation> computeLocations() {
430 Map<Object, InputLocation> newlocs = locations != null ? locations : Map.of();
431 Map<Object, InputLocation> oldlocs = base != null ? base.locations : Map.of();
432 if (newlocs.isEmpty()) {
433 return Map.copyOf(oldlocs);
434 }
435 if (oldlocs.isEmpty()) {
436 return Map.copyOf(newlocs);
437 }
438 return Stream.concat(newlocs.entrySet().stream(), oldlocs.entrySet().stream())
439
440 .collect(Collectors.toUnmodifiableMap(Map.Entry::getKey, Map.Entry::getValue, (v1, v2) -> v1));
441 }
442 }
443
444 }