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