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.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.Set;
15  import org.apache.maven.api.annotations.Experimental;
16  import org.apache.maven.api.annotations.Generated;
17  import org.apache.maven.api.annotations.Immutable;
18  import org.apache.maven.api.annotations.Nonnull;
19  import org.apache.maven.api.annotations.NotThreadSafe;
20  import org.apache.maven.api.annotations.ThreadSafe;
21  
22  /**
23   */
24  @Experimental
25  @Generated @ThreadSafe @Immutable
26  public class Metadata
27      implements Serializable
28  {
29      final String namespaceUri;
30      final String modelEncoding;
31      /**
32       * The version of the underlying metadata model.
33       */
34      final String modelVersion;
35      /**
36       * The groupId when this directory represents "groupId/artifactId" or "groupId/artifactId/version".
37       */
38      final String groupId;
39      /**
40       * The artifactId when this directory represents "groupId/artifactId" or "groupId/artifactId/version".
41       */
42      final String artifactId;
43      /**
44       * Versioning information when this directory represents "groupId/artifactId" or "groupId/artifactId/version".
45       */
46      final Versioning versioning;
47      /**
48       * The base version (i.e. ending in {@code -SNAPSHOT}) when this directory represents a "groupId/artifactId/version" for a SNAPSHOT.
49       */
50      final String version;
51      /**
52       * The set of plugins when this directory represents a "groupId".
53       */
54      final List<Plugin> plugins;
55  
56      /**
57        * Constructor for this class, to be called from its subclasses and {@link Builder}.
58        * @see Builder#build()
59        */
60      protected Metadata(Builder builder) {
61          this.namespaceUri = builder.namespaceUri != null ? builder.namespaceUri : (builder.base != null ? builder.base.namespaceUri : null);
62          this.modelEncoding = builder.modelEncoding != null ? builder.modelEncoding : (builder.base != null ? builder.base.modelEncoding :  "UTF-8");
63          this.modelVersion = builder.modelVersion != null ? builder.modelVersion : (builder.base != null ? builder.base.modelVersion : null);
64          this.groupId = builder.groupId != null ? builder.groupId : (builder.base != null ? builder.base.groupId : null);
65          this.artifactId = builder.artifactId != null ? builder.artifactId : (builder.base != null ? builder.base.artifactId : null);
66          this.versioning = builder.versioning != null ? builder.versioning : (builder.base != null ? builder.base.versioning : null);
67          this.version = builder.version != null ? builder.version : (builder.base != null ? builder.base.version : null);
68          this.plugins = ImmutableCollections.copy(builder.plugins != null ? builder.plugins : (builder.base != null ? builder.base.plugins : null));
69      }
70  
71      public String getNamespaceUri() {
72          return namespaceUri;
73      }
74  
75      public String getModelEncoding() {
76          return modelEncoding;
77      }
78  
79      /**
80       * The version of the underlying metadata model.
81       *
82       * @return a {@code String}
83       */
84      public String getModelVersion() {
85          return this.modelVersion;
86      }
87  
88      /**
89       * The groupId when this directory represents "groupId/artifactId" or "groupId/artifactId/version".
90       *
91       * @return a {@code String}
92       */
93      public String getGroupId() {
94          return this.groupId;
95      }
96  
97      /**
98       * The artifactId when this directory represents "groupId/artifactId" or "groupId/artifactId/version".
99       *
100      * @return a {@code String}
101      */
102     public String getArtifactId() {
103         return this.artifactId;
104     }
105 
106     /**
107      * Versioning information when this directory represents "groupId/artifactId" or "groupId/artifactId/version".
108      *
109      * @return a {@code Versioning}
110      */
111     public Versioning getVersioning() {
112         return this.versioning;
113     }
114 
115     /**
116      * The base version (i.e. ending in {@code -SNAPSHOT}) when this directory represents a "groupId/artifactId/version" for a SNAPSHOT.
117      *
118      * @return a {@code String}
119      */
120     public String getVersion() {
121         return this.version;
122     }
123 
124     /**
125      * The set of plugins when this directory represents a "groupId".
126      *
127      * @return a {@code List<Plugin>}
128      */
129     @Nonnull
130     public List<Plugin> getPlugins() {
131         return this.plugins;
132     }
133 
134     /**
135      * Creates a new builder with this object as the basis.
136      *
137      * @return a {@code Builder}
138      */
139     @Nonnull
140     public Builder with() {
141         return newBuilder(this);
142     }
143     /**
144      * Creates a new {@code Metadata} instance using the specified modelVersion.
145      *
146      * @param modelVersion the new {@code String} to use
147      * @return a {@code Metadata} with the specified modelVersion
148      */
149     @Nonnull
150     public Metadata withModelVersion(String modelVersion) {
151         return newBuilder(this, true).modelVersion(modelVersion).build();
152     }
153     /**
154      * Creates a new {@code Metadata} instance using the specified groupId.
155      *
156      * @param groupId the new {@code String} to use
157      * @return a {@code Metadata} with the specified groupId
158      */
159     @Nonnull
160     public Metadata withGroupId(String groupId) {
161         return newBuilder(this, true).groupId(groupId).build();
162     }
163     /**
164      * Creates a new {@code Metadata} instance using the specified artifactId.
165      *
166      * @param artifactId the new {@code String} to use
167      * @return a {@code Metadata} with the specified artifactId
168      */
169     @Nonnull
170     public Metadata withArtifactId(String artifactId) {
171         return newBuilder(this, true).artifactId(artifactId).build();
172     }
173     /**
174      * Creates a new {@code Metadata} instance using the specified versioning.
175      *
176      * @param versioning the new {@code Versioning} to use
177      * @return a {@code Metadata} with the specified versioning
178      */
179     @Nonnull
180     public Metadata withVersioning(Versioning versioning) {
181         return newBuilder(this, true).versioning(versioning).build();
182     }
183     /**
184      * Creates a new {@code Metadata} instance using the specified version.
185      *
186      * @param version the new {@code String} to use
187      * @return a {@code Metadata} with the specified version
188      */
189     @Nonnull
190     public Metadata withVersion(String version) {
191         return newBuilder(this, true).version(version).build();
192     }
193     /**
194      * Creates a new {@code Metadata} instance using the specified plugins.
195      *
196      * @param plugins the new {@code Collection<Plugin>} to use
197      * @return a {@code Metadata} with the specified plugins
198      */
199     @Nonnull
200     public Metadata withPlugins(Collection<Plugin> plugins) {
201         return newBuilder(this, true).plugins(plugins).build();
202     }
203 
204     /**
205      * Creates a new {@code Metadata} instance.
206      * Equivalent to {@code newInstance(true)}.
207      * @see #newInstance(boolean)
208      *
209      * @return a new {@code Metadata}
210      */
211     @Nonnull
212     public static Metadata newInstance() {
213         return newInstance(true);
214     }
215 
216     /**
217      * Creates a new {@code Metadata} instance using default values or not.
218      * Equivalent to {@code newBuilder(withDefaults).build()}.
219      *
220      * @param withDefaults the boolean indicating whether default values should be used
221      * @return a new {@code Metadata}
222      */
223     @Nonnull
224     public static Metadata newInstance(boolean withDefaults) {
225         return newBuilder(withDefaults).build();
226     }
227 
228     /**
229      * Creates a new {@code Metadata} builder instance.
230      * Equivalent to {@code newBuilder(true)}.
231      * @see #newBuilder(boolean)
232      *
233      * @return a new {@code Builder}
234      */
235     @Nonnull
236     public static Builder newBuilder() {
237         return newBuilder(true);
238     }
239 
240     /**
241      * Creates a new {@code Metadata} builder instance using default values or not.
242      *
243      * @param withDefaults the boolean indicating whether default values should be used
244      * @return a new {@code Builder}
245      */
246     @Nonnull
247     public static Builder newBuilder(boolean withDefaults) {
248         return new Builder(withDefaults);
249     }
250 
251     /**
252      * Creates a new {@code Metadata} builder instance using the specified object as a basis.
253      * Equivalent to {@code newBuilder(from, false)}.
254      *
255      * @param from the {@code Metadata} instance to use as a basis
256      * @return a new {@code Builder}
257      */
258     @Nonnull
259     public static Builder newBuilder(Metadata from) {
260         return newBuilder(from, false);
261     }
262 
263     /**
264      * Creates a new {@code Metadata} builder instance using the specified object as a basis.
265      *
266      * @param from the {@code Metadata} instance to use as a basis
267      * @param forceCopy the boolean indicating if a copy should be forced
268      * @return a new {@code Builder}
269      */
270     @Nonnull
271     public static Builder newBuilder(Metadata from, boolean forceCopy) {
272         return new Builder(from, forceCopy);
273     }
274 
275     /**
276      * Builder class used to create Metadata instances.
277      * @see #with()
278      * @see #newBuilder()
279      */
280     @NotThreadSafe
281     public static class Builder
282     {
283         Metadata base;
284         String namespaceUri;
285         String modelEncoding;
286         String modelVersion;
287         String groupId;
288         String artifactId;
289         Versioning versioning;
290         String version;
291         Collection<Plugin> plugins;
292 
293         protected Builder(boolean withDefaults) {
294             if (withDefaults) {
295             }
296         }
297 
298         protected Builder(Metadata base, boolean forceCopy) {
299             this.namespaceUri = base.namespaceUri;
300             this.modelEncoding = base.modelEncoding;
301             if (forceCopy) {
302                 this.modelVersion = base.modelVersion;
303                 this.groupId = base.groupId;
304                 this.artifactId = base.artifactId;
305                 this.versioning = base.versioning;
306                 this.version = base.version;
307                 this.plugins = base.plugins;
308             } else {
309                 this.base = base;
310             }
311         }
312 
313         @Nonnull
314         public Builder namespaceUri(String namespaceUri) {
315             this.namespaceUri = namespaceUri;
316             return this;
317         }
318 
319         @Nonnull
320         public Builder modelEncoding(String modelEncoding) {
321             this.modelEncoding = modelEncoding;
322             return this;
323         }
324 
325         @Nonnull
326         public Builder modelVersion(String modelVersion) {
327             this.modelVersion = modelVersion;
328             return this;
329         }
330 
331         @Nonnull
332         public Builder groupId(String groupId) {
333             this.groupId = groupId;
334             return this;
335         }
336 
337         @Nonnull
338         public Builder artifactId(String artifactId) {
339             this.artifactId = artifactId;
340             return this;
341         }
342 
343         @Nonnull
344         public Builder versioning(Versioning versioning) {
345             this.versioning = versioning;
346             return this;
347         }
348 
349         @Nonnull
350         public Builder version(String version) {
351             this.version = version;
352             return this;
353         }
354 
355         @Nonnull
356         public Builder plugins(Collection<Plugin> plugins) {
357             this.plugins = plugins;
358             return this;
359         }
360 
361 
362         @Nonnull
363         public Metadata build() {
364             // this method should not contain any logic other than creating (or reusing) an object in order to ease subclassing
365             if (base != null
366                     && (modelVersion == null || modelVersion == base.modelVersion)
367                     && (groupId == null || groupId == base.groupId)
368                     && (artifactId == null || artifactId == base.artifactId)
369                     && (versioning == null || versioning == base.versioning)
370                     && (version == null || version == base.version)
371                     && (plugins == null || plugins == base.plugins)
372             ) {
373                 return base;
374             }
375             return new Metadata(this);
376         }
377     }
378 
379 }