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