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