1 // =================== DO NOT EDIT THIS FILE ====================
2 // Generated by Modello Velocity from model.vm
3 // template, any modifications will be overwritten.
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 * A download mirror for a given repository.
25 */
26 @Experimental
27 @Generated @ThreadSafe @Immutable
28 public class Mirror
29 extends IdentifiableBase
30 implements Serializable, InputLocationTracker
31 {
32 /**
33 * A repository id or (since Maven 2.0.9) an expression matching one or many repository ids to mirror, e.g.,
34 * <code>central</code> or <code>*,!repo1</code>.
35 * <code>*</code> (since Maven 2.0.5), <code>external:*</code> (since Maven 2.0.9) and <code>external:http:*</code> (since Maven 3.8.0) have
36 * a special meaning: see <a href="/guides/mini/guide-mirror-settings.html">Mirror Settings</a> guide.
37 */
38 final String mirrorOf;
39 /**
40 * The optional name that describes the mirror.
41 */
42 final String name;
43 /**
44 * The URL of the mirror repository.
45 */
46 final String url;
47 /**
48 * The layout of the mirror repository.
49 * @since Maven 3.
50 */
51 final String layout;
52 /**
53 * The layouts of repositories being mirrored. This value can be used to restrict the usage
54 * of the mirror to repositories with a matching layout (apart from a matching id).
55 * @since Maven 3.
56 */
57 final String mirrorOfLayouts;
58 /**
59 * Whether this mirror should be blocked from any download request but fail the download process, explaining why.
60 * <br><b>Default value is</b>: <code>false</code>
61 * <br><b>Since</b>: Maven 3.8.0
62 */
63 final boolean blocked;
64
65 /**
66 * Constructor for this class, to be called from its subclasses and {@link Builder}.
67 * @see Builder#build()
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 * A repository id or (since Maven 2.0.9) an expression matching one or many repository ids to mirror, e.g.,
81 * <code>central</code> or <code>*,!repo1</code>.
82 * <code>*</code> (since Maven 2.0.5), <code>external:*</code> (since Maven 2.0.9) and <code>external:http:*</code> (since Maven 3.8.0) have
83 * a special meaning: see <a href="/guides/mini/guide-mirror-settings.html">Mirror Settings</a> guide.
84 *
85 * @return a {@code String}
86 */
87 public String getMirrorOf() {
88 return this.mirrorOf;
89 }
90
91 /**
92 * The optional name that describes the mirror.
93 *
94 * @return a {@code String}
95 */
96 public String getName() {
97 return this.name;
98 }
99
100 /**
101 * The URL of the mirror repository.
102 *
103 * @return a {@code String}
104 */
105 public String getUrl() {
106 return this.url;
107 }
108
109 /**
110 * The layout of the mirror repository.
111 * @since Maven 3.
112 *
113 * @return a {@code String}
114 */
115 public String getLayout() {
116 return this.layout;
117 }
118
119 /**
120 * The layouts of repositories being mirrored. This value can be used to restrict the usage
121 * of the mirror to repositories with a matching layout (apart from a matching id).
122 * @since Maven 3.
123 *
124 * @return a {@code String}
125 */
126 public String getMirrorOfLayouts() {
127 return this.mirrorOfLayouts;
128 }
129
130 /**
131 * Whether this mirror should be blocked from any download request but fail the download process, explaining why.
132 * <br><b>Default value is</b>: <code>false</code>
133 * <br><b>Since</b>: Maven 3.8.0
134 *
135 * @return a {@code boolean}
136 */
137 public boolean isBlocked() {
138 return this.blocked;
139 }
140
141 /**
142 * Creates a new builder with this object as the basis.
143 *
144 * @return a {@code Builder}
145 */
146 @Nonnull
147 public Builder with() {
148 return newBuilder(this);
149 }
150 /**
151 * Creates a new {@code Mirror} instance using the specified id.
152 *
153 * @param id the new {@code String} to use
154 * @return a {@code Mirror} with the specified id
155 */
156 @Nonnull
157 public Mirror withId(String id) {
158 return newBuilder(this, true).id(id).build();
159 }
160 /**
161 * Creates a new {@code Mirror} instance using the specified mirrorOf.
162 *
163 * @param mirrorOf the new {@code String} to use
164 * @return a {@code Mirror} with the specified mirrorOf
165 */
166 @Nonnull
167 public Mirror withMirrorOf(String mirrorOf) {
168 return newBuilder(this, true).mirrorOf(mirrorOf).build();
169 }
170 /**
171 * Creates a new {@code Mirror} instance using the specified name.
172 *
173 * @param name the new {@code String} to use
174 * @return a {@code Mirror} with the specified name
175 */
176 @Nonnull
177 public Mirror withName(String name) {
178 return newBuilder(this, true).name(name).build();
179 }
180 /**
181 * Creates a new {@code Mirror} instance using the specified url.
182 *
183 * @param url the new {@code String} to use
184 * @return a {@code Mirror} with the specified url
185 */
186 @Nonnull
187 public Mirror withUrl(String url) {
188 return newBuilder(this, true).url(url).build();
189 }
190 /**
191 * Creates a new {@code Mirror} instance using the specified layout.
192 *
193 * @param layout the new {@code String} to use
194 * @return a {@code Mirror} with the specified layout
195 */
196 @Nonnull
197 public Mirror withLayout(String layout) {
198 return newBuilder(this, true).layout(layout).build();
199 }
200 /**
201 * Creates a new {@code Mirror} instance using the specified mirrorOfLayouts.
202 *
203 * @param mirrorOfLayouts the new {@code String} to use
204 * @return a {@code Mirror} with the specified mirrorOfLayouts
205 */
206 @Nonnull
207 public Mirror withMirrorOfLayouts(String mirrorOfLayouts) {
208 return newBuilder(this, true).mirrorOfLayouts(mirrorOfLayouts).build();
209 }
210 /**
211 * Creates a new {@code Mirror} instance using the specified blocked.
212 *
213 * @param blocked the new {@code boolean} to use
214 * @return a {@code Mirror} with the specified blocked
215 */
216 @Nonnull
217 public Mirror withBlocked(boolean blocked) {
218 return newBuilder(this, true).blocked(blocked).build();
219 }
220
221 /**
222 * Creates a new {@code Mirror} instance.
223 * Equivalent to {@code newInstance(true)}.
224 * @see #newInstance(boolean)
225 *
226 * @return a new {@code Mirror}
227 */
228 @Nonnull
229 public static Mirror newInstance() {
230 return newInstance(true);
231 }
232
233 /**
234 * Creates a new {@code Mirror} instance using default values or not.
235 * Equivalent to {@code newBuilder(withDefaults).build()}.
236 *
237 * @param withDefaults the boolean indicating whether default values should be used
238 * @return a new {@code Mirror}
239 */
240 @Nonnull
241 public static Mirror newInstance(boolean withDefaults) {
242 return newBuilder(withDefaults).build();
243 }
244
245 /**
246 * Creates a new {@code Mirror} builder instance.
247 * Equivalent to {@code newBuilder(true)}.
248 * @see #newBuilder(boolean)
249 *
250 * @return a new {@code Builder}
251 */
252 @Nonnull
253 public static Builder newBuilder() {
254 return newBuilder(true);
255 }
256
257 /**
258 * Creates a new {@code Mirror} builder instance using default values or not.
259 *
260 * @param withDefaults the boolean indicating whether default values should be used
261 * @return a new {@code Builder}
262 */
263 @Nonnull
264 public static Builder newBuilder(boolean withDefaults) {
265 return new Builder(withDefaults);
266 }
267
268 /**
269 * Creates a new {@code Mirror} builder instance using the specified object as a basis.
270 * Equivalent to {@code newBuilder(from, false)}.
271 *
272 * @param from the {@code Mirror} instance to use as a basis
273 * @return a new {@code Builder}
274 */
275 @Nonnull
276 public static Builder newBuilder(Mirror from) {
277 return newBuilder(from, false);
278 }
279
280 /**
281 * Creates a new {@code Mirror} builder instance using the specified object as a basis.
282 *
283 * @param from the {@code Mirror} instance to use as a basis
284 * @param forceCopy the boolean indicating if a copy should be forced
285 * @return a new {@code Builder}
286 */
287 @Nonnull
288 public static Builder newBuilder(Mirror from, boolean forceCopy) {
289 return new Builder(from, forceCopy);
290 }
291
292 /**
293 * Builder class used to create Mirror instances.
294 * @see #with()
295 * @see #newBuilder()
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 // this method should not contain any logic other than creating (or reusing) an object in order to ease subclassing
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 }