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