1
2
3
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
32
33 final String modelVersion;
34
35
36
37 final String groupId;
38
39
40
41 final String artifactId;
42
43
44
45 final Versioning versioning;
46
47
48
49 final String version;
50
51
52
53 final List<Plugin> plugins;
54
55
56
57
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
89
90
91
92 public String getModelVersion() {
93 return this.modelVersion;
94 }
95
96
97
98
99
100
101 public String getGroupId() {
102 return this.groupId;
103 }
104
105
106
107
108
109
110 public String getArtifactId() {
111 return this.artifactId;
112 }
113
114
115
116
117
118
119 public Versioning getVersioning() {
120 return this.versioning;
121 }
122
123
124
125
126
127
128 public String getVersion() {
129 return this.version;
130 }
131
132
133
134
135
136
137 @Nonnull
138 public List<Plugin> getPlugins() {
139 return this.plugins;
140 }
141
142
143
144
145
146
147 @Nonnull
148 public Builder with() {
149 return newBuilder(this);
150 }
151
152
153
154
155
156
157 @Nonnull
158 public Metadata withModelVersion(String modelVersion) {
159 return newBuilder(this, true).modelVersion(modelVersion).build();
160 }
161
162
163
164
165
166
167 @Nonnull
168 public Metadata withGroupId(String groupId) {
169 return newBuilder(this, true).groupId(groupId).build();
170 }
171
172
173
174
175
176
177 @Nonnull
178 public Metadata withArtifactId(String artifactId) {
179 return newBuilder(this, true).artifactId(artifactId).build();
180 }
181
182
183
184
185
186
187 @Nonnull
188 public Metadata withVersioning(Versioning versioning) {
189 return newBuilder(this, true).versioning(versioning).build();
190 }
191
192
193
194
195
196
197 @Nonnull
198 public Metadata withVersion(String version) {
199 return newBuilder(this, true).version(version).build();
200 }
201
202
203
204
205
206
207 @Nonnull
208 public Metadata withPlugins(Collection<Plugin> plugins) {
209 return newBuilder(this, true).plugins(plugins).build();
210 }
211
212
213
214
215
216
217
218
219 @Nonnull
220 public static Metadata newInstance() {
221 return newInstance(true);
222 }
223
224
225
226
227
228
229
230
231 @Nonnull
232 public static Metadata newInstance(boolean withDefaults) {
233 return newBuilder(withDefaults).build();
234 }
235
236
237
238
239
240
241
242
243 @Nonnull
244 public static Builder newBuilder() {
245 return newBuilder(true);
246 }
247
248
249
250
251
252
253
254 @Nonnull
255 public static Builder newBuilder(boolean withDefaults) {
256 return new Builder(withDefaults);
257 }
258
259
260
261
262
263
264
265
266 @Nonnull
267 public static Builder newBuilder(Metadata from) {
268 return newBuilder(from, false);
269 }
270
271
272
273
274
275
276
277
278 @Nonnull
279 public static Builder newBuilder(Metadata from, boolean forceCopy) {
280 return new Builder(from, forceCopy);
281 }
282
283
284
285
286
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 }