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