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      /** Locations */
52      final Map<Object, InputLocation> locations;
53  
54      /**
55        * Constructor for this class, package protected.
56        * @see Builder#build()
57        */
58      License(
59          String name,
60          String url,
61          String distribution,
62          String comments,
63          Map<Object, InputLocation> locations
64      ) {
65          this.name = name;
66          this.url = url;
67          this.distribution = distribution;
68          this.comments = comments;
69          this.locations = ImmutableCollections.copy(locations);
70      }
71  
72      /**
73       * The full legal name of the license.
74       *
75       * @return a {@code String}
76       */
77      public String getName() {
78          return this.name;
79      }
80  
81      /**
82       * The official url for the license text.
83       *
84       * @return a {@code String}
85       */
86      public String getUrl() {
87          return this.url;
88      }
89  
90      /**
91       * The primary method by which this project may be distributed.
92       * <dl>
93       * <dt>repo</dt>
94       * <dd>may be downloaded from the Maven repository</dd>
95       * <dt>manual</dt>
96       * <dd>user must manually download and install the dependency.</dd>
97       * </dl>
98       *
99       * @return a {@code String}
100      */
101     public String getDistribution() {
102         return this.distribution;
103     }
104 
105     /**
106      * Addendum information pertaining to this license.
107      *
108      * @return a {@code String}
109      */
110     public String getComments() {
111         return this.comments;
112     }
113 
114     /**
115      * Gets the location of the specified field in the input source.
116      */
117     public InputLocation getLocation(Object key) {
118         return locations != null ? locations.get(key) : null;
119     }
120 
121     /**
122      * Creates a new builder with this object as the basis.
123      *
124      * @return a {@code Builder}
125      */
126     @Nonnull
127     public Builder with() {
128         return newBuilder(this);
129     }
130     /**
131      * Creates a new {@code License} instance using the specified name.
132      *
133      * @param name the new {@code String} to use
134      * @return a {@code License} with the specified name
135      */
136     @Nonnull
137     public License withName(String name) {
138         return newBuilder(this, true).name(name).build();
139     }
140     /**
141      * Creates a new {@code License} instance using the specified url.
142      *
143      * @param url the new {@code String} to use
144      * @return a {@code License} with the specified url
145      */
146     @Nonnull
147     public License withUrl(String url) {
148         return newBuilder(this, true).url(url).build();
149     }
150     /**
151      * Creates a new {@code License} instance using the specified distribution.
152      *
153      * @param distribution the new {@code String} to use
154      * @return a {@code License} with the specified distribution
155      */
156     @Nonnull
157     public License withDistribution(String distribution) {
158         return newBuilder(this, true).distribution(distribution).build();
159     }
160     /**
161      * Creates a new {@code License} instance using the specified comments.
162      *
163      * @param comments the new {@code String} to use
164      * @return a {@code License} with the specified comments
165      */
166     @Nonnull
167     public License withComments(String comments) {
168         return newBuilder(this, true).comments(comments).build();
169     }
170 
171     /**
172      * Creates a new {@code License} instance.
173      * Equivalent to {@code newInstance(true)}.
174      * @see #newInstance(boolean)
175      *
176      * @return a new {@code License}
177      */
178     @Nonnull
179     public static License newInstance() {
180         return newInstance(true);
181     }
182 
183     /**
184      * Creates a new {@code License} instance using default values or not.
185      * Equivalent to {@code newBuilder(withDefaults).build()}.
186      *
187      * @param withDefaults the boolean indicating whether default values should be used
188      * @return a new {@code License}
189      */
190     @Nonnull
191     public static License newInstance(boolean withDefaults) {
192         return newBuilder(withDefaults).build();
193     }
194 
195     /**
196      * Creates a new {@code License} builder instance.
197      * Equivalent to {@code newBuilder(true)}.
198      * @see #newBuilder(boolean)
199      *
200      * @return a new {@code Builder}
201      */
202     @Nonnull
203     public static Builder newBuilder() {
204         return newBuilder(true);
205     }
206 
207     /**
208      * Creates a new {@code License} builder instance using default values or not.
209      *
210      * @param withDefaults the boolean indicating whether default values should be used
211      * @return a new {@code Builder}
212      */
213     @Nonnull
214     public static Builder newBuilder(boolean withDefaults) {
215         return new Builder(withDefaults);
216     }
217 
218     /**
219      * Creates a new {@code License} builder instance using the specified object as a basis.
220      * Equivalent to {@code newBuilder(from, false)}.
221      *
222      * @param from the {@code License} instance to use as a basis
223      * @return a new {@code Builder}
224      */
225     @Nonnull
226     public static Builder newBuilder(License from) {
227         return newBuilder(from, false);
228     }
229 
230     /**
231      * Creates a new {@code License} builder instance using the specified object as a basis.
232      *
233      * @param from the {@code License} instance to use as a basis
234      * @param forceCopy the boolean indicating if a copy should be forced
235      * @return a new {@code Builder}
236      */
237     @Nonnull
238     public static Builder newBuilder(License from, boolean forceCopy) {
239         return new Builder(from, forceCopy);
240     }
241 
242     /**
243      * Builder class used to create License instances.
244      * @see #with()
245      * @see #newBuilder()
246      */
247     @NotThreadSafe
248     public static class Builder
249     {
250         License base;
251         String name;
252         String url;
253         String distribution;
254         String comments;
255         Map<Object, InputLocation> locations;
256 
257         Builder(boolean withDefaults) {
258             if (withDefaults) {
259             }
260         }
261 
262         Builder(License base, boolean forceCopy) {
263             if (forceCopy) {
264                 this.name = base.name;
265                 this.url = base.url;
266                 this.distribution = base.distribution;
267                 this.comments = base.comments;
268                 this.locations = base.locations;
269             } else {
270                 this.base = base;
271             }
272         }
273 
274         @Nonnull
275         public Builder name(String name) {
276             this.name = name;
277             return this;
278         }
279 
280         @Nonnull
281         public Builder url(String url) {
282             this.url = url;
283             return this;
284         }
285 
286         @Nonnull
287         public Builder distribution(String distribution) {
288             this.distribution = distribution;
289             return this;
290         }
291 
292         @Nonnull
293         public Builder comments(String comments) {
294             this.comments = comments;
295             return this;
296         }
297 
298 
299         @Nonnull
300         public Builder location(Object key, InputLocation location) {
301             if (location != null) {
302                 if (!(this.locations instanceof HashMap)) {
303                     this.locations = this.locations != null ? new HashMap<>(this.locations) : new HashMap<>();
304                 }
305                 this.locations.put(key, location);
306             }
307             return this;
308         }
309 
310         @Nonnull
311         public License build() {
312             if (base != null
313                     && (name == null || name == base.name)
314                     && (url == null || url == base.url)
315                     && (distribution == null || distribution == base.distribution)
316                     && (comments == null || comments == base.comments)
317             ) {
318                 return base;
319             }
320             Map<Object, InputLocation> newlocs = this.locations != null ? this.locations : Collections.emptyMap();
321             Map<Object, InputLocation> oldlocs = this.base != null && this.base.locations != null ? this.base.locations : Collections.emptyMap();
322             Map<Object, InputLocation> locations = new HashMap<>();
323             locations.put("", newlocs.containsKey("") ? newlocs.get("") : oldlocs.get(""));
324             locations.put("name", newlocs.containsKey("name") ? newlocs.get("name") : oldlocs.get("name"));
325             locations.put("url", newlocs.containsKey("url") ? newlocs.get("url") : oldlocs.get("url"));
326             locations.put("distribution", newlocs.containsKey("distribution") ? newlocs.get("distribution") : oldlocs.get("distribution"));
327             locations.put("comments", newlocs.containsKey("comments") ? newlocs.get("comments") : oldlocs.get("comments"));
328             return new License(
329                 name != null ? name : (base != null ? base.name : null),
330                 url != null ? url : (base != null ? base.url : null),
331                 distribution != null ? distribution : (base != null ? base.distribution : null),
332                 comments != null ? comments : (base != null ? base.comments : null),
333                 locations
334             );
335         }
336     }
337 
338 
339             
340     /**
341      * @see java.lang.Object#toString()
342      */
343     public String toString()
344     {
345         return "License {name=" + getName() + ", url=" + getUrl() + "}";
346     }
347             
348           
349 }