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