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