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.cli.internal.extension.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 CoreExtension
25      implements Serializable
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 class loading strategy: 'self-first' (the default), 'parent-first' (loads classes from the parent, then from the extension) or 'plugin' (follows the rules from extensions defined as plugins).
41       */
42      final String classLoadingStrategy;
43      /**
44       */
45      final XmlNode configuration;
46  
47      /**
48        * Constructor for this class, package protected.
49        * @see Builder#build()
50        */
51      CoreExtension(
52          String groupId,
53          String artifactId,
54          String version,
55          String classLoadingStrategy,
56          XmlNode configuration
57      ) {
58          this.groupId = groupId;
59          this.artifactId = artifactId;
60          this.version = version;
61          this.classLoadingStrategy = classLoadingStrategy;
62          this.configuration = configuration;
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 class loading strategy: 'self-first' (the default), 'parent-first' (loads classes from the parent, then from the extension) or 'plugin' (follows the rules from extensions defined as plugins).
94       *
95       * @return a {@code String}
96       */
97      public String getClassLoadingStrategy() {
98          return this.classLoadingStrategy;
99      }
100 
101     /**
102      *
103      * @return a {@code XmlNode}
104      */
105     public XmlNode getConfiguration() {
106         return this.configuration;
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 CoreExtension} instance using the specified groupId.
120      *
121      * @param groupId the new {@code String} to use
122      * @return a {@code CoreExtension} with the specified groupId
123      */
124     @Nonnull
125     public CoreExtension withGroupId(String groupId) {
126         return newBuilder(this, true).groupId(groupId).build();
127     }
128     /**
129      * Creates a new {@code CoreExtension} instance using the specified artifactId.
130      *
131      * @param artifactId the new {@code String} to use
132      * @return a {@code CoreExtension} with the specified artifactId
133      */
134     @Nonnull
135     public CoreExtension withArtifactId(String artifactId) {
136         return newBuilder(this, true).artifactId(artifactId).build();
137     }
138     /**
139      * Creates a new {@code CoreExtension} instance using the specified version.
140      *
141      * @param version the new {@code String} to use
142      * @return a {@code CoreExtension} with the specified version
143      */
144     @Nonnull
145     public CoreExtension withVersion(String version) {
146         return newBuilder(this, true).version(version).build();
147     }
148     /**
149      * Creates a new {@code CoreExtension} instance using the specified classLoadingStrategy.
150      *
151      * @param classLoadingStrategy the new {@code String} to use
152      * @return a {@code CoreExtension} with the specified classLoadingStrategy
153      */
154     @Nonnull
155     public CoreExtension withClassLoadingStrategy(String classLoadingStrategy) {
156         return newBuilder(this, true).classLoadingStrategy(classLoadingStrategy).build();
157     }
158     /**
159      * Creates a new {@code CoreExtension} instance using the specified configuration.
160      *
161      * @param configuration the new {@code XmlNode} to use
162      * @return a {@code CoreExtension} with the specified configuration
163      */
164     @Nonnull
165     public CoreExtension withConfiguration(XmlNode configuration) {
166         return newBuilder(this, true).configuration(configuration).build();
167     }
168 
169     /**
170      * Creates a new {@code CoreExtension} instance.
171      * Equivalent to {@code newInstance(true)}.
172      * @see #newInstance(boolean)
173      *
174      * @return a new {@code CoreExtension}
175      */
176     @Nonnull
177     public static CoreExtension newInstance() {
178         return newInstance(true);
179     }
180 
181     /**
182      * Creates a new {@code CoreExtension} instance using default values or not.
183      * Equivalent to {@code newBuilder(withDefaults).build()}.
184      *
185      * @param withDefaults the boolean indicating whether default values should be used
186      * @return a new {@code CoreExtension}
187      */
188     @Nonnull
189     public static CoreExtension newInstance(boolean withDefaults) {
190         return newBuilder(withDefaults).build();
191     }
192 
193     /**
194      * Creates a new {@code CoreExtension} builder instance.
195      * Equivalent to {@code newBuilder(true)}.
196      * @see #newBuilder(boolean)
197      *
198      * @return a new {@code Builder}
199      */
200     @Nonnull
201     public static Builder newBuilder() {
202         return newBuilder(true);
203     }
204 
205     /**
206      * Creates a new {@code CoreExtension} builder instance using default values or not.
207      *
208      * @param withDefaults the boolean indicating whether default values should be used
209      * @return a new {@code Builder}
210      */
211     @Nonnull
212     public static Builder newBuilder(boolean withDefaults) {
213         return new Builder(withDefaults);
214     }
215 
216     /**
217      * Creates a new {@code CoreExtension} builder instance using the specified object as a basis.
218      * Equivalent to {@code newBuilder(from, false)}.
219      *
220      * @param from the {@code CoreExtension} instance to use as a basis
221      * @return a new {@code Builder}
222      */
223     @Nonnull
224     public static Builder newBuilder(CoreExtension from) {
225         return newBuilder(from, false);
226     }
227 
228     /**
229      * Creates a new {@code CoreExtension} builder instance using the specified object as a basis.
230      *
231      * @param from the {@code CoreExtension} instance to use as a basis
232      * @param forceCopy the boolean indicating if a copy should be forced
233      * @return a new {@code Builder}
234      */
235     @Nonnull
236     public static Builder newBuilder(CoreExtension from, boolean forceCopy) {
237         return new Builder(from, forceCopy);
238     }
239 
240     /**
241      * Builder class used to create CoreExtension instances.
242      * @see #with()
243      * @see #newBuilder()
244      */
245     @NotThreadSafe
246     public static class Builder
247     {
248         CoreExtension base;
249         String groupId;
250         String artifactId;
251         String version;
252         String classLoadingStrategy;
253         XmlNode configuration;
254 
255         Builder(boolean withDefaults) {
256             if (withDefaults) {
257                 this.classLoadingStrategy = "self-first";
258             }
259         }
260 
261         Builder(CoreExtension base, boolean forceCopy) {
262             if (forceCopy) {
263                 this.groupId = base.groupId;
264                 this.artifactId = base.artifactId;
265                 this.version = base.version;
266                 this.classLoadingStrategy = base.classLoadingStrategy;
267                 this.configuration = base.configuration;
268             } else {
269                 this.base = base;
270             }
271         }
272 
273         @Nonnull
274         public Builder groupId(String groupId) {
275             this.groupId = groupId;
276             return this;
277         }
278 
279         @Nonnull
280         public Builder artifactId(String artifactId) {
281             this.artifactId = artifactId;
282             return this;
283         }
284 
285         @Nonnull
286         public Builder version(String version) {
287             this.version = version;
288             return this;
289         }
290 
291         @Nonnull
292         public Builder classLoadingStrategy(String classLoadingStrategy) {
293             this.classLoadingStrategy = classLoadingStrategy;
294             return this;
295         }
296 
297         @Nonnull
298         public Builder configuration(XmlNode configuration) {
299             this.configuration = configuration;
300             return this;
301         }
302 
303 
304         @Nonnull
305         public CoreExtension build() {
306             if (base != null
307                     && (groupId == null || groupId == base.groupId)
308                     && (artifactId == null || artifactId == base.artifactId)
309                     && (version == null || version == base.version)
310                     && (classLoadingStrategy == null || classLoadingStrategy == base.classLoadingStrategy)
311                     && (configuration == null || configuration == base.configuration)
312             ) {
313                 return base;
314             }
315             return new CoreExtension(
316                 groupId != null ? groupId : (base != null ? base.groupId : null),
317                 artifactId != null ? artifactId : (base != null ? base.artifactId : null),
318                 version != null ? version : (base != null ? base.version : null),
319                 classLoadingStrategy != null ? classLoadingStrategy : (base != null ? base.classLoadingStrategy : null),
320                 configuration != null ? configuration : (base != null ? base.configuration : null)
321             );
322         }
323     }
324 
325 
326             
327     /**
328      * Gets the identifier of the extension.
329      *
330      * @return The extension id in the form {@code <groupId>:<artifactId>:<version>}, never {@code null}.
331      */
332     public String getId() {
333         return (getGroupId() == null ? "[unknown-group-id]" : getGroupId())
334             + ":" + (getArtifactId() == null ? "[unknown-artifact-id]" : getArtifactId())
335             + ":" + (getVersion() == null ? "[unknown-version]" : getVersion());
336     }
337             
338           
339 }