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