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