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