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.ArrayList;
9   import java.util.Collection;
10  import java.util.Collections;
11  import java.util.HashMap;
12  import java.util.List;
13  import java.util.Map;
14  import java.util.Objects;
15  import java.util.Optional;
16  import java.util.Set;
17  import java.util.stream.Collectors;
18  import java.util.stream.Stream;
19  import org.apache.maven.api.annotations.Experimental;
20  import org.apache.maven.api.annotations.Generated;
21  import org.apache.maven.api.annotations.Immutable;
22  import org.apache.maven.api.annotations.Nonnull;
23  import org.apache.maven.api.annotations.NotThreadSafe;
24  import org.apache.maven.api.annotations.ThreadSafe;
25  
26  /**
27   * Root element of the {@code plugin.xml} file.
28   */
29  @Experimental
30  @Generated @ThreadSafe @Immutable
31  public class PluginDescriptor
32      implements Serializable
33  {
34      final String namespaceUri;
35      final String modelEncoding;
36      /**
37       * Name of the plugin.
38       */
39      final String name;
40      /**
41       * Description of the plugin.
42       */
43      final String description;
44      /**
45       * The group id of the plugin.
46       */
47      final String groupId;
48      /**
49       * The artifact id of the plugin.
50       */
51      final String artifactId;
52      /**
53       * The version of the plugin.
54       */
55      final String version;
56      /**
57       * 
58       */
59      final String goalPrefix;
60      /**
61       * 
62       */
63      final boolean isolatedRealm;
64      /**
65       * 
66       */
67      final boolean inheritedByDefault;
68      /**
69       * A version range which specifies the supported Java versions. A version range can either use the usual mathematical syntax "[2.0.10,2.1.0),[3.0,)" or use a single version "2.2.1". The latter is a short form for "[2.2.1,)", i.e. denotes the minimum version required.
70       * @since Maven 4.0.0-alpha-3
71       */
72      final String requiredJavaVersion;
73      /**
74       * A version range which specifies the supported Maven versions. A version range can either use the usual mathematical syntax "[2.0.10,2.1.0),[3.0,)" or use a single version "2.2.1". The latter is a short form for "[2.2.1,)", i.e. denotes the minimum version required. This value takes precedence over the POMs Maven prerequisite.
75       * @since Maven 4.0.0-alpha-3
76       */
77      final String requiredMavenVersion;
78      /**
79       * Description of each Mojo provided by the plugin.
80       */
81      final List<MojoDescriptor> mojos;
82  
83      /**
84        * Constructor for this class, to be called from its subclasses and {@link Builder}.
85        * @see Builder#build()
86        */
87      protected PluginDescriptor(Builder builder) {
88          this.namespaceUri = builder.namespaceUri != null ? builder.namespaceUri : (builder.base != null ? builder.base.namespaceUri : null);
89          this.modelEncoding = builder.modelEncoding != null ? builder.modelEncoding : (builder.base != null ? builder.base.modelEncoding :  "UTF-8");
90          this.name = builder.name != null ? builder.name : (builder.base != null ? builder.base.name : null);
91          this.description = builder.description != null ? builder.description : (builder.base != null ? builder.base.description : null);
92          this.groupId = builder.groupId != null ? builder.groupId : (builder.base != null ? builder.base.groupId : null);
93          this.artifactId = builder.artifactId != null ? builder.artifactId : (builder.base != null ? builder.base.artifactId : null);
94          this.version = builder.version != null ? builder.version : (builder.base != null ? builder.base.version : null);
95          this.goalPrefix = builder.goalPrefix != null ? builder.goalPrefix : (builder.base != null ? builder.base.goalPrefix : null);
96          this.isolatedRealm = builder.isolatedRealm != null ? builder.isolatedRealm : (builder.base != null ? builder.base.isolatedRealm : false);
97          this.inheritedByDefault = builder.inheritedByDefault != null ? builder.inheritedByDefault : (builder.base != null ? builder.base.inheritedByDefault : true);
98          this.requiredJavaVersion = builder.requiredJavaVersion != null ? builder.requiredJavaVersion : (builder.base != null ? builder.base.requiredJavaVersion : null);
99          this.requiredMavenVersion = builder.requiredMavenVersion != null ? builder.requiredMavenVersion : (builder.base != null ? builder.base.requiredMavenVersion : null);
100         this.mojos = ImmutableCollections.copy(builder.mojos != null ? builder.mojos : (builder.base != null ? builder.base.mojos : null));
101     }
102 
103     public String getNamespaceUri() {
104         return namespaceUri;
105     }
106 
107     public String getModelEncoding() {
108         return modelEncoding;
109     }
110 
111     /**
112      * Name of the plugin.
113      *
114      * @return a {@code String}
115      */
116     public String getName() {
117         return this.name;
118     }
119 
120     /**
121      * Description of the plugin.
122      *
123      * @return a {@code String}
124      */
125     public String getDescription() {
126         return this.description;
127     }
128 
129     /**
130      * The group id of the plugin.
131      *
132      * @return a {@code String}
133      */
134     public String getGroupId() {
135         return this.groupId;
136     }
137 
138     /**
139      * The artifact id of the plugin.
140      *
141      * @return a {@code String}
142      */
143     public String getArtifactId() {
144         return this.artifactId;
145     }
146 
147     /**
148      * The version of the plugin.
149      *
150      * @return a {@code String}
151      */
152     public String getVersion() {
153         return this.version;
154     }
155 
156     /**
157      * 
158      *
159      * @return a {@code String}
160      */
161     public String getGoalPrefix() {
162         return this.goalPrefix;
163     }
164 
165     /**
166      * 
167      *
168      * @return a {@code boolean}
169      */
170     public boolean isIsolatedRealm() {
171         return this.isolatedRealm;
172     }
173 
174     /**
175      * 
176      *
177      * @return a {@code boolean}
178      */
179     public boolean isInheritedByDefault() {
180         return this.inheritedByDefault;
181     }
182 
183     /**
184      * A version range which specifies the supported Java versions. A version range can either use the usual mathematical syntax "[2.0.10,2.1.0),[3.0,)" or use a single version "2.2.1". The latter is a short form for "[2.2.1,)", i.e. denotes the minimum version required.
185      * @since Maven 4.0.0-alpha-3
186      *
187      * @return a {@code String}
188      */
189     public String getRequiredJavaVersion() {
190         return this.requiredJavaVersion;
191     }
192 
193     /**
194      * A version range which specifies the supported Maven versions. A version range can either use the usual mathematical syntax "[2.0.10,2.1.0),[3.0,)" or use a single version "2.2.1". The latter is a short form for "[2.2.1,)", i.e. denotes the minimum version required. This value takes precedence over the POMs Maven prerequisite.
195      * @since Maven 4.0.0-alpha-3
196      *
197      * @return a {@code String}
198      */
199     public String getRequiredMavenVersion() {
200         return this.requiredMavenVersion;
201     }
202 
203     /**
204      * Description of each Mojo provided by the plugin.
205      *
206      * @return a {@code List<MojoDescriptor>}
207      */
208     @Nonnull
209     public List<MojoDescriptor> getMojos() {
210         return this.mojos;
211     }
212 
213     /**
214      * Creates a new builder with this object as the basis.
215      *
216      * @return a {@code Builder}
217      */
218     @Nonnull
219     public Builder with() {
220         return newBuilder(this);
221     }
222     /**
223      * Creates a new {@code PluginDescriptor} instance using the specified name.
224      *
225      * @param name the new {@code String} to use
226      * @return a {@code PluginDescriptor} with the specified name
227      */
228     @Nonnull
229     public PluginDescriptor withName(String name) {
230         return newBuilder(this, true).name(name).build();
231     }
232     /**
233      * Creates a new {@code PluginDescriptor} instance using the specified description.
234      *
235      * @param description the new {@code String} to use
236      * @return a {@code PluginDescriptor} with the specified description
237      */
238     @Nonnull
239     public PluginDescriptor withDescription(String description) {
240         return newBuilder(this, true).description(description).build();
241     }
242     /**
243      * Creates a new {@code PluginDescriptor} instance using the specified groupId.
244      *
245      * @param groupId the new {@code String} to use
246      * @return a {@code PluginDescriptor} with the specified groupId
247      */
248     @Nonnull
249     public PluginDescriptor withGroupId(String groupId) {
250         return newBuilder(this, true).groupId(groupId).build();
251     }
252     /**
253      * Creates a new {@code PluginDescriptor} instance using the specified artifactId.
254      *
255      * @param artifactId the new {@code String} to use
256      * @return a {@code PluginDescriptor} with the specified artifactId
257      */
258     @Nonnull
259     public PluginDescriptor withArtifactId(String artifactId) {
260         return newBuilder(this, true).artifactId(artifactId).build();
261     }
262     /**
263      * Creates a new {@code PluginDescriptor} instance using the specified version.
264      *
265      * @param version the new {@code String} to use
266      * @return a {@code PluginDescriptor} with the specified version
267      */
268     @Nonnull
269     public PluginDescriptor withVersion(String version) {
270         return newBuilder(this, true).version(version).build();
271     }
272     /**
273      * Creates a new {@code PluginDescriptor} instance using the specified goalPrefix.
274      *
275      * @param goalPrefix the new {@code String} to use
276      * @return a {@code PluginDescriptor} with the specified goalPrefix
277      */
278     @Nonnull
279     public PluginDescriptor withGoalPrefix(String goalPrefix) {
280         return newBuilder(this, true).goalPrefix(goalPrefix).build();
281     }
282     /**
283      * Creates a new {@code PluginDescriptor} instance using the specified isolatedRealm.
284      *
285      * @param isolatedRealm the new {@code boolean} to use
286      * @return a {@code PluginDescriptor} with the specified isolatedRealm
287      */
288     @Nonnull
289     public PluginDescriptor withIsolatedRealm(boolean isolatedRealm) {
290         return newBuilder(this, true).isolatedRealm(isolatedRealm).build();
291     }
292     /**
293      * Creates a new {@code PluginDescriptor} instance using the specified inheritedByDefault.
294      *
295      * @param inheritedByDefault the new {@code boolean} to use
296      * @return a {@code PluginDescriptor} with the specified inheritedByDefault
297      */
298     @Nonnull
299     public PluginDescriptor withInheritedByDefault(boolean inheritedByDefault) {
300         return newBuilder(this, true).inheritedByDefault(inheritedByDefault).build();
301     }
302     /**
303      * Creates a new {@code PluginDescriptor} instance using the specified requiredJavaVersion.
304      *
305      * @param requiredJavaVersion the new {@code String} to use
306      * @return a {@code PluginDescriptor} with the specified requiredJavaVersion
307      */
308     @Nonnull
309     public PluginDescriptor withRequiredJavaVersion(String requiredJavaVersion) {
310         return newBuilder(this, true).requiredJavaVersion(requiredJavaVersion).build();
311     }
312     /**
313      * Creates a new {@code PluginDescriptor} instance using the specified requiredMavenVersion.
314      *
315      * @param requiredMavenVersion the new {@code String} to use
316      * @return a {@code PluginDescriptor} with the specified requiredMavenVersion
317      */
318     @Nonnull
319     public PluginDescriptor withRequiredMavenVersion(String requiredMavenVersion) {
320         return newBuilder(this, true).requiredMavenVersion(requiredMavenVersion).build();
321     }
322     /**
323      * Creates a new {@code PluginDescriptor} instance using the specified mojos.
324      *
325      * @param mojos the new {@code Collection<MojoDescriptor>} to use
326      * @return a {@code PluginDescriptor} with the specified mojos
327      */
328     @Nonnull
329     public PluginDescriptor withMojos(Collection<MojoDescriptor> mojos) {
330         return newBuilder(this, true).mojos(mojos).build();
331     }
332 
333     /**
334      * Creates a new {@code PluginDescriptor} instance.
335      * Equivalent to {@code newInstance(true)}.
336      * @see #newInstance(boolean)
337      *
338      * @return a new {@code PluginDescriptor}
339      */
340     @Nonnull
341     public static PluginDescriptor newInstance() {
342         return newInstance(true);
343     }
344 
345     /**
346      * Creates a new {@code PluginDescriptor} instance using default values or not.
347      * Equivalent to {@code newBuilder(withDefaults).build()}.
348      *
349      * @param withDefaults the boolean indicating whether default values should be used
350      * @return a new {@code PluginDescriptor}
351      */
352     @Nonnull
353     public static PluginDescriptor newInstance(boolean withDefaults) {
354         return newBuilder(withDefaults).build();
355     }
356 
357     /**
358      * Creates a new {@code PluginDescriptor} builder instance.
359      * Equivalent to {@code newBuilder(true)}.
360      * @see #newBuilder(boolean)
361      *
362      * @return a new {@code Builder}
363      */
364     @Nonnull
365     public static Builder newBuilder() {
366         return newBuilder(true);
367     }
368 
369     /**
370      * Creates a new {@code PluginDescriptor} builder instance using default values or not.
371      *
372      * @param withDefaults the boolean indicating whether default values should be used
373      * @return a new {@code Builder}
374      */
375     @Nonnull
376     public static Builder newBuilder(boolean withDefaults) {
377         return new Builder(withDefaults);
378     }
379 
380     /**
381      * Creates a new {@code PluginDescriptor} builder instance using the specified object as a basis.
382      * Equivalent to {@code newBuilder(from, false)}.
383      *
384      * @param from the {@code PluginDescriptor} instance to use as a basis
385      * @return a new {@code Builder}
386      */
387     @Nonnull
388     public static Builder newBuilder(PluginDescriptor from) {
389         return newBuilder(from, false);
390     }
391 
392     /**
393      * Creates a new {@code PluginDescriptor} builder instance using the specified object as a basis.
394      *
395      * @param from the {@code PluginDescriptor} instance to use as a basis
396      * @param forceCopy the boolean indicating if a copy should be forced
397      * @return a new {@code Builder}
398      */
399     @Nonnull
400     public static Builder newBuilder(PluginDescriptor from, boolean forceCopy) {
401         return new Builder(from, forceCopy);
402     }
403 
404     /**
405      * Builder class used to create PluginDescriptor instances.
406      * @see #with()
407      * @see #newBuilder()
408      */
409     @NotThreadSafe
410     public static class Builder
411     {
412         PluginDescriptor base;
413         String namespaceUri;
414         String modelEncoding;
415         String name;
416         String description;
417         String groupId;
418         String artifactId;
419         String version;
420         String goalPrefix;
421         Boolean isolatedRealm;
422         Boolean inheritedByDefault;
423         String requiredJavaVersion;
424         String requiredMavenVersion;
425         Collection<MojoDescriptor> mojos;
426 
427         protected Builder(boolean withDefaults) {
428             if (withDefaults) {
429                 this.isolatedRealm = false;
430                 this.inheritedByDefault = true;
431             }
432         }
433 
434         protected Builder(PluginDescriptor base, boolean forceCopy) {
435             this.namespaceUri = base.namespaceUri;
436             this.modelEncoding = base.modelEncoding;
437             if (forceCopy) {
438                 this.name = base.name;
439                 this.description = base.description;
440                 this.groupId = base.groupId;
441                 this.artifactId = base.artifactId;
442                 this.version = base.version;
443                 this.goalPrefix = base.goalPrefix;
444                 this.isolatedRealm = base.isolatedRealm;
445                 this.inheritedByDefault = base.inheritedByDefault;
446                 this.requiredJavaVersion = base.requiredJavaVersion;
447                 this.requiredMavenVersion = base.requiredMavenVersion;
448                 this.mojos = base.mojos;
449             } else {
450                 this.base = base;
451             }
452         }
453 
454         @Nonnull
455         public Builder namespaceUri(String namespaceUri) {
456             this.namespaceUri = namespaceUri;
457             return this;
458         }
459 
460         @Nonnull
461         public Builder modelEncoding(String modelEncoding) {
462             this.modelEncoding = modelEncoding;
463             return this;
464         }
465 
466         @Nonnull
467         public Builder name(String name) {
468             this.name = name;
469             return this;
470         }
471 
472         @Nonnull
473         public Builder description(String description) {
474             this.description = description;
475             return this;
476         }
477 
478         @Nonnull
479         public Builder groupId(String groupId) {
480             this.groupId = groupId;
481             return this;
482         }
483 
484         @Nonnull
485         public Builder artifactId(String artifactId) {
486             this.artifactId = artifactId;
487             return this;
488         }
489 
490         @Nonnull
491         public Builder version(String version) {
492             this.version = version;
493             return this;
494         }
495 
496         @Nonnull
497         public Builder goalPrefix(String goalPrefix) {
498             this.goalPrefix = goalPrefix;
499             return this;
500         }
501 
502         @Nonnull
503         public Builder isolatedRealm(boolean isolatedRealm) {
504             this.isolatedRealm = isolatedRealm;
505             return this;
506         }
507 
508         @Nonnull
509         public Builder inheritedByDefault(boolean inheritedByDefault) {
510             this.inheritedByDefault = inheritedByDefault;
511             return this;
512         }
513 
514         @Nonnull
515         public Builder requiredJavaVersion(String requiredJavaVersion) {
516             this.requiredJavaVersion = requiredJavaVersion;
517             return this;
518         }
519 
520         @Nonnull
521         public Builder requiredMavenVersion(String requiredMavenVersion) {
522             this.requiredMavenVersion = requiredMavenVersion;
523             return this;
524         }
525 
526         @Nonnull
527         public Builder mojos(Collection<MojoDescriptor> mojos) {
528             this.mojos = mojos;
529             return this;
530         }
531 
532 
533         @Nonnull
534         public PluginDescriptor build() {
535             // this method should not contain any logic other than creating (or reusing) an object in order to ease subclassing
536             if (base != null
537                     && (name == null || name == base.name)
538                     && (description == null || description == base.description)
539                     && (groupId == null || groupId == base.groupId)
540                     && (artifactId == null || artifactId == base.artifactId)
541                     && (version == null || version == base.version)
542                     && (goalPrefix == null || goalPrefix == base.goalPrefix)
543                     && (isolatedRealm == null || isolatedRealm == base.isolatedRealm)
544                     && (inheritedByDefault == null || inheritedByDefault == base.inheritedByDefault)
545                     && (requiredJavaVersion == null || requiredJavaVersion == base.requiredJavaVersion)
546                     && (requiredMavenVersion == null || requiredMavenVersion == base.requiredMavenVersion)
547                     && (mojos == null || mojos == base.mojos)
548             ) {
549                 return base;
550             }
551             return new PluginDescriptor(this);
552         }
553 
554     }
555 
556 
557     public String getPluginLookupKey() {
558         return groupId + ":" + artifactId;
559     }
560 
561     public String getId() {
562         return groupId + ":" + artifactId + ":" + version;
563     }
564 
565           
566 }