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