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