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   * Describes the licenses for this project. This is used to generate the license
19   * page of the project's web site, as well as being taken into consideration in other reporting
20   * and validation. The licenses listed for the project are that of the project itself, and not
21   * of dependencies.
22   */
23  @Experimental
24  @Generated @ThreadSafe @Immutable
25  public class License
26      implements Serializable, InputLocationTracker
27  {
28      /**
29       * The full legal name of the license.
30       */
31      final String name;
32      /**
33       * The official url for the license text.
34       */
35      final String url;
36      /**
37       * The primary method by which this project may be distributed.
38       * <dl>
39       * <dt>repo</dt>
40       * <dd>may be downloaded from the Maven repository</dd>
41       * <dt>manual</dt>
42       * <dd>user must manually download and install the dependency.</dd>
43       * </dl>
44       */
45      final String distribution;
46      /**
47       * Addendum information pertaining to this license.
48       */
49      final String comments;
50      /** Location of the xml element for this object. */
51      final InputLocation location;
52      /** Location of the xml element for the field name. */
53      final InputLocation nameLocation;
54      /** Location of the xml element for the field url. */
55      final InputLocation urlLocation;
56      /** Location of the xml element for the field distribution. */
57      final InputLocation distributionLocation;
58      /** Location of the xml element for the field comments. */
59      final InputLocation commentsLocation;
60      /** Other locations */
61      final Map<Object, InputLocation> locations;
62  
63      /**
64        * Constructor for this class, package protected.
65        * @see Builder#build()
66        */
67      License(
68          String name,
69          String url,
70          String distribution,
71          String comments,
72          Map<Object, InputLocation> locations,
73          InputLocation location,
74          InputLocation nameLocation,
75          InputLocation urlLocation,
76          InputLocation distributionLocation,
77          InputLocation commentsLocation
78      )
79      {
80          this.name = name;
81          this.url = url;
82          this.distribution = distribution;
83          this.comments = comments;
84          this.locations = ImmutableCollections.copy( locations );
85          this.location = location;
86          this.nameLocation = nameLocation;
87          this.urlLocation = urlLocation;
88          this.distributionLocation = distributionLocation;
89          this.commentsLocation = commentsLocation;
90      }
91  
92      /**
93       * The full legal name of the license.
94       *
95       * @return a {@code String}
96       */
97      public String getName()
98      {
99          return this.name;
100     }
101 
102     /**
103      * The official url for the license text.
104      *
105      * @return a {@code String}
106      */
107     public String getUrl()
108     {
109         return this.url;
110     }
111 
112     /**
113      * The primary method by which this project may be distributed.
114      * <dl>
115      * <dt>repo</dt>
116      * <dd>may be downloaded from the Maven repository</dd>
117      * <dt>manual</dt>
118      * <dd>user must manually download and install the dependency.</dd>
119      * </dl>
120      *
121      * @return a {@code String}
122      */
123     public String getDistribution()
124     {
125         return this.distribution;
126     }
127 
128     /**
129      * Addendum information pertaining to this license.
130      *
131      * @return a {@code String}
132      */
133     public String getComments()
134     {
135         return this.comments;
136     }
137 
138     /**
139      * Gets the location of the specified field in the input source.
140      */
141     public InputLocation getLocation( Object key )
142     {
143         if ( key instanceof String )
144         {
145             switch ( ( String ) key )
146             {
147                 case "":
148                     return location;
149                 case "name":
150                     return nameLocation;
151                 case "url":
152                     return urlLocation;
153                 case "distribution":
154                     return distributionLocation;
155                 case "comments":
156                     return commentsLocation;
157             }
158         }
159         return locations != null ? locations.get( key ) : null;
160     }
161 
162     /**
163      * Creates a new builder with this object as the basis.
164      *
165      * @return a {@code Builder}
166      */
167     @Nonnull
168     public Builder with()
169     {
170         return newBuilder( this );
171     }
172     /**
173      * Creates a new {@code License} instance using the specified name.
174      *
175      * @param name the new {@code String} to use
176      * @return a {@code License} with the specified name
177      */
178     @Nonnull
179     public License withName( String name )
180     {
181         return with().name( name ).build();
182     }
183     /**
184      * Creates a new {@code License} instance using the specified url.
185      *
186      * @param url the new {@code String} to use
187      * @return a {@code License} with the specified url
188      */
189     @Nonnull
190     public License withUrl( String url )
191     {
192         return with().url( url ).build();
193     }
194     /**
195      * Creates a new {@code License} instance using the specified distribution.
196      *
197      * @param distribution the new {@code String} to use
198      * @return a {@code License} with the specified distribution
199      */
200     @Nonnull
201     public License withDistribution( String distribution )
202     {
203         return with().distribution( distribution ).build();
204     }
205     /**
206      * Creates a new {@code License} instance using the specified comments.
207      *
208      * @param comments the new {@code String} to use
209      * @return a {@code License} with the specified comments
210      */
211     @Nonnull
212     public License withComments( String comments )
213     {
214         return with().comments( comments ).build();
215     }
216 
217     /**
218      * Creates a new {@code License} instance.
219      * Equivalent to {@code newInstance( true )}.
220      * @see #newInstance(boolean)
221      *
222      * @return a new {@code License}
223      */
224     @Nonnull
225     public static License newInstance()
226     {
227         return newInstance( true );
228     }
229 
230     /**
231      * Creates a new {@code License} instance using default values or not.
232      * Equivalent to {@code newBuilder( withDefaults ).build()}.
233      *
234      * @param withDefaults the boolean indicating whether default values should be used
235      * @return a new {@code License}
236      */
237     @Nonnull
238     public static License newInstance( boolean withDefaults )
239     {
240         return newBuilder( withDefaults ).build();
241     }
242 
243     /**
244      * Creates a new {@code License} builder instance.
245      * Equivalent to {@code newBuilder( true )}.
246      * @see #newBuilder(boolean)
247      *
248      * @return a new {@code Builder}
249      */
250     @Nonnull
251     public static Builder newBuilder()
252     {
253         return newBuilder( true );
254     }
255 
256     /**
257      * Creates a new {@code License} builder instance using default values or not.
258      *
259      * @param withDefaults the boolean indicating whether default values should be used
260      * @return a new {@code Builder}
261      */
262     @Nonnull
263     public static Builder newBuilder( boolean withDefaults )
264     {
265         return new Builder( withDefaults );
266     }
267 
268     /**
269      * Creates a new {@code License} builder instance using the specified object as a basis.
270      * Equivalent to {@code newBuilder( from, false )}.
271      *
272      * @param from the {@code License} instance to use as a basis
273      * @return a new {@code Builder}
274      */
275     @Nonnull
276     public static Builder newBuilder( License from )
277     {
278         return newBuilder( from, false );
279     }
280 
281     /**
282      * Creates a new {@code License} builder instance using the specified object as a basis.
283      *
284      * @param from the {@code License} instance to use as a basis
285      * @param forceCopy the boolean indicating if a copy should be forced
286      * @return a new {@code Builder}
287      */
288     @Nonnull
289     public static Builder newBuilder( License from, boolean forceCopy )
290     {
291         return new Builder( from, forceCopy );
292     }
293 
294     /**
295      * Builder class used to create License instances.
296      * @see #with()
297      * @see #newBuilder()
298      */
299     @NotThreadSafe
300     public static class Builder
301     {
302         License base;
303         String name;
304         String url;
305         String distribution;
306         String comments;
307         Map<Object, InputLocation> locations;
308 
309         Builder( boolean withDefaults )
310         {
311             if ( withDefaults )
312             {
313             }
314         }
315 
316         Builder( License base, boolean forceCopy )
317         {
318             if ( forceCopy )
319             {
320                 this.name = base.name;
321                 this.url = base.url;
322                 this.distribution = base.distribution;
323                 this.comments = base.comments;
324             }
325             else
326             {
327                 this.base = base;
328             }
329         }
330 
331         @Nonnull
332         public Builder name( String name )
333         {
334             this.name = name;
335             return this;
336         }
337 
338         @Nonnull
339         public Builder url( String url )
340         {
341             this.url = url;
342             return this;
343         }
344 
345         @Nonnull
346         public Builder distribution( String distribution )
347         {
348             this.distribution = distribution;
349             return this;
350         }
351 
352         @Nonnull
353         public Builder comments( String comments )
354         {
355             this.comments = comments;
356             return this;
357         }
358 
359 
360         @Nonnull
361         public Builder location( Object key, InputLocation location )
362         {
363             if ( location != null )
364             {
365                 if ( this.locations == null )
366                 {
367                     this.locations = new HashMap<>();
368                 }
369                 this.locations.put( key, location );
370             }
371             return this;
372         }
373 
374         @Nonnull
375         public License build()
376         {
377             if ( base != null
378                     && ( name == null || name == base.name )
379                     && ( url == null || url == base.url )
380                     && ( distribution == null || distribution == base.distribution )
381                     && ( comments == null || comments == base.comments )
382             )
383             {
384                 return base;
385             }
386             Map<Object, InputLocation> locations = null;
387             InputLocation location = null;
388             InputLocation nameLocation = null;
389             InputLocation urlLocation = null;
390             InputLocation distributionLocation = null;
391             InputLocation commentsLocation = null;
392             if ( this.locations != null )
393             {
394                 locations = this.locations;
395                 location = locations.remove( "" );
396                 nameLocation = locations.remove( "name" );
397                 urlLocation = locations.remove( "url" );
398                 distributionLocation = locations.remove( "distribution" );
399                 commentsLocation = locations.remove( "comments" );
400             }
401             return new License(
402                 name != null ? name : ( base != null ? base.name : null ),
403                 url != null ? url : ( base != null ? base.url : null ),
404                 distribution != null ? distribution : ( base != null ? base.distribution : null ),
405                 comments != null ? comments : ( base != null ? base.comments : null ),
406                 locations != null ? locations : ( base != null ? base.locations : null ),
407                 location != null ? location : ( base != null ? base.location : null ),
408                 nameLocation != null ? nameLocation : ( base != null ? base.nameLocation : null ),
409                 urlLocation != null ? urlLocation : ( base != null ? base.urlLocation : null ),
410                 distributionLocation != null ? distributionLocation : ( base != null ? base.distributionLocation : null ),
411                 commentsLocation != null ? commentsLocation : ( base != null ? base.commentsLocation : null )
412             );
413         }
414     }
415 
416 }