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