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   * The <code>&lt;proxy&gt;</code> element contains informations required to a proxy settings.
20   */
21  @Experimental
22  @Generated @ThreadSafe @Immutable
23  public class Proxy
24      extends IdentifiableBase
25      implements Serializable
26  {
27      /**
28       * Whether this proxy configuration is the active one.
29       */
30      final boolean active;
31      /**
32       * The proxy protocol.
33       */
34      final String protocol;
35      /**
36       * The proxy user.
37       */
38      final String username;
39      /**
40       * The proxy password.
41       */
42      final String password;
43      /**
44       * The proxy port.
45       */
46      final int port;
47      /**
48       * The proxy host.
49       */
50      final String host;
51      /**
52       * The list of non-proxied hosts (delimited by |).
53       */
54      final String nonProxyHosts;
55  
56      /**
57        * Constructor for this class, package protected.
58        * @see Builder#build()
59        */
60      Proxy(
61          String id,
62          boolean active,
63          String protocol,
64          String username,
65          String password,
66          int port,
67          String host,
68          String nonProxyHosts
69      )
70      {
71          super(
72              id
73          );
74          this.active = active;
75          this.protocol = protocol;
76          this.username = username;
77          this.password = password;
78          this.port = port;
79          this.host = host;
80          this.nonProxyHosts = nonProxyHosts;
81      }
82  
83      /**
84       * Whether this proxy configuration is the active one.
85       *
86       * @return a {@code boolean}
87       */
88      public boolean isActive()
89      {
90          return this.active;
91      }
92  
93      /**
94       * The proxy protocol.
95       *
96       * @return a {@code String}
97       */
98      public String getProtocol()
99      {
100         return this.protocol;
101     }
102 
103     /**
104      * The proxy user.
105      *
106      * @return a {@code String}
107      */
108     public String getUsername()
109     {
110         return this.username;
111     }
112 
113     /**
114      * The proxy password.
115      *
116      * @return a {@code String}
117      */
118     public String getPassword()
119     {
120         return this.password;
121     }
122 
123     /**
124      * The proxy port.
125      *
126      * @return a {@code int}
127      */
128     public int getPort()
129     {
130         return this.port;
131     }
132 
133     /**
134      * The proxy host.
135      *
136      * @return a {@code String}
137      */
138     public String getHost()
139     {
140         return this.host;
141     }
142 
143     /**
144      * The list of non-proxied hosts (delimited by |).
145      *
146      * @return a {@code String}
147      */
148     public String getNonProxyHosts()
149     {
150         return this.nonProxyHosts;
151     }
152 
153     /**
154      * Creates a new builder with this object as the basis.
155      *
156      * @return a {@code Builder}
157      */
158     @Nonnull
159     public Builder with()
160     {
161         return newBuilder( this );
162     }
163     /**
164      * Creates a new {@code Proxy} instance using the specified id.
165      *
166      * @param id the new {@code String} to use
167      * @return a {@code Proxy} with the specified id
168      */
169     @Nonnull
170     public Proxy withId( String id )
171     {
172         return with().id( id ).build();
173     }
174     /**
175      * Creates a new {@code Proxy} instance using the specified active.
176      *
177      * @param active the new {@code boolean} to use
178      * @return a {@code Proxy} with the specified active
179      */
180     @Nonnull
181     public Proxy withActive( boolean active )
182     {
183         return with().active( active ).build();
184     }
185     /**
186      * Creates a new {@code Proxy} instance using the specified protocol.
187      *
188      * @param protocol the new {@code String} to use
189      * @return a {@code Proxy} with the specified protocol
190      */
191     @Nonnull
192     public Proxy withProtocol( String protocol )
193     {
194         return with().protocol( protocol ).build();
195     }
196     /**
197      * Creates a new {@code Proxy} instance using the specified username.
198      *
199      * @param username the new {@code String} to use
200      * @return a {@code Proxy} with the specified username
201      */
202     @Nonnull
203     public Proxy withUsername( String username )
204     {
205         return with().username( username ).build();
206     }
207     /**
208      * Creates a new {@code Proxy} instance using the specified password.
209      *
210      * @param password the new {@code String} to use
211      * @return a {@code Proxy} with the specified password
212      */
213     @Nonnull
214     public Proxy withPassword( String password )
215     {
216         return with().password( password ).build();
217     }
218     /**
219      * Creates a new {@code Proxy} instance using the specified port.
220      *
221      * @param port the new {@code int} to use
222      * @return a {@code Proxy} with the specified port
223      */
224     @Nonnull
225     public Proxy withPort( int port )
226     {
227         return with().port( port ).build();
228     }
229     /**
230      * Creates a new {@code Proxy} instance using the specified host.
231      *
232      * @param host the new {@code String} to use
233      * @return a {@code Proxy} with the specified host
234      */
235     @Nonnull
236     public Proxy withHost( String host )
237     {
238         return with().host( host ).build();
239     }
240     /**
241      * Creates a new {@code Proxy} instance using the specified nonProxyHosts.
242      *
243      * @param nonProxyHosts the new {@code String} to use
244      * @return a {@code Proxy} with the specified nonProxyHosts
245      */
246     @Nonnull
247     public Proxy withNonProxyHosts( String nonProxyHosts )
248     {
249         return with().nonProxyHosts( nonProxyHosts ).build();
250     }
251 
252     /**
253      * Creates a new {@code Proxy} instance.
254      * Equivalent to {@code newInstance( true )}.
255      * @see #newInstance(boolean)
256      *
257      * @return a new {@code Proxy}
258      */
259     @Nonnull
260     public static Proxy newInstance()
261     {
262         return newInstance( true );
263     }
264 
265     /**
266      * Creates a new {@code Proxy} instance using default values or not.
267      * Equivalent to {@code newBuilder( withDefaults ).build()}.
268      *
269      * @param withDefaults the boolean indicating whether default values should be used
270      * @return a new {@code Proxy}
271      */
272     @Nonnull
273     public static Proxy newInstance( boolean withDefaults )
274     {
275         return newBuilder( withDefaults ).build();
276     }
277 
278     /**
279      * Creates a new {@code Proxy} builder instance.
280      * Equivalent to {@code newBuilder( true )}.
281      * @see #newBuilder(boolean)
282      *
283      * @return a new {@code Builder}
284      */
285     @Nonnull
286     public static Builder newBuilder()
287     {
288         return newBuilder( true );
289     }
290 
291     /**
292      * Creates a new {@code Proxy} builder instance using default values or not.
293      *
294      * @param withDefaults the boolean indicating whether default values should be used
295      * @return a new {@code Builder}
296      */
297     @Nonnull
298     public static Builder newBuilder( boolean withDefaults )
299     {
300         return new Builder( withDefaults );
301     }
302 
303     /**
304      * Creates a new {@code Proxy} builder instance using the specified object as a basis.
305      * Equivalent to {@code newBuilder( from, false )}.
306      *
307      * @param from the {@code Proxy} instance to use as a basis
308      * @return a new {@code Builder}
309      */
310     @Nonnull
311     public static Builder newBuilder( Proxy from )
312     {
313         return newBuilder( from, false );
314     }
315 
316     /**
317      * Creates a new {@code Proxy} builder instance using the specified object as a basis.
318      *
319      * @param from the {@code Proxy} instance to use as a basis
320      * @param forceCopy the boolean indicating if a copy should be forced
321      * @return a new {@code Builder}
322      */
323     @Nonnull
324     public static Builder newBuilder( Proxy from, boolean forceCopy )
325     {
326         return new Builder( from, forceCopy );
327     }
328 
329     /**
330      * Builder class used to create Proxy instances.
331      * @see #with()
332      * @see #newBuilder()
333      */
334     @NotThreadSafe
335     public static class Builder
336         extends IdentifiableBase.Builder
337     {
338         Proxy base;
339         Boolean active;
340         String protocol;
341         String username;
342         String password;
343         Integer port;
344         String host;
345         String nonProxyHosts;
346 
347         Builder( boolean withDefaults )
348         {
349             super( withDefaults );
350             if ( withDefaults )
351             {
352                 this.active = true;
353                 this.protocol = "http";
354                 this.port = 8080;
355             }
356         }
357 
358         Builder( Proxy base, boolean forceCopy )
359         {
360             super( base, forceCopy );
361             if ( forceCopy )
362             {
363                 this.active = base.active;
364                 this.protocol = base.protocol;
365                 this.username = base.username;
366                 this.password = base.password;
367                 this.port = base.port;
368                 this.host = base.host;
369                 this.nonProxyHosts = base.nonProxyHosts;
370             }
371             else
372             {
373                 this.base = base;
374             }
375         }
376 
377         @Nonnull
378         public Builder id( String id )
379         {
380             this.id = id;
381             return this;
382         }
383 
384         @Nonnull
385         public Builder active( boolean active )
386         {
387             this.active = active;
388             return this;
389         }
390 
391         @Nonnull
392         public Builder protocol( String protocol )
393         {
394             this.protocol = protocol;
395             return this;
396         }
397 
398         @Nonnull
399         public Builder username( String username )
400         {
401             this.username = username;
402             return this;
403         }
404 
405         @Nonnull
406         public Builder password( String password )
407         {
408             this.password = password;
409             return this;
410         }
411 
412         @Nonnull
413         public Builder port( int port )
414         {
415             this.port = port;
416             return this;
417         }
418 
419         @Nonnull
420         public Builder host( String host )
421         {
422             this.host = host;
423             return this;
424         }
425 
426         @Nonnull
427         public Builder nonProxyHosts( String nonProxyHosts )
428         {
429             this.nonProxyHosts = nonProxyHosts;
430             return this;
431         }
432 
433 
434         @Nonnull
435         public Proxy build()
436         {
437             if ( base != null
438                     && ( id == null || id == base.id )
439                     && ( active == null || active == base.active )
440                     && ( protocol == null || protocol == base.protocol )
441                     && ( username == null || username == base.username )
442                     && ( password == null || password == base.password )
443                     && ( port == null || port == base.port )
444                     && ( host == null || host == base.host )
445                     && ( nonProxyHosts == null || nonProxyHosts == base.nonProxyHosts )
446             )
447             {
448                 return base;
449             }
450             return new Proxy(
451                 id != null ? id : ( base != null ? base.id : null ),
452                 active != null ? active : ( base != null ? base.active : true ),
453                 protocol != null ? protocol : ( base != null ? base.protocol : null ),
454                 username != null ? username : ( base != null ? base.username : null ),
455                 password != null ? password : ( base != null ? base.password : null ),
456                 port != null ? port : ( base != null ? base.port : 8080 ),
457                 host != null ? host : ( base != null ? base.host : null ),
458                 nonProxyHosts != null ? nonProxyHosts : ( base != null ? base.nonProxyHosts : null )
459             );
460         }
461     }
462 
463 }