View Javadoc
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.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   * This elements describes all that pertains to distribution for a project. It is
21   * primarily used for deployment of artifacts and the site produced by the build.
22   */
23  @Experimental
24  @Generated @ThreadSafe @Immutable
25  public class DistributionManagement
26      implements Serializable, InputLocationTracker
27  {
28      /**
29       * Information needed to deploy the artifacts generated by the project to a
30       * remote repository.
31       */
32      final DeploymentRepository repository;
33      /**
34       * Where to deploy snapshots of artifacts to. If not given, it defaults to the
35       * {@code repository} element.
36       */
37      final DeploymentRepository snapshotRepository;
38      /**
39       * Information needed for deploying the web site of the project.
40       */
41      final Site site;
42      /**
43       * The URL of the project's download page. If not given users will be
44       * referred to the homepage given by {@code url}.
45       * This is given to assist in locating artifacts that are not in the repository due to
46       * licensing restrictions.
47       */
48      final String downloadUrl;
49      /**
50       * Relocation information of the artifact if it has been moved to a new group ID
51       * and/or artifact ID.
52       */
53      final Relocation relocation;
54      /**
55       * Gives the status of this artifact in the remote repository.
56       * This must not be set in your local project, as it is updated by
57       * tools placing it in the repository. Valid values are: {@code none} (default),
58       * {@code converted} (repository manager converted this from an Maven 1 POM),
59       * {@code partner}
60       * (directly synced from a partner Maven 2 repository), {@code deployed} (was deployed from a Maven 2
61       * instance), {@code verified} (has been hand verified as correct and final).
62       */
63      final String status;
64      /** Locations (this potentially hides the same name field from the super class) */
65      final Map<Object, InputLocation> locations;
66      /** Location tracking */
67      final InputLocation importedFrom;
68  
69      /**
70        * Constructor for this class, to be called from its subclasses and {@link Builder}.
71        * @see Builder#build()
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       * Information needed to deploy the artifacts generated by the project to a
96       * remote repository.
97       *
98       * @return a {@code DeploymentRepository}
99       */
100     public DeploymentRepository getRepository() {
101         return this.repository;
102     }
103 
104     /**
105      * Where to deploy snapshots of artifacts to. If not given, it defaults to the
106      * {@code repository} element.
107      *
108      * @return a {@code DeploymentRepository}
109      */
110     public DeploymentRepository getSnapshotRepository() {
111         return this.snapshotRepository;
112     }
113 
114     /**
115      * Information needed for deploying the web site of the project.
116      *
117      * @return a {@code Site}
118      */
119     public Site getSite() {
120         return this.site;
121     }
122 
123     /**
124      * The URL of the project's download page. If not given users will be
125      * referred to the homepage given by {@code url}.
126      * This is given to assist in locating artifacts that are not in the repository due to
127      * licensing restrictions.
128      *
129      * @return a {@code String}
130      */
131     public String getDownloadUrl() {
132         return this.downloadUrl;
133     }
134 
135     /**
136      * Relocation information of the artifact if it has been moved to a new group ID
137      * and/or artifact ID.
138      *
139      * @return a {@code Relocation}
140      */
141     public Relocation getRelocation() {
142         return this.relocation;
143     }
144 
145     /**
146      * Gives the status of this artifact in the remote repository.
147      * This must not be set in your local project, as it is updated by
148      * tools placing it in the repository. Valid values are: {@code none} (default),
149      * {@code converted} (repository manager converted this from an Maven 1 POM),
150      * {@code partner}
151      * (directly synced from a partner Maven 2 repository), {@code deployed} (was deployed from a Maven 2
152      * instance), {@code verified} (has been hand verified as correct and final).
153      *
154      * @return a {@code String}
155      */
156     public String getStatus() {
157         return this.status;
158     }
159 
160     /**
161      * Gets the location of the specified field in the input source.
162      */
163     public InputLocation getLocation(Object key) {
164         return locations != null ? locations.get(key) : null;
165     }
166 
167     /**
168     * Gets the keys of the locations of the input source.
169     */
170     public Set<Object> getLocationKeys() {
171         return locations != null ? locations.keySet() : null;
172     }
173 
174     /**
175      * Gets the input location that caused this model to be read.
176      */
177     public InputLocation getImportedFrom()
178     {
179         return importedFrom;
180     }
181 
182     /**
183      * Creates a new builder with this object as the basis.
184      *
185      * @return a {@code Builder}
186      */
187     @Nonnull
188     public Builder with() {
189         return newBuilder(this);
190     }
191     /**
192      * Creates a new {@code DistributionManagement} instance using the specified repository.
193      *
194      * @param repository the new {@code DeploymentRepository} to use
195      * @return a {@code DistributionManagement} with the specified repository
196      */
197     @Nonnull
198     public DistributionManagement withRepository(DeploymentRepository repository) {
199         return newBuilder(this, true).repository(repository).build();
200     }
201     /**
202      * Creates a new {@code DistributionManagement} instance using the specified snapshotRepository.
203      *
204      * @param snapshotRepository the new {@code DeploymentRepository} to use
205      * @return a {@code DistributionManagement} with the specified snapshotRepository
206      */
207     @Nonnull
208     public DistributionManagement withSnapshotRepository(DeploymentRepository snapshotRepository) {
209         return newBuilder(this, true).snapshotRepository(snapshotRepository).build();
210     }
211     /**
212      * Creates a new {@code DistributionManagement} instance using the specified site.
213      *
214      * @param site the new {@code Site} to use
215      * @return a {@code DistributionManagement} with the specified site
216      */
217     @Nonnull
218     public DistributionManagement withSite(Site site) {
219         return newBuilder(this, true).site(site).build();
220     }
221     /**
222      * Creates a new {@code DistributionManagement} instance using the specified downloadUrl.
223      *
224      * @param downloadUrl the new {@code String} to use
225      * @return a {@code DistributionManagement} with the specified downloadUrl
226      */
227     @Nonnull
228     public DistributionManagement withDownloadUrl(String downloadUrl) {
229         return newBuilder(this, true).downloadUrl(downloadUrl).build();
230     }
231     /**
232      * Creates a new {@code DistributionManagement} instance using the specified relocation.
233      *
234      * @param relocation the new {@code Relocation} to use
235      * @return a {@code DistributionManagement} with the specified relocation
236      */
237     @Nonnull
238     public DistributionManagement withRelocation(Relocation relocation) {
239         return newBuilder(this, true).relocation(relocation).build();
240     }
241     /**
242      * Creates a new {@code DistributionManagement} instance using the specified status.
243      *
244      * @param status the new {@code String} to use
245      * @return a {@code DistributionManagement} with the specified status
246      */
247     @Nonnull
248     public DistributionManagement withStatus(String status) {
249         return newBuilder(this, true).status(status).build();
250     }
251 
252     /**
253      * Creates a new {@code DistributionManagement} instance.
254      * Equivalent to {@code newInstance(true)}.
255      * @see #newInstance(boolean)
256      *
257      * @return a new {@code DistributionManagement}
258      */
259     @Nonnull
260     public static DistributionManagement newInstance() {
261         return newInstance(true);
262     }
263 
264     /**
265      * Creates a new {@code DistributionManagement} instance using default values or not.
266      * Equivalent to {@code newBuilder(withDefaults).build()}.
267      *
268      * @param withDefaults the boolean indicating whether default values should be used
269      * @return a new {@code DistributionManagement}
270      */
271     @Nonnull
272     public static DistributionManagement newInstance(boolean withDefaults) {
273         return newBuilder(withDefaults).build();
274     }
275 
276     /**
277      * Creates a new {@code DistributionManagement} builder instance.
278      * Equivalent to {@code newBuilder(true)}.
279      * @see #newBuilder(boolean)
280      *
281      * @return a new {@code Builder}
282      */
283     @Nonnull
284     public static Builder newBuilder() {
285         return newBuilder(true);
286     }
287 
288     /**
289      * Creates a new {@code DistributionManagement} builder instance using default values or not.
290      *
291      * @param withDefaults the boolean indicating whether default values should be used
292      * @return a new {@code Builder}
293      */
294     @Nonnull
295     public static Builder newBuilder(boolean withDefaults) {
296         return new Builder(withDefaults);
297     }
298 
299     /**
300      * Creates a new {@code DistributionManagement} builder instance using the specified object as a basis.
301      * Equivalent to {@code newBuilder(from, false)}.
302      *
303      * @param from the {@code DistributionManagement} instance to use as a basis
304      * @return a new {@code Builder}
305      */
306     @Nonnull
307     public static Builder newBuilder(DistributionManagement from) {
308         return newBuilder(from, false);
309     }
310 
311     /**
312      * Creates a new {@code DistributionManagement} builder instance using the specified object as a basis.
313      *
314      * @param from the {@code DistributionManagement} instance to use as a basis
315      * @param forceCopy the boolean indicating if a copy should be forced
316      * @return a new {@code Builder}
317      */
318     @Nonnull
319     public static Builder newBuilder(DistributionManagement from, boolean forceCopy) {
320         return new Builder(from, forceCopy);
321     }
322 
323     /**
324      * Builder class used to create DistributionManagement instances.
325      * @see #with()
326      * @see #newBuilder()
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             // this method should not contain any logic other than creating (or reusing) an object in order to ease subclassing
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 }