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