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