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