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