1
2
3
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
22
23 @Experimental
24 @Generated @ThreadSafe @Immutable
25 public class Server
26 extends IdentifiableBase
27 implements Serializable, InputLocationTracker
28 {
29
30
31
32 final String username;
33
34
35
36 final String password;
37
38
39
40 final String privateKey;
41
42
43
44 final String passphrase;
45
46
47
48 final String filePermissions;
49
50
51
52 final String directoryPermissions;
53
54
55
56 final XmlNode configuration;
57
58 final Map<Object, InputLocation> locations;
59
60
61
62
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
88
89
90
91 public String getUsername() {
92 return this.username;
93 }
94
95
96
97
98
99
100 public String getPassword() {
101 return this.password;
102 }
103
104
105
106
107
108
109 public String getPrivateKey() {
110 return this.privateKey;
111 }
112
113
114
115
116
117
118 public String getPassphrase() {
119 return this.passphrase;
120 }
121
122
123
124
125
126
127 public String getFilePermissions() {
128 return this.filePermissions;
129 }
130
131
132
133
134
135
136 public String getDirectoryPermissions() {
137 return this.directoryPermissions;
138 }
139
140
141
142
143
144
145 public XmlNode getConfiguration() {
146 return this.configuration;
147 }
148
149
150
151
152 public InputLocation getLocation(Object key) {
153 return locations != null ? locations.get(key) : null;
154 }
155
156
157
158
159 public Set<Object> getLocationKeys() {
160 return locations != null ? locations.keySet() : null;
161 }
162
163
164
165
166
167
168 @Nonnull
169 public Builder with() {
170 return newBuilder(this);
171 }
172
173
174
175
176
177
178 @Nonnull
179 public Server withId(String id) {
180 return newBuilder(this, true).id(id).build();
181 }
182
183
184
185
186
187
188 @Nonnull
189 public Server withUsername(String username) {
190 return newBuilder(this, true).username(username).build();
191 }
192
193
194
195
196
197
198 @Nonnull
199 public Server withPassword(String password) {
200 return newBuilder(this, true).password(password).build();
201 }
202
203
204
205
206
207
208 @Nonnull
209 public Server withPrivateKey(String privateKey) {
210 return newBuilder(this, true).privateKey(privateKey).build();
211 }
212
213
214
215
216
217
218 @Nonnull
219 public Server withPassphrase(String passphrase) {
220 return newBuilder(this, true).passphrase(passphrase).build();
221 }
222
223
224
225
226
227
228 @Nonnull
229 public Server withFilePermissions(String filePermissions) {
230 return newBuilder(this, true).filePermissions(filePermissions).build();
231 }
232
233
234
235
236
237
238 @Nonnull
239 public Server withDirectoryPermissions(String directoryPermissions) {
240 return newBuilder(this, true).directoryPermissions(directoryPermissions).build();
241 }
242
243
244
245
246
247
248 @Nonnull
249 public Server withConfiguration(XmlNode configuration) {
250 return newBuilder(this, true).configuration(configuration).build();
251 }
252
253
254
255
256
257
258
259
260 @Nonnull
261 public static Server newInstance() {
262 return newInstance(true);
263 }
264
265
266
267
268
269
270
271
272 @Nonnull
273 public static Server newInstance(boolean withDefaults) {
274 return newBuilder(withDefaults).build();
275 }
276
277
278
279
280
281
282
283
284 @Nonnull
285 public static Builder newBuilder() {
286 return newBuilder(true);
287 }
288
289
290
291
292
293
294
295 @Nonnull
296 public static Builder newBuilder(boolean withDefaults) {
297 return new Builder(withDefaults);
298 }
299
300
301
302
303
304
305
306
307 @Nonnull
308 public static Builder newBuilder(Server from) {
309 return newBuilder(from, false);
310 }
311
312
313
314
315
316
317
318
319 @Nonnull
320 public static Builder newBuilder(Server from, boolean forceCopy) {
321 return new Builder(from, forceCopy);
322 }
323
324
325
326
327
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
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 }