1
2
3
4
5 package org.apache.maven.api.toolchain;
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 import org.apache.maven.api.xml.XmlNode;
19
20
21
22
23 @Experimental
24 @Generated @ThreadSafe @Immutable
25 public class ToolchainModel
26 extends TrackableBase
27 implements Serializable, InputLocationTracker
28 {
29
30
31
32
33
34
35
36
37 final String type;
38
39
40
41
42
43
44
45
46 final Map<String, String> provides;
47
48
49
50
51
52
53
54 final XmlNode configuration;
55
56 final Map<Object, InputLocation> locations;
57
58
59
60
61
62 protected ToolchainModel(Builder builder) {
63 super(builder);
64 this.type = builder.type != null ? builder.type : (builder.base != null ? builder.base.type : null);
65 this.provides = ImmutableCollections.copy(builder.provides != null ? builder.provides : (builder.base != null ? builder.base.provides : null));
66 this.configuration = builder.configuration != null ? builder.configuration : (builder.base != null ? builder.base.configuration : null);
67 Map<Object, InputLocation> newlocs = builder.locations != null ? builder.locations : Collections.emptyMap();
68 Map<Object, InputLocation> oldlocs = builder.base != null && builder.base.locations != null ? builder.base.locations : Collections.emptyMap();
69 Map<Object, InputLocation> mutableLocations = new HashMap<>(super.locations);
70 mutableLocations.put("type", newlocs.containsKey("type") ? newlocs.get("type") : oldlocs.get("type"));
71 mutableLocations.put("provides", newlocs.containsKey("provides") ? newlocs.get("provides") : oldlocs.get("provides"));
72 mutableLocations.put("configuration", newlocs.containsKey("configuration") ? newlocs.get("configuration") : oldlocs.get("configuration"));
73 this.locations = Collections.unmodifiableMap(mutableLocations);
74 }
75
76
77
78
79
80
81
82
83
84
85
86 public String getType() {
87 return this.type;
88 }
89
90
91
92
93
94
95
96
97
98
99
100 @Nonnull
101 public Map<String, String> getProvides() {
102 return this.provides;
103 }
104
105
106
107
108
109
110
111
112
113
114 public XmlNode getConfiguration() {
115 return this.configuration;
116 }
117
118
119
120
121 public InputLocation getLocation(Object key) {
122 return locations != null ? locations.get(key) : null;
123 }
124
125
126
127
128 public Set<Object> getLocationKeys() {
129 return locations != null ? locations.keySet() : null;
130 }
131
132
133
134
135
136
137 @Nonnull
138 public Builder with() {
139 return newBuilder(this);
140 }
141
142
143
144
145
146
147 @Nonnull
148 public ToolchainModel withType(String type) {
149 return newBuilder(this, true).type(type).build();
150 }
151
152
153
154
155
156
157 @Nonnull
158 public ToolchainModel withProvides(Map<String, String> provides) {
159 return newBuilder(this, true).provides(provides).build();
160 }
161
162
163
164
165
166
167 @Nonnull
168 public ToolchainModel withConfiguration(XmlNode configuration) {
169 return newBuilder(this, true).configuration(configuration).build();
170 }
171
172
173
174
175
176
177
178
179 @Nonnull
180 public static ToolchainModel newInstance() {
181 return newInstance(true);
182 }
183
184
185
186
187
188
189
190
191 @Nonnull
192 public static ToolchainModel newInstance(boolean withDefaults) {
193 return newBuilder(withDefaults).build();
194 }
195
196
197
198
199
200
201
202
203 @Nonnull
204 public static Builder newBuilder() {
205 return newBuilder(true);
206 }
207
208
209
210
211
212
213
214 @Nonnull
215 public static Builder newBuilder(boolean withDefaults) {
216 return new Builder(withDefaults);
217 }
218
219
220
221
222
223
224
225
226 @Nonnull
227 public static Builder newBuilder(ToolchainModel from) {
228 return newBuilder(from, false);
229 }
230
231
232
233
234
235
236
237
238 @Nonnull
239 public static Builder newBuilder(ToolchainModel from, boolean forceCopy) {
240 return new Builder(from, forceCopy);
241 }
242
243
244
245
246
247
248 @NotThreadSafe
249 public static class Builder
250 extends TrackableBase.Builder
251 {
252 ToolchainModel base;
253 String type;
254 Map<String, String> provides;
255 XmlNode configuration;
256
257 protected Builder(boolean withDefaults) {
258 super(withDefaults);
259 if (withDefaults) {
260 }
261 }
262
263 protected Builder(ToolchainModel base, boolean forceCopy) {
264 super(base, forceCopy);
265 if (forceCopy) {
266 this.type = base.type;
267 this.provides = base.provides;
268 this.configuration = base.configuration;
269 this.locations = base.locations;
270 this.importedFrom = base.importedFrom;
271 } else {
272 this.base = base;
273 }
274 }
275
276 @Nonnull
277 public Builder type(String type) {
278 this.type = type;
279 return this;
280 }
281
282 @Nonnull
283 public Builder provides(Map<String, String> provides) {
284 this.provides = provides;
285 return this;
286 }
287
288 @Nonnull
289 public Builder configuration(XmlNode configuration) {
290 this.configuration = configuration;
291 return this;
292 }
293
294
295 @Nonnull
296 public Builder location(Object key, InputLocation location) {
297 if (location != null) {
298 if (!(this.locations instanceof HashMap)) {
299 this.locations = this.locations != null ? new HashMap<>(this.locations) : new HashMap<>();
300 }
301 this.locations.put(key, location);
302 }
303 return this;
304 }
305
306 @Nonnull
307 public Builder importedFrom(InputLocation importedFrom) {
308 this.importedFrom = importedFrom;
309 return this;
310 }
311
312 @Nonnull
313 public ToolchainModel build() {
314
315 if (base != null
316 && (type == null || type == base.type)
317 && (provides == null || provides == base.provides)
318 && (configuration == null || configuration == base.configuration)
319 ) {
320 return base;
321 }
322 return new ToolchainModel(this);
323 }
324 }
325
326
327
328
329
330
331 public int hashCode() {
332 return java.util.Objects.hash(getType(), getProvides());
333 }
334
335
336
337
338 public boolean equals(Object other) {
339 if (this == other) {
340 return true;
341 } else if (!(other instanceof ToolchainModel)) {
342 return false;
343 } else {
344 ToolchainModel that = (ToolchainModel) other;
345 return java.util.Objects.equals(this.getType(), that.getType())
346 && java.util.Objects.equals(this.getProvides(), that.getProvides());
347 }
348 }
349
350
351 }