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.metadata;
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   * Mapping information for a single plugin within this group.
21   */
22  @Experimental
23  @Generated @ThreadSafe @Immutable
24  public class Plugin
25      implements Serializable
26  {
27      /**
28       * Display name for the plugin.
29       */
30      final String name;
31      /**
32       * The plugin invocation prefix (i.e. eclipse for eclipse:eclipse)
33       */
34      final String prefix;
35      /**
36       * The plugin artifactId
37       */
38      final String artifactId;
39  
40      /**
41        * Constructor for this class, to be called from its subclasses and {@link Builder}.
42        * @see Builder#build()
43        */
44      protected Plugin(Builder builder) {
45          this.name = builder.name != null ? builder.name : (builder.base != null ? builder.base.name : null);
46          this.prefix = builder.prefix != null ? builder.prefix : (builder.base != null ? builder.base.prefix : null);
47          this.artifactId = builder.artifactId != null ? builder.artifactId : (builder.base != null ? builder.base.artifactId : null);
48      }
49  
50      /**
51       * Display name for the plugin.
52       *
53       * @return a {@code String}
54       */
55      public String getName() {
56          return this.name;
57      }
58  
59      /**
60       * The plugin invocation prefix (i.e. eclipse for eclipse:eclipse)
61       *
62       * @return a {@code String}
63       */
64      public String getPrefix() {
65          return this.prefix;
66      }
67  
68      /**
69       * The plugin artifactId
70       *
71       * @return a {@code String}
72       */
73      public String getArtifactId() {
74          return this.artifactId;
75      }
76  
77      /**
78       * Creates a new builder with this object as the basis.
79       *
80       * @return a {@code Builder}
81       */
82      @Nonnull
83      public Builder with() {
84          return newBuilder(this);
85      }
86      /**
87       * Creates a new {@code Plugin} instance using the specified name.
88       *
89       * @param name the new {@code String} to use
90       * @return a {@code Plugin} with the specified name
91       */
92      @Nonnull
93      public Plugin withName(String name) {
94          return newBuilder(this, true).name(name).build();
95      }
96      /**
97       * Creates a new {@code Plugin} instance using the specified prefix.
98       *
99       * @param prefix the new {@code String} to use
100      * @return a {@code Plugin} with the specified prefix
101      */
102     @Nonnull
103     public Plugin withPrefix(String prefix) {
104         return newBuilder(this, true).prefix(prefix).build();
105     }
106     /**
107      * Creates a new {@code Plugin} instance using the specified artifactId.
108      *
109      * @param artifactId the new {@code String} to use
110      * @return a {@code Plugin} with the specified artifactId
111      */
112     @Nonnull
113     public Plugin withArtifactId(String artifactId) {
114         return newBuilder(this, true).artifactId(artifactId).build();
115     }
116 
117     /**
118      * Creates a new {@code Plugin} instance.
119      * Equivalent to {@code newInstance(true)}.
120      * @see #newInstance(boolean)
121      *
122      * @return a new {@code Plugin}
123      */
124     @Nonnull
125     public static Plugin newInstance() {
126         return newInstance(true);
127     }
128 
129     /**
130      * Creates a new {@code Plugin} instance using default values or not.
131      * Equivalent to {@code newBuilder(withDefaults).build()}.
132      *
133      * @param withDefaults the boolean indicating whether default values should be used
134      * @return a new {@code Plugin}
135      */
136     @Nonnull
137     public static Plugin newInstance(boolean withDefaults) {
138         return newBuilder(withDefaults).build();
139     }
140 
141     /**
142      * Creates a new {@code Plugin} builder instance.
143      * Equivalent to {@code newBuilder(true)}.
144      * @see #newBuilder(boolean)
145      *
146      * @return a new {@code Builder}
147      */
148     @Nonnull
149     public static Builder newBuilder() {
150         return newBuilder(true);
151     }
152 
153     /**
154      * Creates a new {@code Plugin} builder instance using default values or not.
155      *
156      * @param withDefaults the boolean indicating whether default values should be used
157      * @return a new {@code Builder}
158      */
159     @Nonnull
160     public static Builder newBuilder(boolean withDefaults) {
161         return new Builder(withDefaults);
162     }
163 
164     /**
165      * Creates a new {@code Plugin} builder instance using the specified object as a basis.
166      * Equivalent to {@code newBuilder(from, false)}.
167      *
168      * @param from the {@code Plugin} instance to use as a basis
169      * @return a new {@code Builder}
170      */
171     @Nonnull
172     public static Builder newBuilder(Plugin from) {
173         return newBuilder(from, false);
174     }
175 
176     /**
177      * Creates a new {@code Plugin} builder instance using the specified object as a basis.
178      *
179      * @param from the {@code Plugin} instance to use as a basis
180      * @param forceCopy the boolean indicating if a copy should be forced
181      * @return a new {@code Builder}
182      */
183     @Nonnull
184     public static Builder newBuilder(Plugin from, boolean forceCopy) {
185         return new Builder(from, forceCopy);
186     }
187 
188     /**
189      * Builder class used to create Plugin instances.
190      * @see #with()
191      * @see #newBuilder()
192      */
193     @NotThreadSafe
194     public static class Builder
195     {
196         Plugin base;
197         String name;
198         String prefix;
199         String artifactId;
200 
201         protected Builder(boolean withDefaults) {
202             if (withDefaults) {
203             }
204         }
205 
206         protected Builder(Plugin base, boolean forceCopy) {
207             if (forceCopy) {
208                 this.name = base.name;
209                 this.prefix = base.prefix;
210                 this.artifactId = base.artifactId;
211             } else {
212                 this.base = base;
213             }
214         }
215 
216         @Nonnull
217         public Builder name(String name) {
218             this.name = name;
219             return this;
220         }
221 
222         @Nonnull
223         public Builder prefix(String prefix) {
224             this.prefix = prefix;
225             return this;
226         }
227 
228         @Nonnull
229         public Builder artifactId(String artifactId) {
230             this.artifactId = artifactId;
231             return this;
232         }
233 
234 
235         @Nonnull
236         public Plugin build() {
237             // this method should not contain any logic other than creating (or reusing) an object in order to ease subclassing
238             if (base != null
239                     && (name == null || name == base.name)
240                     && (prefix == null || prefix == base.prefix)
241                     && (artifactId == null || artifactId == base.artifactId)
242             ) {
243                 return base;
244             }
245             return new Plugin(this);
246         }
247     }
248 
249 }