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