View Javadoc
1   // =================== DO NOT EDIT THIS FILE ====================
2   //   Generated by Maven, any modifications will be overwritten.
3   // ==============================================================
4   package org.apache.maven.api.model;
5   
6   import java.io.Serializable;
7   import java.util.Collections;
8   import java.util.HashMap;
9   import java.util.Map;
10  import org.apache.maven.api.annotations.Experimental;
11  import org.apache.maven.api.annotations.Generated;
12  import org.apache.maven.api.annotations.Immutable;
13  import org.apache.maven.api.annotations.Nonnull;
14  import org.apache.maven.api.annotations.NotThreadSafe;
15  import org.apache.maven.api.annotations.ThreadSafe;
16  
17  /**
18   * This elements describes all that pertains to distribution for a project. It is
19   * primarily used for deployment of artifacts and the site produced by the build.
20   */
21  @Experimental
22  @Generated @ThreadSafe @Immutable
23  public class DistributionManagement
24      implements Serializable, InputLocationTracker
25  {
26      /**
27       * Information needed to deploy the artifacts generated by the project to a
28       * remote repository.
29       */
30      final DeploymentRepository repository;
31      /**
32       * Where to deploy snapshots of artifacts to. If not given, it defaults to the
33       * {@code repository} element.
34       */
35      final DeploymentRepository snapshotRepository;
36      /**
37       * Information needed for deploying the web site of the project.
38       */
39      final Site site;
40      /**
41       * The URL of the project's download page. If not given users will be
42       * referred to the homepage given by {@code url}.
43       * This is given to assist in locating artifacts that are not in the repository due to
44       * licensing restrictions.
45       */
46      final String downloadUrl;
47      /**
48       * Relocation information of the artifact if it has been moved to a new group ID
49       * and/or artifact ID.
50       */
51      final Relocation relocation;
52      /**
53       * Gives the status of this artifact in the remote repository.
54       * This must not be set in your local project, as it is updated by
55       * tools placing it in the reposiory. Valid values are: {@code none} (default),
56       * {@code converted} (repository manager converted this from an Maven 1 POM),
57       * {@code partner}
58       * (directly synced from a partner Maven 2 repository), {@code deployed} (was deployed from a Maven 2
59       * instance), {@code verified} (has been hand verified as correct and final).
60       */
61      final String status;
62      /** Location of the xml element for this object. */
63      final InputLocation location;
64      /** Location of the xml element for the field repository. */
65      final InputLocation repositoryLocation;
66      /** Location of the xml element for the field snapshotRepository. */
67      final InputLocation snapshotRepositoryLocation;
68      /** Location of the xml element for the field site. */
69      final InputLocation siteLocation;
70      /** Location of the xml element for the field downloadUrl. */
71      final InputLocation downloadUrlLocation;
72      /** Location of the xml element for the field relocation. */
73      final InputLocation relocationLocation;
74      /** Location of the xml element for the field status. */
75      final InputLocation statusLocation;
76      /** Other locations */
77      final Map<Object, InputLocation> locations;
78  
79      /**
80        * Constructor for this class, package protected.
81        * @see Builder#build()
82        */
83      DistributionManagement(
84          DeploymentRepository repository,
85          DeploymentRepository snapshotRepository,
86          Site site,
87          String downloadUrl,
88          Relocation relocation,
89          String status,
90          Map<Object, InputLocation> locations,
91          InputLocation location,
92          InputLocation repositoryLocation,
93          InputLocation snapshotRepositoryLocation,
94          InputLocation siteLocation,
95          InputLocation downloadUrlLocation,
96          InputLocation relocationLocation,
97          InputLocation statusLocation
98      )
99      {
100         this.repository = repository;
101         this.snapshotRepository = snapshotRepository;
102         this.site = site;
103         this.downloadUrl = downloadUrl;
104         this.relocation = relocation;
105         this.status = status;
106         this.locations = ImmutableCollections.copy( locations );
107         this.location = location;
108         this.repositoryLocation = repositoryLocation;
109         this.snapshotRepositoryLocation = snapshotRepositoryLocation;
110         this.siteLocation = siteLocation;
111         this.downloadUrlLocation = downloadUrlLocation;
112         this.relocationLocation = relocationLocation;
113         this.statusLocation = statusLocation;
114     }
115 
116     /**
117      * Information needed to deploy the artifacts generated by the project to a
118      * remote repository.
119      *
120      * @return a {@code DeploymentRepository}
121      */
122     public DeploymentRepository getRepository()
123     {
124         return this.repository;
125     }
126 
127     /**
128      * Where to deploy snapshots of artifacts to. If not given, it defaults to the
129      * {@code repository} element.
130      *
131      * @return a {@code DeploymentRepository}
132      */
133     public DeploymentRepository getSnapshotRepository()
134     {
135         return this.snapshotRepository;
136     }
137 
138     /**
139      * Information needed for deploying the web site of the project.
140      *
141      * @return a {@code Site}
142      */
143     public Site getSite()
144     {
145         return this.site;
146     }
147 
148     /**
149      * The URL of the project's download page. If not given users will be
150      * referred to the homepage given by {@code url}.
151      * This is given to assist in locating artifacts that are not in the repository due to
152      * licensing restrictions.
153      *
154      * @return a {@code String}
155      */
156     public String getDownloadUrl()
157     {
158         return this.downloadUrl;
159     }
160 
161     /**
162      * Relocation information of the artifact if it has been moved to a new group ID
163      * and/or artifact ID.
164      *
165      * @return a {@code Relocation}
166      */
167     public Relocation getRelocation()
168     {
169         return this.relocation;
170     }
171 
172     /**
173      * Gives the status of this artifact in the remote repository.
174      * This must not be set in your local project, as it is updated by
175      * tools placing it in the reposiory. Valid values are: {@code none} (default),
176      * {@code converted} (repository manager converted this from an Maven 1 POM),
177      * {@code partner}
178      * (directly synced from a partner Maven 2 repository), {@code deployed} (was deployed from a Maven 2
179      * instance), {@code verified} (has been hand verified as correct and final).
180      *
181      * @return a {@code String}
182      */
183     public String getStatus()
184     {
185         return this.status;
186     }
187 
188     /**
189      * Gets the location of the specified field in the input source.
190      */
191     public InputLocation getLocation( Object key )
192     {
193         if ( key instanceof String )
194         {
195             switch ( ( String ) key )
196             {
197                 case "":
198                     return location;
199                 case "repository":
200                     return repositoryLocation;
201                 case "snapshotRepository":
202                     return snapshotRepositoryLocation;
203                 case "site":
204                     return siteLocation;
205                 case "downloadUrl":
206                     return downloadUrlLocation;
207                 case "relocation":
208                     return relocationLocation;
209                 case "status":
210                     return statusLocation;
211             }
212         }
213         return locations != null ? locations.get( key ) : null;
214     }
215 
216     /**
217      * Creates a new builder with this object as the basis.
218      *
219      * @return a {@code Builder}
220      */
221     @Nonnull
222     public Builder with()
223     {
224         return newBuilder( this );
225     }
226     /**
227      * Creates a new {@code DistributionManagement} instance using the specified repository.
228      *
229      * @param repository the new {@code DeploymentRepository} to use
230      * @return a {@code DistributionManagement} with the specified repository
231      */
232     @Nonnull
233     public DistributionManagement withRepository( DeploymentRepository repository )
234     {
235         return with().repository( repository ).build();
236     }
237     /**
238      * Creates a new {@code DistributionManagement} instance using the specified snapshotRepository.
239      *
240      * @param snapshotRepository the new {@code DeploymentRepository} to use
241      * @return a {@code DistributionManagement} with the specified snapshotRepository
242      */
243     @Nonnull
244     public DistributionManagement withSnapshotRepository( DeploymentRepository snapshotRepository )
245     {
246         return with().snapshotRepository( snapshotRepository ).build();
247     }
248     /**
249      * Creates a new {@code DistributionManagement} instance using the specified site.
250      *
251      * @param site the new {@code Site} to use
252      * @return a {@code DistributionManagement} with the specified site
253      */
254     @Nonnull
255     public DistributionManagement withSite( Site site )
256     {
257         return with().site( site ).build();
258     }
259     /**
260      * Creates a new {@code DistributionManagement} instance using the specified downloadUrl.
261      *
262      * @param downloadUrl the new {@code String} to use
263      * @return a {@code DistributionManagement} with the specified downloadUrl
264      */
265     @Nonnull
266     public DistributionManagement withDownloadUrl( String downloadUrl )
267     {
268         return with().downloadUrl( downloadUrl ).build();
269     }
270     /**
271      * Creates a new {@code DistributionManagement} instance using the specified relocation.
272      *
273      * @param relocation the new {@code Relocation} to use
274      * @return a {@code DistributionManagement} with the specified relocation
275      */
276     @Nonnull
277     public DistributionManagement withRelocation( Relocation relocation )
278     {
279         return with().relocation( relocation ).build();
280     }
281     /**
282      * Creates a new {@code DistributionManagement} instance using the specified status.
283      *
284      * @param status the new {@code String} to use
285      * @return a {@code DistributionManagement} with the specified status
286      */
287     @Nonnull
288     public DistributionManagement withStatus( String status )
289     {
290         return with().status( status ).build();
291     }
292 
293     /**
294      * Creates a new {@code DistributionManagement} instance.
295      * Equivalent to {@code newInstance( true )}.
296      * @see #newInstance(boolean)
297      *
298      * @return a new {@code DistributionManagement}
299      */
300     @Nonnull
301     public static DistributionManagement newInstance()
302     {
303         return newInstance( true );
304     }
305 
306     /**
307      * Creates a new {@code DistributionManagement} instance using default values or not.
308      * Equivalent to {@code newBuilder( withDefaults ).build()}.
309      *
310      * @param withDefaults the boolean indicating whether default values should be used
311      * @return a new {@code DistributionManagement}
312      */
313     @Nonnull
314     public static DistributionManagement newInstance( boolean withDefaults )
315     {
316         return newBuilder( withDefaults ).build();
317     }
318 
319     /**
320      * Creates a new {@code DistributionManagement} builder instance.
321      * Equivalent to {@code newBuilder( true )}.
322      * @see #newBuilder(boolean)
323      *
324      * @return a new {@code Builder}
325      */
326     @Nonnull
327     public static Builder newBuilder()
328     {
329         return newBuilder( true );
330     }
331 
332     /**
333      * Creates a new {@code DistributionManagement} builder instance using default values or not.
334      *
335      * @param withDefaults the boolean indicating whether default values should be used
336      * @return a new {@code Builder}
337      */
338     @Nonnull
339     public static Builder newBuilder( boolean withDefaults )
340     {
341         return new Builder( withDefaults );
342     }
343 
344     /**
345      * Creates a new {@code DistributionManagement} builder instance using the specified object as a basis.
346      * Equivalent to {@code newBuilder( from, false )}.
347      *
348      * @param from the {@code DistributionManagement} instance to use as a basis
349      * @return a new {@code Builder}
350      */
351     @Nonnull
352     public static Builder newBuilder( DistributionManagement from )
353     {
354         return newBuilder( from, false );
355     }
356 
357     /**
358      * Creates a new {@code DistributionManagement} builder instance using the specified object as a basis.
359      *
360      * @param from the {@code DistributionManagement} instance to use as a basis
361      * @param forceCopy the boolean indicating if a copy should be forced
362      * @return a new {@code Builder}
363      */
364     @Nonnull
365     public static Builder newBuilder( DistributionManagement from, boolean forceCopy )
366     {
367         return new Builder( from, forceCopy );
368     }
369 
370     /**
371      * Builder class used to create DistributionManagement instances.
372      * @see #with()
373      * @see #newBuilder()
374      */
375     @NotThreadSafe
376     public static class Builder
377     {
378         DistributionManagement base;
379         DeploymentRepository repository;
380         DeploymentRepository snapshotRepository;
381         Site site;
382         String downloadUrl;
383         Relocation relocation;
384         String status;
385         Map<Object, InputLocation> locations;
386 
387         Builder( boolean withDefaults )
388         {
389             if ( withDefaults )
390             {
391             }
392         }
393 
394         Builder( DistributionManagement base, boolean forceCopy )
395         {
396             if ( forceCopy )
397             {
398                 this.repository = base.repository;
399                 this.snapshotRepository = base.snapshotRepository;
400                 this.site = base.site;
401                 this.downloadUrl = base.downloadUrl;
402                 this.relocation = base.relocation;
403                 this.status = base.status;
404             }
405             else
406             {
407                 this.base = base;
408             }
409         }
410 
411         @Nonnull
412         public Builder repository( DeploymentRepository repository )
413         {
414             this.repository = repository;
415             return this;
416         }
417 
418         @Nonnull
419         public Builder snapshotRepository( DeploymentRepository snapshotRepository )
420         {
421             this.snapshotRepository = snapshotRepository;
422             return this;
423         }
424 
425         @Nonnull
426         public Builder site( Site site )
427         {
428             this.site = site;
429             return this;
430         }
431 
432         @Nonnull
433         public Builder downloadUrl( String downloadUrl )
434         {
435             this.downloadUrl = downloadUrl;
436             return this;
437         }
438 
439         @Nonnull
440         public Builder relocation( Relocation relocation )
441         {
442             this.relocation = relocation;
443             return this;
444         }
445 
446         @Nonnull
447         public Builder status( String status )
448         {
449             this.status = status;
450             return this;
451         }
452 
453 
454         @Nonnull
455         public Builder location( Object key, InputLocation location )
456         {
457             if ( location != null )
458             {
459                 if ( this.locations == null )
460                 {
461                     this.locations = new HashMap<>();
462                 }
463                 this.locations.put( key, location );
464             }
465             return this;
466         }
467 
468         @Nonnull
469         public DistributionManagement build()
470         {
471             if ( base != null
472                     && ( repository == null || repository == base.repository )
473                     && ( snapshotRepository == null || snapshotRepository == base.snapshotRepository )
474                     && ( site == null || site == base.site )
475                     && ( downloadUrl == null || downloadUrl == base.downloadUrl )
476                     && ( relocation == null || relocation == base.relocation )
477                     && ( status == null || status == base.status )
478             )
479             {
480                 return base;
481             }
482             Map<Object, InputLocation> locations = null;
483             InputLocation location = null;
484             InputLocation repositoryLocation = null;
485             InputLocation snapshotRepositoryLocation = null;
486             InputLocation siteLocation = null;
487             InputLocation downloadUrlLocation = null;
488             InputLocation relocationLocation = null;
489             InputLocation statusLocation = null;
490             if ( this.locations != null )
491             {
492                 locations = this.locations;
493                 location = locations.remove( "" );
494                 repositoryLocation = locations.remove( "repository" );
495                 snapshotRepositoryLocation = locations.remove( "snapshotRepository" );
496                 siteLocation = locations.remove( "site" );
497                 downloadUrlLocation = locations.remove( "downloadUrl" );
498                 relocationLocation = locations.remove( "relocation" );
499                 statusLocation = locations.remove( "status" );
500             }
501             return new DistributionManagement(
502                 repository != null ? repository : ( base != null ? base.repository : null ),
503                 snapshotRepository != null ? snapshotRepository : ( base != null ? base.snapshotRepository : null ),
504                 site != null ? site : ( base != null ? base.site : null ),
505                 downloadUrl != null ? downloadUrl : ( base != null ? base.downloadUrl : null ),
506                 relocation != null ? relocation : ( base != null ? base.relocation : null ),
507                 status != null ? status : ( base != null ? base.status : null ),
508                 locations != null ? locations : ( base != null ? base.locations : null ),
509                 location != null ? location : ( base != null ? base.location : null ),
510                 repositoryLocation != null ? repositoryLocation : ( base != null ? base.repositoryLocation : null ),
511                 snapshotRepositoryLocation != null ? snapshotRepositoryLocation : ( base != null ? base.snapshotRepositoryLocation : null ),
512                 siteLocation != null ? siteLocation : ( base != null ? base.siteLocation : null ),
513                 downloadUrlLocation != null ? downloadUrlLocation : ( base != null ? base.downloadUrlLocation : null ),
514                 relocationLocation != null ? relocationLocation : ( base != null ? base.relocationLocation : null ),
515                 statusLocation != null ? statusLocation : ( base != null ? base.statusLocation : null )
516             );
517         }
518     }
519 
520 }