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