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