1
2
3
4
5 package org.apache.maven.api.model;
6
7 import java.io.Serializable;
8 import java.util.Collections;
9 import java.util.HashMap;
10 import java.util.Map;
11 import java.util.Set;
12 import org.apache.maven.api.annotations.Experimental;
13 import org.apache.maven.api.annotations.Generated;
14 import org.apache.maven.api.annotations.Immutable;
15 import org.apache.maven.api.annotations.Nonnull;
16 import org.apache.maven.api.annotations.NotThreadSafe;
17 import org.apache.maven.api.annotations.ThreadSafe;
18
19
20
21
22
23
24 @Experimental
25 @Generated @ThreadSafe @Immutable
26 public class Parent
27 implements Serializable, InputLocationTracker
28 {
29
30
31
32 final String groupId;
33
34
35
36 final String artifactId;
37
38
39
40 final String version;
41
42
43
44
45
46
47
48
49
50
51 final String relativePath;
52
53 final Map<Object, InputLocation> locations;
54
55 final InputLocation importedFrom;
56
57
58
59
60
61 protected Parent(Builder builder) {
62 this.groupId = builder.groupId != null ? builder.groupId : (builder.base != null ? builder.base.groupId : null);
63 this.artifactId = builder.artifactId != null ? builder.artifactId : (builder.base != null ? builder.base.artifactId : null);
64 this.version = builder.version != null ? builder.version : (builder.base != null ? builder.base.version : null);
65 this.relativePath = builder.relativePath != null ? builder.relativePath : (builder.base != null ? builder.base.relativePath : null);
66 Map<Object, InputLocation> newlocs = builder.locations != null ? builder.locations : Collections.emptyMap();
67 Map<Object, InputLocation> oldlocs = builder.base != null && builder.base.locations != null ? builder.base.locations : Collections.emptyMap();
68 Map<Object, InputLocation> mutableLocations = new HashMap<>();
69 this.importedFrom = builder.importedFrom;
70 mutableLocations.put("", newlocs.containsKey("") ? newlocs.get("") : oldlocs.get(""));
71 mutableLocations.put("groupId", newlocs.containsKey("groupId") ? newlocs.get("groupId") : oldlocs.get("groupId"));
72 mutableLocations.put("artifactId", newlocs.containsKey("artifactId") ? newlocs.get("artifactId") : oldlocs.get("artifactId"));
73 mutableLocations.put("version", newlocs.containsKey("version") ? newlocs.get("version") : oldlocs.get("version"));
74 mutableLocations.put("relativePath", newlocs.containsKey("relativePath") ? newlocs.get("relativePath") : oldlocs.get("relativePath"));
75 this.locations = Collections.unmodifiableMap(mutableLocations);
76 }
77
78
79
80
81
82
83 public String getGroupId() {
84 return this.groupId;
85 }
86
87
88
89
90
91
92 public String getArtifactId() {
93 return this.artifactId;
94 }
95
96
97
98
99
100
101 public String getVersion() {
102 return this.version;
103 }
104
105
106
107
108
109
110
111
112
113
114
115
116
117 public String getRelativePath() {
118 return this.relativePath;
119 }
120
121
122
123
124 public InputLocation getLocation(Object key) {
125 return locations != null ? locations.get(key) : null;
126 }
127
128
129
130
131 public Set<Object> getLocationKeys() {
132 return locations != null ? locations.keySet() : null;
133 }
134
135
136
137
138 public InputLocation getImportedFrom()
139 {
140 return importedFrom;
141 }
142
143
144
145
146
147
148 @Nonnull
149 public Builder with() {
150 return newBuilder(this);
151 }
152
153
154
155
156
157
158 @Nonnull
159 public Parent withGroupId(String groupId) {
160 return newBuilder(this, true).groupId(groupId).build();
161 }
162
163
164
165
166
167
168 @Nonnull
169 public Parent withArtifactId(String artifactId) {
170 return newBuilder(this, true).artifactId(artifactId).build();
171 }
172
173
174
175
176
177
178 @Nonnull
179 public Parent withVersion(String version) {
180 return newBuilder(this, true).version(version).build();
181 }
182
183
184
185
186
187
188 @Nonnull
189 public Parent withRelativePath(String relativePath) {
190 return newBuilder(this, true).relativePath(relativePath).build();
191 }
192
193
194
195
196
197
198
199
200 @Nonnull
201 public static Parent newInstance() {
202 return newInstance(true);
203 }
204
205
206
207
208
209
210
211
212 @Nonnull
213 public static Parent newInstance(boolean withDefaults) {
214 return newBuilder(withDefaults).build();
215 }
216
217
218
219
220
221
222
223
224 @Nonnull
225 public static Builder newBuilder() {
226 return newBuilder(true);
227 }
228
229
230
231
232
233
234
235 @Nonnull
236 public static Builder newBuilder(boolean withDefaults) {
237 return new Builder(withDefaults);
238 }
239
240
241
242
243
244
245
246
247 @Nonnull
248 public static Builder newBuilder(Parent from) {
249 return newBuilder(from, false);
250 }
251
252
253
254
255
256
257
258
259 @Nonnull
260 public static Builder newBuilder(Parent from, boolean forceCopy) {
261 return new Builder(from, forceCopy);
262 }
263
264
265
266
267
268
269 @NotThreadSafe
270 public static class Builder
271 {
272 Parent base;
273 String groupId;
274 String artifactId;
275 String version;
276 String relativePath;
277 Map<Object, InputLocation> locations;
278 InputLocation importedFrom;
279
280 protected Builder(boolean withDefaults) {
281 if (withDefaults) {
282 }
283 }
284
285 protected Builder(Parent base, boolean forceCopy) {
286 if (forceCopy) {
287 this.groupId = base.groupId;
288 this.artifactId = base.artifactId;
289 this.version = base.version;
290 this.relativePath = base.relativePath;
291 this.locations = base.locations;
292 this.importedFrom = base.importedFrom;
293 } else {
294 this.base = base;
295 }
296 }
297
298 @Nonnull
299 public Builder groupId(String groupId) {
300 this.groupId = groupId;
301 return this;
302 }
303
304 @Nonnull
305 public Builder artifactId(String artifactId) {
306 this.artifactId = artifactId;
307 return this;
308 }
309
310 @Nonnull
311 public Builder version(String version) {
312 this.version = version;
313 return this;
314 }
315
316 @Nonnull
317 public Builder relativePath(String relativePath) {
318 this.relativePath = relativePath;
319 return this;
320 }
321
322
323 @Nonnull
324 public Builder location(Object key, InputLocation location) {
325 if (location != null) {
326 if (!(this.locations instanceof HashMap)) {
327 this.locations = this.locations != null ? new HashMap<>(this.locations) : new HashMap<>();
328 }
329 this.locations.put(key, location);
330 }
331 return this;
332 }
333
334 @Nonnull
335 public Builder importedFrom(InputLocation importedFrom) {
336 this.importedFrom = importedFrom;
337 return this;
338 }
339
340 @Nonnull
341 public Parent build() {
342
343 if (base != null
344 && (groupId == null || groupId == base.groupId)
345 && (artifactId == null || artifactId == base.artifactId)
346 && (version == null || version == base.version)
347 && (relativePath == null || relativePath == base.relativePath)
348 ) {
349 return base;
350 }
351 return new Parent(this);
352 }
353 }
354
355
356
357
358
359
360 public String getId() {
361 return getGroupId() + ":" + getArtifactId() + ":pom:" + getVersion();
362 }
363
364 @Override
365 public String toString() {
366 return getId();
367 }
368
369
370 }