1
2
3
4
5 package org.apache.maven.api.settings;
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 @Experimental
23 @Generated @ThreadSafe @Immutable
24 public class Mirror
25 extends IdentifiableBase
26 implements Serializable, InputLocationTracker
27 {
28
29
30
31
32
33
34 final String mirrorOf;
35
36
37
38 final String name;
39
40
41
42 final String url;
43
44
45
46
47 final String layout;
48
49
50
51
52
53 final String mirrorOfLayouts;
54
55
56
57
58
59 final boolean blocked;
60
61 final Map<Object, InputLocation> locations;
62
63
64
65
66
67 protected Mirror(Builder builder) {
68 super(builder);
69 this.mirrorOf = builder.mirrorOf != null ? builder.mirrorOf : (builder.base != null ? builder.base.mirrorOf : null);
70 this.name = builder.name != null ? builder.name : (builder.base != null ? builder.base.name : null);
71 this.url = builder.url != null ? builder.url : (builder.base != null ? builder.base.url : null);
72 this.layout = builder.layout != null ? builder.layout : (builder.base != null ? builder.base.layout : null);
73 this.mirrorOfLayouts = builder.mirrorOfLayouts != null ? builder.mirrorOfLayouts : (builder.base != null ? builder.base.mirrorOfLayouts : null);
74 this.blocked = builder.blocked != null ? builder.blocked : (builder.base != null ? builder.base.blocked : false);
75 Map<Object, InputLocation> newlocs = builder.locations != null ? builder.locations : Collections.emptyMap();
76 Map<Object, InputLocation> oldlocs = builder.base != null && builder.base.locations != null ? builder.base.locations : Collections.emptyMap();
77 Map<Object, InputLocation> mutableLocations = new HashMap<>(super.locations);
78 mutableLocations.put("mirrorOf", newlocs.containsKey("mirrorOf") ? newlocs.get("mirrorOf") : oldlocs.get("mirrorOf"));
79 mutableLocations.put("name", newlocs.containsKey("name") ? newlocs.get("name") : oldlocs.get("name"));
80 mutableLocations.put("url", newlocs.containsKey("url") ? newlocs.get("url") : oldlocs.get("url"));
81 mutableLocations.put("layout", newlocs.containsKey("layout") ? newlocs.get("layout") : oldlocs.get("layout"));
82 mutableLocations.put("mirrorOfLayouts", newlocs.containsKey("mirrorOfLayouts") ? newlocs.get("mirrorOfLayouts") : oldlocs.get("mirrorOfLayouts"));
83 mutableLocations.put("blocked", newlocs.containsKey("blocked") ? newlocs.get("blocked") : oldlocs.get("blocked"));
84 this.locations = Collections.unmodifiableMap(mutableLocations);
85 }
86
87
88
89
90
91
92
93
94
95 public String getMirrorOf() {
96 return this.mirrorOf;
97 }
98
99
100
101
102
103
104 public String getName() {
105 return this.name;
106 }
107
108
109
110
111
112
113 public String getUrl() {
114 return this.url;
115 }
116
117
118
119
120
121
122
123 public String getLayout() {
124 return this.layout;
125 }
126
127
128
129
130
131
132
133
134 public String getMirrorOfLayouts() {
135 return this.mirrorOfLayouts;
136 }
137
138
139
140
141
142
143
144
145 public boolean isBlocked() {
146 return this.blocked;
147 }
148
149
150
151
152 public InputLocation getLocation(Object key) {
153 return locations != null ? locations.get(key) : null;
154 }
155
156
157
158
159 public Set<Object> getLocationKeys() {
160 return locations != null ? locations.keySet() : null;
161 }
162
163
164
165
166
167
168 @Nonnull
169 public Builder with() {
170 return newBuilder(this);
171 }
172
173
174
175
176
177
178 @Nonnull
179 public Mirror withId(String id) {
180 return newBuilder(this, true).id(id).build();
181 }
182
183
184
185
186
187
188 @Nonnull
189 public Mirror withMirrorOf(String mirrorOf) {
190 return newBuilder(this, true).mirrorOf(mirrorOf).build();
191 }
192
193
194
195
196
197
198 @Nonnull
199 public Mirror withName(String name) {
200 return newBuilder(this, true).name(name).build();
201 }
202
203
204
205
206
207
208 @Nonnull
209 public Mirror withUrl(String url) {
210 return newBuilder(this, true).url(url).build();
211 }
212
213
214
215
216
217
218 @Nonnull
219 public Mirror withLayout(String layout) {
220 return newBuilder(this, true).layout(layout).build();
221 }
222
223
224
225
226
227
228 @Nonnull
229 public Mirror withMirrorOfLayouts(String mirrorOfLayouts) {
230 return newBuilder(this, true).mirrorOfLayouts(mirrorOfLayouts).build();
231 }
232
233
234
235
236
237
238 @Nonnull
239 public Mirror withBlocked(boolean blocked) {
240 return newBuilder(this, true).blocked(blocked).build();
241 }
242
243
244
245
246
247
248
249
250 @Nonnull
251 public static Mirror newInstance() {
252 return newInstance(true);
253 }
254
255
256
257
258
259
260
261
262 @Nonnull
263 public static Mirror newInstance(boolean withDefaults) {
264 return newBuilder(withDefaults).build();
265 }
266
267
268
269
270
271
272
273
274 @Nonnull
275 public static Builder newBuilder() {
276 return newBuilder(true);
277 }
278
279
280
281
282
283
284
285 @Nonnull
286 public static Builder newBuilder(boolean withDefaults) {
287 return new Builder(withDefaults);
288 }
289
290
291
292
293
294
295
296
297 @Nonnull
298 public static Builder newBuilder(Mirror from) {
299 return newBuilder(from, false);
300 }
301
302
303
304
305
306
307
308
309 @Nonnull
310 public static Builder newBuilder(Mirror from, boolean forceCopy) {
311 return new Builder(from, forceCopy);
312 }
313
314
315
316
317
318
319 @NotThreadSafe
320 public static class Builder
321 extends IdentifiableBase.Builder
322 {
323 Mirror base;
324 String mirrorOf;
325 String name;
326 String url;
327 String layout;
328 String mirrorOfLayouts;
329 Boolean blocked;
330
331 protected Builder(boolean withDefaults) {
332 super(withDefaults);
333 if (withDefaults) {
334 this.layout = "default";
335 this.mirrorOfLayouts = "default,legacy";
336 this.blocked = false;
337 }
338 }
339
340 protected Builder(Mirror base, boolean forceCopy) {
341 super(base, forceCopy);
342 if (forceCopy) {
343 this.mirrorOf = base.mirrorOf;
344 this.name = base.name;
345 this.url = base.url;
346 this.layout = base.layout;
347 this.mirrorOfLayouts = base.mirrorOfLayouts;
348 this.blocked = base.blocked;
349 this.locations = base.locations;
350 this.importedFrom = base.importedFrom;
351 } else {
352 this.base = base;
353 }
354 }
355
356 @Nonnull
357 public Builder id(String id) {
358 this.id = id;
359 return this;
360 }
361
362 @Nonnull
363 public Builder mirrorOf(String mirrorOf) {
364 this.mirrorOf = mirrorOf;
365 return this;
366 }
367
368 @Nonnull
369 public Builder name(String name) {
370 this.name = name;
371 return this;
372 }
373
374 @Nonnull
375 public Builder url(String url) {
376 this.url = url;
377 return this;
378 }
379
380 @Nonnull
381 public Builder layout(String layout) {
382 this.layout = layout;
383 return this;
384 }
385
386 @Nonnull
387 public Builder mirrorOfLayouts(String mirrorOfLayouts) {
388 this.mirrorOfLayouts = mirrorOfLayouts;
389 return this;
390 }
391
392 @Nonnull
393 public Builder blocked(boolean blocked) {
394 this.blocked = blocked;
395 return this;
396 }
397
398
399 @Nonnull
400 public Builder location(Object key, InputLocation location) {
401 if (location != null) {
402 if (!(this.locations instanceof HashMap)) {
403 this.locations = this.locations != null ? new HashMap<>(this.locations) : new HashMap<>();
404 }
405 this.locations.put(key, location);
406 }
407 return this;
408 }
409
410 @Nonnull
411 public Builder importedFrom(InputLocation importedFrom) {
412 this.importedFrom = importedFrom;
413 return this;
414 }
415
416 @Nonnull
417 public Mirror build() {
418
419 if (base != null
420 && (id == null || id == base.id)
421 && (mirrorOf == null || mirrorOf == base.mirrorOf)
422 && (name == null || name == base.name)
423 && (url == null || url == base.url)
424 && (layout == null || layout == base.layout)
425 && (mirrorOfLayouts == null || mirrorOfLayouts == base.mirrorOfLayouts)
426 && (blocked == null || blocked == base.blocked)
427 ) {
428 return base;
429 }
430 return new Mirror(this);
431 }
432 }
433
434
435
436
437 public String toString() {
438 StringBuilder sb = new StringBuilder(128);
439 sb.append("Mirror[");
440 sb.append("id=").append(this.getId());
441 sb.append(",mirrorOf=").append(this.getMirrorOf());
442 sb.append(",url=").append(this.getUrl());
443 sb.append(",name=").append(this.getName());
444 if (isBlocked()) {
445 sb.append(",blocked");
446 }
447 sb.append("]");
448 return sb.toString();
449 }
450
451
452 }