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