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