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