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