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