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