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.Objects;
12  import java.util.Optional;
13  import java.util.Set;
14  import java.util.stream.Collectors;
15  import java.util.stream.Stream;
16  import org.apache.maven.api.annotations.Experimental;
17  import org.apache.maven.api.annotations.Generated;
18  import org.apache.maven.api.annotations.Immutable;
19  import org.apache.maven.api.annotations.Nonnull;
20  import org.apache.maven.api.annotations.NotThreadSafe;
21  import org.apache.maven.api.annotations.ThreadSafe;
22  import org.apache.maven.api.xml.XmlNode;
23  
24  /**
25   * The {@code <server>} element contains information required to a server settings.
26   */
27  @Experimental
28  @Generated @ThreadSafe @Immutable
29  public class Server
30      extends IdentifiableBase
31      implements Serializable, InputLocationTracker
32  {
33      /**
34       * The username used to authenticate.
35       */
36      final String username;
37      /**
38       * The password used in conjunction with the username to authenticate.
39       */
40      final String password;
41      /**
42       * The private key location used to authenticate.
43       */
44      final String privateKey;
45      /**
46       * The passphrase used in conjunction with the privateKey to authenticate.
47       */
48      final String passphrase;
49      /**
50       * The permissions for files when they are created.
51       */
52      final String filePermissions;
53      /**
54       * The permissions for directories when they are created.
55       */
56      final String directoryPermissions;
57      /**
58       * Extra configuration for the transport layer.
59       */
60      final XmlNode configuration;
61  
62      /**
63        * Constructor for this class, to be called from its subclasses and {@link Builder}.
64        * @see Builder#build()
65        */
66      protected Server(Builder builder) {
67          super(builder);
68          this.username = builder.username != null ? builder.username : (builder.base != null ? builder.base.username : null);
69          this.password = builder.password != null ? builder.password : (builder.base != null ? builder.base.password : null);
70          this.privateKey = builder.privateKey != null ? builder.privateKey : (builder.base != null ? builder.base.privateKey : null);
71          this.passphrase = builder.passphrase != null ? builder.passphrase : (builder.base != null ? builder.base.passphrase : null);
72          this.filePermissions = builder.filePermissions != null ? builder.filePermissions : (builder.base != null ? builder.base.filePermissions : null);
73          this.directoryPermissions = builder.directoryPermissions != null ? builder.directoryPermissions : (builder.base != null ? builder.base.directoryPermissions : null);
74          this.configuration = builder.configuration != null ? builder.configuration : (builder.base != null ? builder.base.configuration : null);
75      }
76  
77      /**
78       * The username used to authenticate.
79       *
80       * @return a {@code String}
81       */
82      public String getUsername() {
83          return this.username;
84      }
85  
86      /**
87       * The password used in conjunction with the username to authenticate.
88       *
89       * @return a {@code String}
90       */
91      public String getPassword() {
92          return this.password;
93      }
94  
95      /**
96       * The private key location used to authenticate.
97       *
98       * @return a {@code String}
99       */
100     public String getPrivateKey() {
101         return this.privateKey;
102     }
103 
104     /**
105      * The passphrase used in conjunction with the privateKey to authenticate.
106      *
107      * @return a {@code String}
108      */
109     public String getPassphrase() {
110         return this.passphrase;
111     }
112 
113     /**
114      * The permissions for files when they are created.
115      *
116      * @return a {@code String}
117      */
118     public String getFilePermissions() {
119         return this.filePermissions;
120     }
121 
122     /**
123      * The permissions for directories when they are created.
124      *
125      * @return a {@code String}
126      */
127     public String getDirectoryPermissions() {
128         return this.directoryPermissions;
129     }
130 
131     /**
132      * Extra configuration for the transport layer.
133      *
134      * @return a {@code XmlNode}
135      */
136     public XmlNode getConfiguration() {
137         return this.configuration;
138     }
139 
140     /**
141      * Creates a new builder with this object as the basis.
142      *
143      * @return a {@code Builder}
144      */
145     @Nonnull
146     public Builder with() {
147         return newBuilder(this);
148     }
149     /**
150      * Creates a new {@code Server} instance using the specified id.
151      *
152      * @param id the new {@code String} to use
153      * @return a {@code Server} with the specified id
154      */
155     @Nonnull
156     public Server withId(String id) {
157         return newBuilder(this, true).id(id).build();
158     }
159     /**
160      * Creates a new {@code Server} instance using the specified username.
161      *
162      * @param username the new {@code String} to use
163      * @return a {@code Server} with the specified username
164      */
165     @Nonnull
166     public Server withUsername(String username) {
167         return newBuilder(this, true).username(username).build();
168     }
169     /**
170      * Creates a new {@code Server} instance using the specified password.
171      *
172      * @param password the new {@code String} to use
173      * @return a {@code Server} with the specified password
174      */
175     @Nonnull
176     public Server withPassword(String password) {
177         return newBuilder(this, true).password(password).build();
178     }
179     /**
180      * Creates a new {@code Server} instance using the specified privateKey.
181      *
182      * @param privateKey the new {@code String} to use
183      * @return a {@code Server} with the specified privateKey
184      */
185     @Nonnull
186     public Server withPrivateKey(String privateKey) {
187         return newBuilder(this, true).privateKey(privateKey).build();
188     }
189     /**
190      * Creates a new {@code Server} instance using the specified passphrase.
191      *
192      * @param passphrase the new {@code String} to use
193      * @return a {@code Server} with the specified passphrase
194      */
195     @Nonnull
196     public Server withPassphrase(String passphrase) {
197         return newBuilder(this, true).passphrase(passphrase).build();
198     }
199     /**
200      * Creates a new {@code Server} instance using the specified filePermissions.
201      *
202      * @param filePermissions the new {@code String} to use
203      * @return a {@code Server} with the specified filePermissions
204      */
205     @Nonnull
206     public Server withFilePermissions(String filePermissions) {
207         return newBuilder(this, true).filePermissions(filePermissions).build();
208     }
209     /**
210      * Creates a new {@code Server} instance using the specified directoryPermissions.
211      *
212      * @param directoryPermissions the new {@code String} to use
213      * @return a {@code Server} with the specified directoryPermissions
214      */
215     @Nonnull
216     public Server withDirectoryPermissions(String directoryPermissions) {
217         return newBuilder(this, true).directoryPermissions(directoryPermissions).build();
218     }
219     /**
220      * Creates a new {@code Server} instance using the specified configuration.
221      *
222      * @param configuration the new {@code XmlNode} to use
223      * @return a {@code Server} with the specified configuration
224      */
225     @Nonnull
226     public Server withConfiguration(XmlNode configuration) {
227         return newBuilder(this, true).configuration(configuration).build();
228     }
229 
230     /**
231      * Creates a new {@code Server} instance.
232      * Equivalent to {@code newInstance(true)}.
233      * @see #newInstance(boolean)
234      *
235      * @return a new {@code Server}
236      */
237     @Nonnull
238     public static Server newInstance() {
239         return newInstance(true);
240     }
241 
242     /**
243      * Creates a new {@code Server} 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 Server}
248      */
249     @Nonnull
250     public static Server newInstance(boolean withDefaults) {
251         return newBuilder(withDefaults).build();
252     }
253 
254     /**
255      * Creates a new {@code Server} builder instance.
256      * Equivalent to {@code newBuilder(true)}.
257      * @see #newBuilder(boolean)
258      *
259      * @return a new {@code Builder}
260      */
261     @Nonnull
262     public static Builder newBuilder() {
263         return newBuilder(true);
264     }
265 
266     /**
267      * Creates a new {@code Server} builder instance using default values or not.
268      *
269      * @param withDefaults the boolean indicating whether default values should be used
270      * @return a new {@code Builder}
271      */
272     @Nonnull
273     public static Builder newBuilder(boolean withDefaults) {
274         return new Builder(withDefaults);
275     }
276 
277     /**
278      * Creates a new {@code Server} builder instance using the specified object as a basis.
279      * Equivalent to {@code newBuilder(from, false)}.
280      *
281      * @param from the {@code Server} instance to use as a basis
282      * @return a new {@code Builder}
283      */
284     @Nonnull
285     public static Builder newBuilder(Server from) {
286         return newBuilder(from, false);
287     }
288 
289     /**
290      * Creates a new {@code Server} builder instance using the specified object as a basis.
291      *
292      * @param from the {@code Server} instance to use as a basis
293      * @param forceCopy the boolean indicating if a copy should be forced
294      * @return a new {@code Builder}
295      */
296     @Nonnull
297     public static Builder newBuilder(Server from, boolean forceCopy) {
298         return new Builder(from, forceCopy);
299     }
300 
301     /**
302      * Builder class used to create Server instances.
303      * @see #with()
304      * @see #newBuilder()
305      */
306     @NotThreadSafe
307     public static class Builder
308         extends IdentifiableBase.Builder
309     {
310         Server base;
311         String username;
312         String password;
313         String privateKey;
314         String passphrase;
315         String filePermissions;
316         String directoryPermissions;
317         XmlNode configuration;
318 
319         protected Builder(boolean withDefaults) {
320             super(withDefaults);
321             if (withDefaults) {
322             }
323         }
324 
325         protected Builder(Server base, boolean forceCopy) {
326             super(base, forceCopy);
327             if (forceCopy) {
328                 this.username = base.username;
329                 this.password = base.password;
330                 this.privateKey = base.privateKey;
331                 this.passphrase = base.passphrase;
332                 this.filePermissions = base.filePermissions;
333                 this.directoryPermissions = base.directoryPermissions;
334                 this.configuration = base.configuration;
335                 this.locations = base.locations;
336                 this.importedFrom = base.importedFrom;
337             } else {
338                 this.base = base;
339             }
340         }
341 
342         @Nonnull
343         public Builder id(String id) {
344             this.id = id;
345             return this;
346         }
347 
348         @Nonnull
349         public Builder username(String username) {
350             this.username = username;
351             return this;
352         }
353 
354         @Nonnull
355         public Builder password(String password) {
356             this.password = password;
357             return this;
358         }
359 
360         @Nonnull
361         public Builder privateKey(String privateKey) {
362             this.privateKey = privateKey;
363             return this;
364         }
365 
366         @Nonnull
367         public Builder passphrase(String passphrase) {
368             this.passphrase = passphrase;
369             return this;
370         }
371 
372         @Nonnull
373         public Builder filePermissions(String filePermissions) {
374             this.filePermissions = filePermissions;
375             return this;
376         }
377 
378         @Nonnull
379         public Builder directoryPermissions(String directoryPermissions) {
380             this.directoryPermissions = directoryPermissions;
381             return this;
382         }
383 
384         @Nonnull
385         public Builder configuration(XmlNode configuration) {
386             this.configuration = configuration;
387             return this;
388         }
389 
390 
391         @Nonnull
392         public Builder location(Object key, InputLocation location) {
393             if (location != null) {
394                 if (!(this.locations instanceof HashMap)) {
395                     this.locations = this.locations != null ? new HashMap<>(this.locations) : new HashMap<>();
396                 }
397                 this.locations.put(key, location);
398             }
399             return this;
400         }
401 
402         @Nonnull
403         public Builder importedFrom(InputLocation importedFrom) {
404             this.importedFrom = importedFrom;
405             return this;
406         }
407 
408         @Nonnull
409         public Server build() {
410             // this method should not contain any logic other than creating (or reusing) an object in order to ease subclassing
411             if (base != null
412                     && (id == null || id == base.id)
413                     && (username == null || username == base.username)
414                     && (password == null || password == base.password)
415                     && (privateKey == null || privateKey == base.privateKey)
416                     && (passphrase == null || passphrase == base.passphrase)
417                     && (filePermissions == null || filePermissions == base.filePermissions)
418                     && (directoryPermissions == null || directoryPermissions == base.directoryPermissions)
419                     && (configuration == null || configuration == base.configuration)
420             ) {
421                 return base;
422             }
423             return new Server(this);
424         }
425 
426     }
427 
428 }