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