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