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