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 org.apache.maven.api.annotations.Experimental;
12 import org.apache.maven.api.annotations.Generated;
13 import org.apache.maven.api.annotations.Immutable;
14 import org.apache.maven.api.annotations.Nonnull;
15 import org.apache.maven.api.annotations.NotThreadSafe;
16 import org.apache.maven.api.annotations.ThreadSafe;
17
18 /**
19 * This elements describes all that pertains to distribution for a project. It is
20 * primarily used for deployment of artifacts and the site produced by the build.
21 */
22 @Experimental
23 @Generated @ThreadSafe @Immutable
24 public class DistributionManagement
25 implements Serializable, InputLocationTracker
26 {
27 /**
28 * Information needed to deploy the artifacts generated by the project to a
29 * remote repository.
30 */
31 final DeploymentRepository repository;
32 /**
33 * Where to deploy snapshots of artifacts to. If not given, it defaults to the
34 * {@code repository} element.
35 */
36 final DeploymentRepository snapshotRepository;
37 /**
38 * Information needed for deploying the web site of the project.
39 */
40 final Site site;
41 /**
42 * The URL of the project's download page. If not given users will be
43 * referred to the homepage given by {@code url}.
44 * This is given to assist in locating artifacts that are not in the repository due to
45 * licensing restrictions.
46 */
47 final String downloadUrl;
48 /**
49 * Relocation information of the artifact if it has been moved to a new group ID
50 * and/or artifact ID.
51 */
52 final Relocation relocation;
53 /**
54 * Gives the status of this artifact in the remote repository.
55 * This must not be set in your local project, as it is updated by
56 * tools placing it in the repository. Valid values are: {@code none} (default),
57 * {@code converted} (repository manager converted this from an Maven 1 POM),
58 * {@code partner}
59 * (directly synced from a partner Maven 2 repository), {@code deployed} (was deployed from a Maven 2
60 * instance), {@code verified} (has been hand verified as correct and final).
61 */
62 final String status;
63 /** Locations */
64 final Map<Object, InputLocation> locations;
65
66 /**
67 * Constructor for this class, package protected.
68 * @see Builder#build()
69 */
70 DistributionManagement(
71 DeploymentRepository repository,
72 DeploymentRepository snapshotRepository,
73 Site site,
74 String downloadUrl,
75 Relocation relocation,
76 String status,
77 Map<Object, InputLocation> locations
78 ) {
79 this.repository = repository;
80 this.snapshotRepository = snapshotRepository;
81 this.site = site;
82 this.downloadUrl = downloadUrl;
83 this.relocation = relocation;
84 this.status = status;
85 this.locations = ImmutableCollections.copy(locations);
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 an 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 public InputLocation getLocation(Object key) {
158 return locations != null ? locations.get(key) : null;
159 }
160
161 /**
162 * Creates a new builder with this object as the basis.
163 *
164 * @return a {@code Builder}
165 */
166 @Nonnull
167 public Builder with() {
168 return newBuilder(this);
169 }
170 /**
171 * Creates a new {@code DistributionManagement} instance using the specified repository.
172 *
173 * @param repository the new {@code DeploymentRepository} to use
174 * @return a {@code DistributionManagement} with the specified repository
175 */
176 @Nonnull
177 public DistributionManagement withRepository(DeploymentRepository repository) {
178 return newBuilder(this, true).repository(repository).build();
179 }
180 /**
181 * Creates a new {@code DistributionManagement} instance using the specified snapshotRepository.
182 *
183 * @param snapshotRepository the new {@code DeploymentRepository} to use
184 * @return a {@code DistributionManagement} with the specified snapshotRepository
185 */
186 @Nonnull
187 public DistributionManagement withSnapshotRepository(DeploymentRepository snapshotRepository) {
188 return newBuilder(this, true).snapshotRepository(snapshotRepository).build();
189 }
190 /**
191 * Creates a new {@code DistributionManagement} instance using the specified site.
192 *
193 * @param site the new {@code Site} to use
194 * @return a {@code DistributionManagement} with the specified site
195 */
196 @Nonnull
197 public DistributionManagement withSite(Site site) {
198 return newBuilder(this, true).site(site).build();
199 }
200 /**
201 * Creates a new {@code DistributionManagement} instance using the specified downloadUrl.
202 *
203 * @param downloadUrl the new {@code String} to use
204 * @return a {@code DistributionManagement} with the specified downloadUrl
205 */
206 @Nonnull
207 public DistributionManagement withDownloadUrl(String downloadUrl) {
208 return newBuilder(this, true).downloadUrl(downloadUrl).build();
209 }
210 /**
211 * Creates a new {@code DistributionManagement} instance using the specified relocation.
212 *
213 * @param relocation the new {@code Relocation} to use
214 * @return a {@code DistributionManagement} with the specified relocation
215 */
216 @Nonnull
217 public DistributionManagement withRelocation(Relocation relocation) {
218 return newBuilder(this, true).relocation(relocation).build();
219 }
220 /**
221 * Creates a new {@code DistributionManagement} instance using the specified status.
222 *
223 * @param status the new {@code String} to use
224 * @return a {@code DistributionManagement} with the specified status
225 */
226 @Nonnull
227 public DistributionManagement withStatus(String status) {
228 return newBuilder(this, true).status(status).build();
229 }
230
231 /**
232 * Creates a new {@code DistributionManagement} instance.
233 * Equivalent to {@code newInstance(true)}.
234 * @see #newInstance(boolean)
235 *
236 * @return a new {@code DistributionManagement}
237 */
238 @Nonnull
239 public static DistributionManagement newInstance() {
240 return newInstance(true);
241 }
242
243 /**
244 * Creates a new {@code DistributionManagement} instance using default values or not.
245 * Equivalent to {@code newBuilder(withDefaults).build()}.
246 *
247 * @param withDefaults the boolean indicating whether default values should be used
248 * @return a new {@code DistributionManagement}
249 */
250 @Nonnull
251 public static DistributionManagement newInstance(boolean withDefaults) {
252 return newBuilder(withDefaults).build();
253 }
254
255 /**
256 * Creates a new {@code DistributionManagement} builder instance.
257 * Equivalent to {@code newBuilder(true)}.
258 * @see #newBuilder(boolean)
259 *
260 * @return a new {@code Builder}
261 */
262 @Nonnull
263 public static Builder newBuilder() {
264 return newBuilder(true);
265 }
266
267 /**
268 * Creates a new {@code DistributionManagement} builder instance using default values or not.
269 *
270 * @param withDefaults the boolean indicating whether default values should be used
271 * @return a new {@code Builder}
272 */
273 @Nonnull
274 public static Builder newBuilder(boolean withDefaults) {
275 return new Builder(withDefaults);
276 }
277
278 /**
279 * Creates a new {@code DistributionManagement} builder instance using the specified object as a basis.
280 * Equivalent to {@code newBuilder(from, false)}.
281 *
282 * @param from the {@code DistributionManagement} instance to use as a basis
283 * @return a new {@code Builder}
284 */
285 @Nonnull
286 public static Builder newBuilder(DistributionManagement from) {
287 return newBuilder(from, false);
288 }
289
290 /**
291 * Creates a new {@code DistributionManagement} builder instance using the specified object as a basis.
292 *
293 * @param from the {@code DistributionManagement} instance to use as a basis
294 * @param forceCopy the boolean indicating if a copy should be forced
295 * @return a new {@code Builder}
296 */
297 @Nonnull
298 public static Builder newBuilder(DistributionManagement from, boolean forceCopy) {
299 return new Builder(from, forceCopy);
300 }
301
302 /**
303 * Builder class used to create DistributionManagement instances.
304 * @see #with()
305 * @see #newBuilder()
306 */
307 @NotThreadSafe
308 public static class Builder
309 {
310 DistributionManagement base;
311 DeploymentRepository repository;
312 DeploymentRepository snapshotRepository;
313 Site site;
314 String downloadUrl;
315 Relocation relocation;
316 String status;
317 Map<Object, InputLocation> locations;
318
319 Builder(boolean withDefaults) {
320 if (withDefaults) {
321 }
322 }
323
324 Builder(DistributionManagement base, boolean forceCopy) {
325 if (forceCopy) {
326 this.repository = base.repository;
327 this.snapshotRepository = base.snapshotRepository;
328 this.site = base.site;
329 this.downloadUrl = base.downloadUrl;
330 this.relocation = base.relocation;
331 this.status = base.status;
332 this.locations = base.locations;
333 } else {
334 this.base = base;
335 }
336 }
337
338 @Nonnull
339 public Builder repository(DeploymentRepository repository) {
340 this.repository = repository;
341 return this;
342 }
343
344 @Nonnull
345 public Builder snapshotRepository(DeploymentRepository snapshotRepository) {
346 this.snapshotRepository = snapshotRepository;
347 return this;
348 }
349
350 @Nonnull
351 public Builder site(Site site) {
352 this.site = site;
353 return this;
354 }
355
356 @Nonnull
357 public Builder downloadUrl(String downloadUrl) {
358 this.downloadUrl = downloadUrl;
359 return this;
360 }
361
362 @Nonnull
363 public Builder relocation(Relocation relocation) {
364 this.relocation = relocation;
365 return this;
366 }
367
368 @Nonnull
369 public Builder status(String status) {
370 this.status = status;
371 return this;
372 }
373
374
375 @Nonnull
376 public Builder location(Object key, InputLocation location) {
377 if (location != null) {
378 if (!(this.locations instanceof HashMap)) {
379 this.locations = this.locations != null ? new HashMap<>(this.locations) : new HashMap<>();
380 }
381 this.locations.put(key, location);
382 }
383 return this;
384 }
385
386 @Nonnull
387 public DistributionManagement build() {
388 if (base != null
389 && (repository == null || repository == base.repository)
390 && (snapshotRepository == null || snapshotRepository == base.snapshotRepository)
391 && (site == null || site == base.site)
392 && (downloadUrl == null || downloadUrl == base.downloadUrl)
393 && (relocation == null || relocation == base.relocation)
394 && (status == null || status == base.status)
395 ) {
396 return base;
397 }
398 Map<Object, InputLocation> newlocs = this.locations != null ? this.locations : Collections.emptyMap();
399 Map<Object, InputLocation> oldlocs = this.base != null && this.base.locations != null ? this.base.locations : Collections.emptyMap();
400 Map<Object, InputLocation> locations = new HashMap<>();
401 locations.put("", newlocs.containsKey("") ? newlocs.get("") : oldlocs.get(""));
402 locations.put("repository", newlocs.containsKey("repository") ? newlocs.get("repository") : oldlocs.get("repository"));
403 locations.put("snapshotRepository", newlocs.containsKey("snapshotRepository") ? newlocs.get("snapshotRepository") : oldlocs.get("snapshotRepository"));
404 locations.put("site", newlocs.containsKey("site") ? newlocs.get("site") : oldlocs.get("site"));
405 locations.put("downloadUrl", newlocs.containsKey("downloadUrl") ? newlocs.get("downloadUrl") : oldlocs.get("downloadUrl"));
406 locations.put("relocation", newlocs.containsKey("relocation") ? newlocs.get("relocation") : oldlocs.get("relocation"));
407 locations.put("status", newlocs.containsKey("status") ? newlocs.get("status") : oldlocs.get("status"));
408 return new DistributionManagement(
409 repository != null ? repository : (base != null ? base.repository : null),
410 snapshotRepository != null ? snapshotRepository : (base != null ? base.snapshotRepository : null),
411 site != null ? site : (base != null ? base.site : null),
412 downloadUrl != null ? downloadUrl : (base != null ? base.downloadUrl : null),
413 relocation != null ? relocation : (base != null ? base.relocation : null),
414 status != null ? status : (base != null ? base.status : null),
415 locations
416 );
417 }
418 }
419
420 }