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