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