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