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