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