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
18
19
20
21
22 @Experimental
23 @Generated @ThreadSafe @Immutable
24 public class Relocation
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 final String message;
43
44 final Map<Object, InputLocation> locations;
45
46
47
48
49
50 Relocation(
51 String groupId,
52 String artifactId,
53 String version,
54 String message,
55 Map<Object, InputLocation> locations
56 ) {
57 this.groupId = groupId;
58 this.artifactId = artifactId;
59 this.version = version;
60 this.message = message;
61 this.locations = ImmutableCollections.copy(locations);
62 }
63
64
65
66
67
68
69 public String getGroupId() {
70 return this.groupId;
71 }
72
73
74
75
76
77
78 public String getArtifactId() {
79 return this.artifactId;
80 }
81
82
83
84
85
86
87 public String getVersion() {
88 return this.version;
89 }
90
91
92
93
94
95
96 public String getMessage() {
97 return this.message;
98 }
99
100
101
102
103 public InputLocation getLocation(Object key) {
104 return locations != null ? locations.get(key) : null;
105 }
106
107
108
109
110
111
112 @Nonnull
113 public Builder with() {
114 return newBuilder(this);
115 }
116
117
118
119
120
121
122 @Nonnull
123 public Relocation withGroupId(String groupId) {
124 return newBuilder(this, true).groupId(groupId).build();
125 }
126
127
128
129
130
131
132 @Nonnull
133 public Relocation withArtifactId(String artifactId) {
134 return newBuilder(this, true).artifactId(artifactId).build();
135 }
136
137
138
139
140
141
142 @Nonnull
143 public Relocation withVersion(String version) {
144 return newBuilder(this, true).version(version).build();
145 }
146
147
148
149
150
151
152 @Nonnull
153 public Relocation withMessage(String message) {
154 return newBuilder(this, true).message(message).build();
155 }
156
157
158
159
160
161
162
163
164 @Nonnull
165 public static Relocation newInstance() {
166 return newInstance(true);
167 }
168
169
170
171
172
173
174
175
176 @Nonnull
177 public static Relocation newInstance(boolean withDefaults) {
178 return newBuilder(withDefaults).build();
179 }
180
181
182
183
184
185
186
187
188 @Nonnull
189 public static Builder newBuilder() {
190 return newBuilder(true);
191 }
192
193
194
195
196
197
198
199 @Nonnull
200 public static Builder newBuilder(boolean withDefaults) {
201 return new Builder(withDefaults);
202 }
203
204
205
206
207
208
209
210
211 @Nonnull
212 public static Builder newBuilder(Relocation from) {
213 return newBuilder(from, false);
214 }
215
216
217
218
219
220
221
222
223 @Nonnull
224 public static Builder newBuilder(Relocation from, boolean forceCopy) {
225 return new Builder(from, forceCopy);
226 }
227
228
229
230
231
232
233 @NotThreadSafe
234 public static class Builder
235 {
236 Relocation base;
237 String groupId;
238 String artifactId;
239 String version;
240 String message;
241 Map<Object, InputLocation> locations;
242
243 Builder(boolean withDefaults) {
244 if (withDefaults) {
245 }
246 }
247
248 Builder(Relocation base, boolean forceCopy) {
249 if (forceCopy) {
250 this.groupId = base.groupId;
251 this.artifactId = base.artifactId;
252 this.version = base.version;
253 this.message = base.message;
254 this.locations = base.locations;
255 } else {
256 this.base = base;
257 }
258 }
259
260 @Nonnull
261 public Builder groupId(String groupId) {
262 this.groupId = groupId;
263 return this;
264 }
265
266 @Nonnull
267 public Builder artifactId(String artifactId) {
268 this.artifactId = artifactId;
269 return this;
270 }
271
272 @Nonnull
273 public Builder version(String version) {
274 this.version = version;
275 return this;
276 }
277
278 @Nonnull
279 public Builder message(String message) {
280 this.message = message;
281 return this;
282 }
283
284
285 @Nonnull
286 public Builder location(Object key, InputLocation location) {
287 if (location != null) {
288 if (!(this.locations instanceof HashMap)) {
289 this.locations = this.locations != null ? new HashMap<>(this.locations) : new HashMap<>();
290 }
291 this.locations.put(key, location);
292 }
293 return this;
294 }
295
296 @Nonnull
297 public Relocation build() {
298 if (base != null
299 && (groupId == null || groupId == base.groupId)
300 && (artifactId == null || artifactId == base.artifactId)
301 && (version == null || version == base.version)
302 && (message == null || message == base.message)
303 ) {
304 return base;
305 }
306 Map<Object, InputLocation> newlocs = this.locations != null ? this.locations : Collections.emptyMap();
307 Map<Object, InputLocation> oldlocs = this.base != null && this.base.locations != null ? this.base.locations : Collections.emptyMap();
308 Map<Object, InputLocation> locations = new HashMap<>();
309 locations.put("", newlocs.containsKey("") ? newlocs.get("") : oldlocs.get(""));
310 locations.put("groupId", newlocs.containsKey("groupId") ? newlocs.get("groupId") : oldlocs.get("groupId"));
311 locations.put("artifactId", newlocs.containsKey("artifactId") ? newlocs.get("artifactId") : oldlocs.get("artifactId"));
312 locations.put("version", newlocs.containsKey("version") ? newlocs.get("version") : oldlocs.get("version"));
313 locations.put("message", newlocs.containsKey("message") ? newlocs.get("message") : oldlocs.get("message"));
314 return new Relocation(
315 groupId != null ? groupId : (base != null ? base.groupId : null),
316 artifactId != null ? artifactId : (base != null ? base.artifactId : null),
317 version != null ? version : (base != null ? base.version : null),
318 message != null ? message : (base != null ? base.message : null),
319 locations
320 );
321 }
322 }
323
324 }