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.plugin.descriptor;
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  
19  /**
20   * A parameter description.
21   */
22  @Experimental
23  @Generated @ThreadSafe @Immutable
24  public class Parameter
25      implements Serializable
26  {
27      /**
28       * The name of the parameter, to be used while configuring this parameter from the Mojo's declared defaults
29       * or from the POM.
30       */
31      final String name;
32      /**
33       * Specifies an alias which can be used to configure this parameter from the POM.
34       * This is primarily useful to improve user-friendliness, where Mojo field names are not intuitive to the
35       * user or are otherwise not conducive to configuration via the POM.
36       */
37      final String alias;
38      /**
39       * The Java type for this parameter. This is used to validate the result of any expressions used to calculate
40       * the value which should be injected into the Mojo for this parameter.
41       */
42      final String type;
43      /**
44       * Whether this parameter is required for the Mojo to function. This is used to validate the configuration
45       * for a Mojo before it is injected, and before the Mojo is executed from some half-state.
46       */
47      final boolean required;
48      /**
49       * Specifies that this parameter can be configured directly by the user (as in the case of POM-specified
50       * configuration). This is useful when you want to force the user to use common POM elements rather than
51       * plugin configurations, as in the case where you want to use the artifact's final name as a parameter. In
52       * this case, you want the user to modify {@code <build><finalName/></build>} rather
53       * than specifying a value for finalName directly in the plugin configuration section. It is also useful to
54       * ensure that - for example - a List-typed parameter which expects items of type Artifact doesn't get a List
55       * full of Strings.
56       */
57      final boolean editable;
58      /**
59       * The description of this parameter's use inside the Mojo.
60       */
61      final String description;
62      /**
63       * Specify the version when the parameter was added to the API. Similar to Javadoc since.
64       */
65      final String since;
66      /**
67       * Description with the reason of parameter deprecation. Similar to Javadoc {@code @deprecated}.
68       * This will trigger a warning when a user tries to configure a parameter marked as deprecated.
69       */
70      final String deprecated;
71      /**
72       * Parameter expression, to let user override default value with a user property, system property or project property.
73       */
74      final String expression;
75      /**
76       * The default value, as an expression that will be evaluated at injection or run-time.
77       */
78      final String defaultValue;
79  
80      /**
81        * Constructor for this class, to be called from its subclasses and {@link Builder}.
82        * @see Builder#build()
83        */
84      protected Parameter(Builder builder) {
85          this.name = builder.name != null ? builder.name : (builder.base != null ? builder.base.name : null);
86          this.alias = builder.alias != null ? builder.alias : (builder.base != null ? builder.base.alias : null);
87          this.type = builder.type != null ? builder.type : (builder.base != null ? builder.base.type : null);
88          this.required = builder.required != null ? builder.required : (builder.base != null ? builder.base.required : false);
89          this.editable = builder.editable != null ? builder.editable : (builder.base != null ? builder.base.editable : true);
90          this.description = builder.description != null ? builder.description : (builder.base != null ? builder.base.description : null);
91          this.since = builder.since != null ? builder.since : (builder.base != null ? builder.base.since : null);
92          this.deprecated = builder.deprecated != null ? builder.deprecated : (builder.base != null ? builder.base.deprecated : null);
93          this.expression = builder.expression != null ? builder.expression : (builder.base != null ? builder.base.expression : null);
94          this.defaultValue = builder.defaultValue != null ? builder.defaultValue : (builder.base != null ? builder.base.defaultValue : null);
95      }
96  
97      /**
98       * The name of the parameter, to be used while configuring this parameter from the Mojo's declared defaults
99       * or from the POM.
100      *
101      * @return a {@code String}
102      */
103     public String getName() {
104         return this.name;
105     }
106 
107     /**
108      * Specifies an alias which can be used to configure this parameter from the POM.
109      * This is primarily useful to improve user-friendliness, where Mojo field names are not intuitive to the
110      * user or are otherwise not conducive to configuration via the POM.
111      *
112      * @return a {@code String}
113      */
114     public String getAlias() {
115         return this.alias;
116     }
117 
118     /**
119      * The Java type for this parameter. This is used to validate the result of any expressions used to calculate
120      * the value which should be injected into the Mojo for this parameter.
121      *
122      * @return a {@code String}
123      */
124     public String getType() {
125         return this.type;
126     }
127 
128     /**
129      * Whether this parameter is required for the Mojo to function. This is used to validate the configuration
130      * for a Mojo before it is injected, and before the Mojo is executed from some half-state.
131      *
132      * @return a {@code boolean}
133      */
134     public boolean isRequired() {
135         return this.required;
136     }
137 
138     /**
139      * Specifies that this parameter can be configured directly by the user (as in the case of POM-specified
140      * configuration). This is useful when you want to force the user to use common POM elements rather than
141      * plugin configurations, as in the case where you want to use the artifact's final name as a parameter. In
142      * this case, you want the user to modify {@code <build><finalName/></build>} rather
143      * than specifying a value for finalName directly in the plugin configuration section. It is also useful to
144      * ensure that - for example - a List-typed parameter which expects items of type Artifact doesn't get a List
145      * full of Strings.
146      *
147      * @return a {@code boolean}
148      */
149     public boolean isEditable() {
150         return this.editable;
151     }
152 
153     /**
154      * The description of this parameter's use inside the Mojo.
155      *
156      * @return a {@code String}
157      */
158     public String getDescription() {
159         return this.description;
160     }
161 
162     /**
163      * Specify the version when the parameter was added to the API. Similar to Javadoc since.
164      *
165      * @return a {@code String}
166      */
167     public String getSince() {
168         return this.since;
169     }
170 
171     /**
172      * Description with the reason of parameter deprecation. Similar to Javadoc {@code @deprecated}.
173      * This will trigger a warning when a user tries to configure a parameter marked as deprecated.
174      *
175      * @return a {@code String}
176      */
177     public String getDeprecated() {
178         return this.deprecated;
179     }
180 
181     /**
182      * Parameter expression, to let user override default value with a user property, system property or project property.
183      *
184      * @return a {@code String}
185      */
186     public String getExpression() {
187         return this.expression;
188     }
189 
190     /**
191      * The default value, as an expression that will be evaluated at injection or run-time.
192      *
193      * @return a {@code String}
194      */
195     public String getDefaultValue() {
196         return this.defaultValue;
197     }
198 
199     /**
200      * Creates a new builder with this object as the basis.
201      *
202      * @return a {@code Builder}
203      */
204     @Nonnull
205     public Builder with() {
206         return newBuilder(this);
207     }
208     /**
209      * Creates a new {@code Parameter} instance using the specified name.
210      *
211      * @param name the new {@code String} to use
212      * @return a {@code Parameter} with the specified name
213      */
214     @Nonnull
215     public Parameter withName(String name) {
216         return newBuilder(this, true).name(name).build();
217     }
218     /**
219      * Creates a new {@code Parameter} instance using the specified alias.
220      *
221      * @param alias the new {@code String} to use
222      * @return a {@code Parameter} with the specified alias
223      */
224     @Nonnull
225     public Parameter withAlias(String alias) {
226         return newBuilder(this, true).alias(alias).build();
227     }
228     /**
229      * Creates a new {@code Parameter} instance using the specified type.
230      *
231      * @param type the new {@code String} to use
232      * @return a {@code Parameter} with the specified type
233      */
234     @Nonnull
235     public Parameter withType(String type) {
236         return newBuilder(this, true).type(type).build();
237     }
238     /**
239      * Creates a new {@code Parameter} instance using the specified required.
240      *
241      * @param required the new {@code boolean} to use
242      * @return a {@code Parameter} with the specified required
243      */
244     @Nonnull
245     public Parameter withRequired(boolean required) {
246         return newBuilder(this, true).required(required).build();
247     }
248     /**
249      * Creates a new {@code Parameter} instance using the specified editable.
250      *
251      * @param editable the new {@code boolean} to use
252      * @return a {@code Parameter} with the specified editable
253      */
254     @Nonnull
255     public Parameter withEditable(boolean editable) {
256         return newBuilder(this, true).editable(editable).build();
257     }
258     /**
259      * Creates a new {@code Parameter} instance using the specified description.
260      *
261      * @param description the new {@code String} to use
262      * @return a {@code Parameter} with the specified description
263      */
264     @Nonnull
265     public Parameter withDescription(String description) {
266         return newBuilder(this, true).description(description).build();
267     }
268     /**
269      * Creates a new {@code Parameter} instance using the specified since.
270      *
271      * @param since the new {@code String} to use
272      * @return a {@code Parameter} with the specified since
273      */
274     @Nonnull
275     public Parameter withSince(String since) {
276         return newBuilder(this, true).since(since).build();
277     }
278     /**
279      * Creates a new {@code Parameter} instance using the specified deprecated.
280      *
281      * @param deprecated the new {@code String} to use
282      * @return a {@code Parameter} with the specified deprecated
283      */
284     @Nonnull
285     public Parameter withDeprecated(String deprecated) {
286         return newBuilder(this, true).deprecated(deprecated).build();
287     }
288     /**
289      * Creates a new {@code Parameter} instance using the specified expression.
290      *
291      * @param expression the new {@code String} to use
292      * @return a {@code Parameter} with the specified expression
293      */
294     @Nonnull
295     public Parameter withExpression(String expression) {
296         return newBuilder(this, true).expression(expression).build();
297     }
298     /**
299      * Creates a new {@code Parameter} instance using the specified defaultValue.
300      *
301      * @param defaultValue the new {@code String} to use
302      * @return a {@code Parameter} with the specified defaultValue
303      */
304     @Nonnull
305     public Parameter withDefaultValue(String defaultValue) {
306         return newBuilder(this, true).defaultValue(defaultValue).build();
307     }
308 
309     /**
310      * Creates a new {@code Parameter} instance.
311      * Equivalent to {@code newInstance(true)}.
312      * @see #newInstance(boolean)
313      *
314      * @return a new {@code Parameter}
315      */
316     @Nonnull
317     public static Parameter newInstance() {
318         return newInstance(true);
319     }
320 
321     /**
322      * Creates a new {@code Parameter} instance using default values or not.
323      * Equivalent to {@code newBuilder(withDefaults).build()}.
324      *
325      * @param withDefaults the boolean indicating whether default values should be used
326      * @return a new {@code Parameter}
327      */
328     @Nonnull
329     public static Parameter newInstance(boolean withDefaults) {
330         return newBuilder(withDefaults).build();
331     }
332 
333     /**
334      * Creates a new {@code Parameter} builder instance.
335      * Equivalent to {@code newBuilder(true)}.
336      * @see #newBuilder(boolean)
337      *
338      * @return a new {@code Builder}
339      */
340     @Nonnull
341     public static Builder newBuilder() {
342         return newBuilder(true);
343     }
344 
345     /**
346      * Creates a new {@code Parameter} builder instance using default values or not.
347      *
348      * @param withDefaults the boolean indicating whether default values should be used
349      * @return a new {@code Builder}
350      */
351     @Nonnull
352     public static Builder newBuilder(boolean withDefaults) {
353         return new Builder(withDefaults);
354     }
355 
356     /**
357      * Creates a new {@code Parameter} builder instance using the specified object as a basis.
358      * Equivalent to {@code newBuilder(from, false)}.
359      *
360      * @param from the {@code Parameter} instance to use as a basis
361      * @return a new {@code Builder}
362      */
363     @Nonnull
364     public static Builder newBuilder(Parameter from) {
365         return newBuilder(from, false);
366     }
367 
368     /**
369      * Creates a new {@code Parameter} builder instance using the specified object as a basis.
370      *
371      * @param from the {@code Parameter} instance to use as a basis
372      * @param forceCopy the boolean indicating if a copy should be forced
373      * @return a new {@code Builder}
374      */
375     @Nonnull
376     public static Builder newBuilder(Parameter from, boolean forceCopy) {
377         return new Builder(from, forceCopy);
378     }
379 
380     /**
381      * Builder class used to create Parameter instances.
382      * @see #with()
383      * @see #newBuilder()
384      */
385     @NotThreadSafe
386     public static class Builder
387     {
388         Parameter base;
389         String name;
390         String alias;
391         String type;
392         Boolean required;
393         Boolean editable;
394         String description;
395         String since;
396         String deprecated;
397         String expression;
398         String defaultValue;
399 
400         protected Builder(boolean withDefaults) {
401             if (withDefaults) {
402                 this.required = false;
403                 this.editable = true;
404             }
405         }
406 
407         protected Builder(Parameter base, boolean forceCopy) {
408             if (forceCopy) {
409                 this.name = base.name;
410                 this.alias = base.alias;
411                 this.type = base.type;
412                 this.required = base.required;
413                 this.editable = base.editable;
414                 this.description = base.description;
415                 this.since = base.since;
416                 this.deprecated = base.deprecated;
417                 this.expression = base.expression;
418                 this.defaultValue = base.defaultValue;
419             } else {
420                 this.base = base;
421             }
422         }
423 
424         @Nonnull
425         public Builder name(String name) {
426             this.name = name;
427             return this;
428         }
429 
430         @Nonnull
431         public Builder alias(String alias) {
432             this.alias = alias;
433             return this;
434         }
435 
436         @Nonnull
437         public Builder type(String type) {
438             this.type = type;
439             return this;
440         }
441 
442         @Nonnull
443         public Builder required(boolean required) {
444             this.required = required;
445             return this;
446         }
447 
448         @Nonnull
449         public Builder editable(boolean editable) {
450             this.editable = editable;
451             return this;
452         }
453 
454         @Nonnull
455         public Builder description(String description) {
456             this.description = description;
457             return this;
458         }
459 
460         @Nonnull
461         public Builder since(String since) {
462             this.since = since;
463             return this;
464         }
465 
466         @Nonnull
467         public Builder deprecated(String deprecated) {
468             this.deprecated = deprecated;
469             return this;
470         }
471 
472         @Nonnull
473         public Builder expression(String expression) {
474             this.expression = expression;
475             return this;
476         }
477 
478         @Nonnull
479         public Builder defaultValue(String defaultValue) {
480             this.defaultValue = defaultValue;
481             return this;
482         }
483 
484 
485         @Nonnull
486         public Parameter build() {
487             // this method should not contain any logic other than creating (or reusing) an object in order to ease subclassing
488             if (base != null
489                     && (name == null || name == base.name)
490                     && (alias == null || alias == base.alias)
491                     && (type == null || type == base.type)
492                     && (required == null || required == base.required)
493                     && (editable == null || editable == base.editable)
494                     && (description == null || description == base.description)
495                     && (since == null || since == base.since)
496                     && (deprecated == null || deprecated == base.deprecated)
497                     && (expression == null || expression == base.expression)
498                     && (defaultValue == null || defaultValue == base.defaultValue)
499             ) {
500                 return base;
501             }
502             return new Parameter(this);
503         }
504     }
505 
506 }