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