1 // =================== DO NOT EDIT THIS FILE ====================
2 // Generated by Modello Velocity from model.vm
3 // template, any modifications will be overwritten.
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 * This elements describes all that pertains to distribution for a project. It is
25 * primarily used for deployment of artifacts and the site produced by the build.
26 */
27 @Experimental
28 @Generated @ThreadSafe @Immutable
29 public class DistributionManagement
30 implements Serializable, InputLocationTracker
31 {
32 /**
33 * Information needed to deploy the artifacts generated by the project to a
34 * remote repository.
35 */
36 final DeploymentRepository repository;
37 /**
38 * Where to deploy snapshots of artifacts to. If not given, it defaults to the
39 * {@code repository} element.
40 */
41 final DeploymentRepository snapshotRepository;
42 /**
43 * Information needed for deploying the web site of the project.
44 */
45 final Site site;
46 /**
47 * The URL of the project's download page. If not given users will be
48 * referred to the homepage given by {@code url}.
49 * This is given to assist in locating artifacts that are not in the repository due to
50 * licensing restrictions.
51 */
52 final String downloadUrl;
53 /**
54 * Relocation information of the artifact if it has been moved to a new group ID
55 * and/or artifact ID.
56 */
57 final Relocation relocation;
58 /**
59 * Gives the status of this artifact in the remote repository.
60 * This must not be set in your local project, as it is updated by
61 * tools placing it in the repository. Valid values are: {@code none} (default),
62 * {@code converted} (repository manager converted this from a Maven 1 POM),
63 * {@code partner}
64 * (directly synced from a partner Maven 2 repository), {@code deployed} (was deployed from a Maven 2
65 * instance), {@code verified} (has been hand verified as correct and final).
66 */
67 final String status;
68 /** Locations */
69 final Map<Object, InputLocation> locations;
70 /** Location tracking */
71 final InputLocation importedFrom;
72
73 /**
74 * Constructor for this class, to be called from its subclasses and {@link Builder}.
75 * @see Builder#build()
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 * Information needed to deploy the artifacts generated by the project to a
90 * remote repository.
91 *
92 * @return a {@code DeploymentRepository}
93 */
94 public DeploymentRepository getRepository() {
95 return this.repository;
96 }
97
98 /**
99 * Where to deploy snapshots of artifacts to. If not given, it defaults to the
100 * {@code repository} element.
101 *
102 * @return a {@code DeploymentRepository}
103 */
104 public DeploymentRepository getSnapshotRepository() {
105 return this.snapshotRepository;
106 }
107
108 /**
109 * Information needed for deploying the web site of the project.
110 *
111 * @return a {@code Site}
112 */
113 public Site getSite() {
114 return this.site;
115 }
116
117 /**
118 * The URL of the project's download page. If not given users will be
119 * referred to the homepage given by {@code url}.
120 * This is given to assist in locating artifacts that are not in the repository due to
121 * licensing restrictions.
122 *
123 * @return a {@code String}
124 */
125 public String getDownloadUrl() {
126 return this.downloadUrl;
127 }
128
129 /**
130 * Relocation information of the artifact if it has been moved to a new group ID
131 * and/or artifact ID.
132 *
133 * @return a {@code Relocation}
134 */
135 public Relocation getRelocation() {
136 return this.relocation;
137 }
138
139 /**
140 * Gives the status of this artifact in the remote repository.
141 * This must not be set in your local project, as it is updated by
142 * tools placing it in the repository. Valid values are: {@code none} (default),
143 * {@code converted} (repository manager converted this from a Maven 1 POM),
144 * {@code partner}
145 * (directly synced from a partner Maven 2 repository), {@code deployed} (was deployed from a Maven 2
146 * instance), {@code verified} (has been hand verified as correct and final).
147 *
148 * @return a {@code String}
149 */
150 public String getStatus() {
151 return this.status;
152 }
153
154 /**
155 * Gets the location of the specified field in the input source.
156 *
157 * @param key the key of the field, must not be {@code null}
158 * @return the location of the field in the input source or {@code null} if unknown
159 * @throws NullPointerException if {@code key} is {@code null}
160 */
161 public InputLocation getLocation(Object key) {
162 Objects.requireNonNull(key, "key");
163 return locations.get(key);
164 }
165
166 /**
167 * Gets the keys of the locations of the input source.
168 */
169 public Set<Object> getLocationKeys() {
170 return locations.keySet();
171 }
172
173 protected Stream<Object> getLocationKeyStream() {
174 return locations.keySet().stream();
175 }
176
177 /**
178 * Gets the input location that caused this model to be read.
179 */
180 public InputLocation getImportedFrom() {
181 return importedFrom;
182 }
183
184 /**
185 * Creates a new builder with this object as the basis.
186 *
187 * @return a {@code Builder}
188 */
189 @Nonnull
190 public Builder with() {
191 return newBuilder(this);
192 }
193 /**
194 * Creates a new {@code DistributionManagement} instance using the specified repository.
195 *
196 * @param repository the new {@code DeploymentRepository} to use
197 * @return a {@code DistributionManagement} with the specified repository
198 */
199 @Nonnull
200 public DistributionManagement withRepository(DeploymentRepository repository) {
201 return newBuilder(this, true).repository(repository).build();
202 }
203 /**
204 * Creates a new {@code DistributionManagement} instance using the specified snapshotRepository.
205 *
206 * @param snapshotRepository the new {@code DeploymentRepository} to use
207 * @return a {@code DistributionManagement} with the specified snapshotRepository
208 */
209 @Nonnull
210 public DistributionManagement withSnapshotRepository(DeploymentRepository snapshotRepository) {
211 return newBuilder(this, true).snapshotRepository(snapshotRepository).build();
212 }
213 /**
214 * Creates a new {@code DistributionManagement} instance using the specified site.
215 *
216 * @param site the new {@code Site} to use
217 * @return a {@code DistributionManagement} with the specified site
218 */
219 @Nonnull
220 public DistributionManagement withSite(Site site) {
221 return newBuilder(this, true).site(site).build();
222 }
223 /**
224 * Creates a new {@code DistributionManagement} instance using the specified downloadUrl.
225 *
226 * @param downloadUrl the new {@code String} to use
227 * @return a {@code DistributionManagement} with the specified downloadUrl
228 */
229 @Nonnull
230 public DistributionManagement withDownloadUrl(String downloadUrl) {
231 return newBuilder(this, true).downloadUrl(downloadUrl).build();
232 }
233 /**
234 * Creates a new {@code DistributionManagement} instance using the specified relocation.
235 *
236 * @param relocation the new {@code Relocation} to use
237 * @return a {@code DistributionManagement} with the specified relocation
238 */
239 @Nonnull
240 public DistributionManagement withRelocation(Relocation relocation) {
241 return newBuilder(this, true).relocation(relocation).build();
242 }
243 /**
244 * Creates a new {@code DistributionManagement} instance using the specified status.
245 *
246 * @param status the new {@code String} to use
247 * @return a {@code DistributionManagement} with the specified status
248 */
249 @Nonnull
250 public DistributionManagement withStatus(String status) {
251 return newBuilder(this, true).status(status).build();
252 }
253
254 /**
255 * Creates a new {@code DistributionManagement} instance.
256 * Equivalent to {@code newInstance(true)}.
257 * @see #newInstance(boolean)
258 *
259 * @return a new {@code DistributionManagement}
260 */
261 @Nonnull
262 public static DistributionManagement newInstance() {
263 return newInstance(true);
264 }
265
266 /**
267 * Creates a new {@code DistributionManagement} instance using default values or not.
268 * Equivalent to {@code newBuilder(withDefaults).build()}.
269 *
270 * @param withDefaults the boolean indicating whether default values should be used
271 * @return a new {@code DistributionManagement}
272 */
273 @Nonnull
274 public static DistributionManagement newInstance(boolean withDefaults) {
275 return newBuilder(withDefaults).build();
276 }
277
278 /**
279 * Creates a new {@code DistributionManagement} builder instance.
280 * Equivalent to {@code newBuilder(true)}.
281 * @see #newBuilder(boolean)
282 *
283 * @return a new {@code Builder}
284 */
285 @Nonnull
286 public static Builder newBuilder() {
287 return newBuilder(true);
288 }
289
290 /**
291 * Creates a new {@code DistributionManagement} builder instance using default values or not.
292 *
293 * @param withDefaults the boolean indicating whether default values should be used
294 * @return a new {@code Builder}
295 */
296 @Nonnull
297 public static Builder newBuilder(boolean withDefaults) {
298 return new Builder(withDefaults);
299 }
300
301 /**
302 * Creates a new {@code DistributionManagement} builder instance using the specified object as a basis.
303 * Equivalent to {@code newBuilder(from, false)}.
304 *
305 * @param from the {@code DistributionManagement} instance to use as a basis
306 * @return a new {@code Builder}
307 */
308 @Nonnull
309 public static Builder newBuilder(DistributionManagement from) {
310 return newBuilder(from, false);
311 }
312
313 /**
314 * Creates a new {@code DistributionManagement} builder instance using the specified object as a basis.
315 *
316 * @param from the {@code DistributionManagement} instance to use as a basis
317 * @param forceCopy the boolean indicating if a copy should be forced
318 * @return a new {@code Builder}
319 */
320 @Nonnull
321 public static Builder newBuilder(DistributionManagement from, boolean forceCopy) {
322 return new Builder(from, forceCopy);
323 }
324
325 /**
326 * Builder class used to create DistributionManagement instances.
327 * @see #with()
328 * @see #newBuilder()
329 */
330 @NotThreadSafe
331 public static class Builder
332 {
333 DistributionManagement base;
334 DeploymentRepository repository;
335 DeploymentRepository snapshotRepository;
336 Site site;
337 String downloadUrl;
338 Relocation relocation;
339 String status;
340 Map<Object, InputLocation> locations;
341 InputLocation importedFrom;
342
343 protected Builder(boolean withDefaults) {
344 if (withDefaults) {
345 }
346 }
347
348 protected Builder(DistributionManagement base, boolean forceCopy) {
349 if (forceCopy) {
350 this.repository = base.repository;
351 this.snapshotRepository = base.snapshotRepository;
352 this.site = base.site;
353 this.downloadUrl = base.downloadUrl;
354 this.relocation = base.relocation;
355 this.status = base.status;
356 this.locations = base.locations;
357 this.importedFrom = base.importedFrom;
358 } else {
359 this.base = base;
360 }
361 }
362
363 @Nonnull
364 public Builder repository(DeploymentRepository repository) {
365 this.repository = repository;
366 return this;
367 }
368
369 @Nonnull
370 public Builder snapshotRepository(DeploymentRepository snapshotRepository) {
371 this.snapshotRepository = snapshotRepository;
372 return this;
373 }
374
375 @Nonnull
376 public Builder site(Site site) {
377 this.site = site;
378 return this;
379 }
380
381 @Nonnull
382 public Builder downloadUrl(String downloadUrl) {
383 this.downloadUrl = downloadUrl;
384 return this;
385 }
386
387 @Nonnull
388 public Builder relocation(Relocation relocation) {
389 this.relocation = relocation;
390 return this;
391 }
392
393 @Nonnull
394 public Builder status(String status) {
395 this.status = status;
396 return this;
397 }
398
399
400 @Nonnull
401 public Builder location(Object key, InputLocation location) {
402 if (location != null) {
403 if (!(this.locations instanceof HashMap)) {
404 this.locations = this.locations != null ? new HashMap<>(this.locations) : new HashMap<>();
405 }
406 this.locations.put(key, location);
407 }
408 return this;
409 }
410
411 @Nonnull
412 public Builder importedFrom(InputLocation importedFrom) {
413 this.importedFrom = importedFrom;
414 return this;
415 }
416
417 @Nonnull
418 public DistributionManagement build() {
419 // this method should not contain any logic other than creating (or reusing) an object in order to ease subclassing
420 if (base != null
421 && (repository == null || repository == base.repository)
422 && (snapshotRepository == null || snapshotRepository == base.snapshotRepository)
423 && (site == null || site == base.site)
424 && (downloadUrl == null || downloadUrl == base.downloadUrl)
425 && (relocation == null || relocation == base.relocation)
426 && (status == null || status == base.status)
427 ) {
428 return base;
429 }
430 return new DistributionManagement(this);
431 }
432
433 Map<Object, InputLocation> computeLocations() {
434 Map<Object, InputLocation> newlocs = locations != null ? locations : Map.of();
435 Map<Object, InputLocation> oldlocs = base != null ? base.locations : Map.of();
436 if (newlocs.isEmpty()) {
437 return Map.copyOf(oldlocs);
438 }
439 if (oldlocs.isEmpty()) {
440 return Map.copyOf(newlocs);
441 }
442 return Stream.concat(newlocs.entrySet().stream(), oldlocs.entrySet().stream())
443 // Keep value from newlocs in case of duplicates
444 .collect(Collectors.toUnmodifiableMap(Map.Entry::getKey, Map.Entry::getValue, (v1, v2) -> v1));
445 }
446 }
447
448 }