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 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
18
19
20
21 @Experimental
22 @Generated @ThreadSafe @Immutable
23 public class Proxy
24 extends IdentifiableBase
25 implements Serializable, InputLocationTracker
26 {
27
28
29
30
31
32 final String activeString;
33
34
35
36 final String protocol;
37
38
39
40 final String username;
41
42
43
44 final String password;
45
46
47
48
49
50 final String portString;
51
52
53
54 final String host;
55
56
57
58 final String nonProxyHosts;
59
60
61
62
63
64 Proxy(
65 String id,
66 String activeString,
67 String protocol,
68 String username,
69 String password,
70 String portString,
71 String host,
72 String nonProxyHosts,
73 Map<Object, InputLocation> locations
74 ) {
75 super(
76 id,
77 locations
78 );
79 this.activeString = activeString;
80 this.protocol = protocol;
81 this.username = username;
82 this.password = password;
83 this.portString = portString;
84 this.host = host;
85 this.nonProxyHosts = nonProxyHosts;
86 }
87
88
89
90
91
92
93
94
95 public String getActiveString() {
96 return this.activeString;
97 }
98
99
100
101
102
103
104 public String getProtocol() {
105 return this.protocol;
106 }
107
108
109
110
111
112
113 public String getUsername() {
114 return this.username;
115 }
116
117
118
119
120
121
122 public String getPassword() {
123 return this.password;
124 }
125
126
127
128
129
130
131
132
133 public String getPortString() {
134 return this.portString;
135 }
136
137
138
139
140
141
142 public String getHost() {
143 return this.host;
144 }
145
146
147
148
149
150
151 public String getNonProxyHosts() {
152 return this.nonProxyHosts;
153 }
154
155
156
157
158
159
160 @Nonnull
161 public Builder with() {
162 return newBuilder(this);
163 }
164
165
166
167
168
169
170 @Nonnull
171 public Proxy withId(String id) {
172 return newBuilder(this, true).id(id).build();
173 }
174
175
176
177
178
179
180 @Nonnull
181 public Proxy withActiveString(String activeString) {
182 return newBuilder(this, true).activeString(activeString).build();
183 }
184
185
186
187
188
189
190 @Nonnull
191 public Proxy withProtocol(String protocol) {
192 return newBuilder(this, true).protocol(protocol).build();
193 }
194
195
196
197
198
199
200 @Nonnull
201 public Proxy withUsername(String username) {
202 return newBuilder(this, true).username(username).build();
203 }
204
205
206
207
208
209
210 @Nonnull
211 public Proxy withPassword(String password) {
212 return newBuilder(this, true).password(password).build();
213 }
214
215
216
217
218
219
220 @Nonnull
221 public Proxy withPortString(String portString) {
222 return newBuilder(this, true).portString(portString).build();
223 }
224
225
226
227
228
229
230 @Nonnull
231 public Proxy withHost(String host) {
232 return newBuilder(this, true).host(host).build();
233 }
234
235
236
237
238
239
240 @Nonnull
241 public Proxy withNonProxyHosts(String nonProxyHosts) {
242 return newBuilder(this, true).nonProxyHosts(nonProxyHosts).build();
243 }
244
245
246
247
248
249
250
251
252 @Nonnull
253 public static Proxy newInstance() {
254 return newInstance(true);
255 }
256
257
258
259
260
261
262
263
264 @Nonnull
265 public static Proxy newInstance(boolean withDefaults) {
266 return newBuilder(withDefaults).build();
267 }
268
269
270
271
272
273
274
275
276 @Nonnull
277 public static Builder newBuilder() {
278 return newBuilder(true);
279 }
280
281
282
283
284
285
286
287 @Nonnull
288 public static Builder newBuilder(boolean withDefaults) {
289 return new Builder(withDefaults);
290 }
291
292
293
294
295
296
297
298
299 @Nonnull
300 public static Builder newBuilder(Proxy from) {
301 return newBuilder(from, false);
302 }
303
304
305
306
307
308
309
310
311 @Nonnull
312 public static Builder newBuilder(Proxy from, boolean forceCopy) {
313 return new Builder(from, forceCopy);
314 }
315
316
317
318
319
320
321 @NotThreadSafe
322 public static class Builder
323 extends IdentifiableBase.Builder
324 {
325 Proxy base;
326 String activeString;
327 String protocol;
328 String username;
329 String password;
330 String portString;
331 String host;
332 String nonProxyHosts;
333
334 Builder(boolean withDefaults) {
335 super(withDefaults);
336 if (withDefaults) {
337 this.activeString = "true";
338 this.protocol = "http";
339 this.portString = "8080";
340 }
341 }
342
343 Builder(Proxy base, boolean forceCopy) {
344 super(base, forceCopy);
345 if (forceCopy) {
346 this.activeString = base.activeString;
347 this.protocol = base.protocol;
348 this.username = base.username;
349 this.password = base.password;
350 this.portString = base.portString;
351 this.host = base.host;
352 this.nonProxyHosts = base.nonProxyHosts;
353 this.locations = base.locations;
354 } else {
355 this.base = base;
356 }
357 }
358
359 @Nonnull
360 public Builder id(String id) {
361 this.id = id;
362 return this;
363 }
364
365 @Nonnull
366 public Builder activeString(String activeString) {
367 this.activeString = activeString;
368 return this;
369 }
370
371 @Nonnull
372 public Builder protocol(String protocol) {
373 this.protocol = protocol;
374 return this;
375 }
376
377 @Nonnull
378 public Builder username(String username) {
379 this.username = username;
380 return this;
381 }
382
383 @Nonnull
384 public Builder password(String password) {
385 this.password = password;
386 return this;
387 }
388
389 @Nonnull
390 public Builder portString(String portString) {
391 this.portString = portString;
392 return this;
393 }
394
395 @Nonnull
396 public Builder host(String host) {
397 this.host = host;
398 return this;
399 }
400
401 @Nonnull
402 public Builder nonProxyHosts(String nonProxyHosts) {
403 this.nonProxyHosts = nonProxyHosts;
404 return this;
405 }
406
407
408 @Nonnull
409 public Builder location(Object key, InputLocation location) {
410 if (location != null) {
411 if (!(this.locations instanceof HashMap)) {
412 this.locations = this.locations != null ? new HashMap<>(this.locations) : new HashMap<>();
413 }
414 this.locations.put(key, location);
415 }
416 return this;
417 }
418
419 @Nonnull
420 public Proxy build() {
421 if (base != null
422 && (id == null || id == base.id)
423 && (activeString == null || activeString == base.activeString)
424 && (protocol == null || protocol == base.protocol)
425 && (username == null || username == base.username)
426 && (password == null || password == base.password)
427 && (portString == null || portString == base.portString)
428 && (host == null || host == base.host)
429 && (nonProxyHosts == null || nonProxyHosts == base.nonProxyHosts)
430 ) {
431 return base;
432 }
433 Map<Object, InputLocation> newlocs = this.locations != null ? this.locations : Collections.emptyMap();
434 Map<Object, InputLocation> oldlocs = this.base != null && this.base.locations != null ? this.base.locations : Collections.emptyMap();
435 Map<Object, InputLocation> locations = new HashMap<>();
436 locations.put("", newlocs.containsKey("") ? newlocs.get("") : oldlocs.get(""));
437 locations.put("id", newlocs.containsKey("id") ? newlocs.get("id") : oldlocs.get("id"));
438 locations.put("activeString", newlocs.containsKey("activeString") ? newlocs.get("activeString") : oldlocs.get("activeString"));
439 locations.put("protocol", newlocs.containsKey("protocol") ? newlocs.get("protocol") : oldlocs.get("protocol"));
440 locations.put("username", newlocs.containsKey("username") ? newlocs.get("username") : oldlocs.get("username"));
441 locations.put("password", newlocs.containsKey("password") ? newlocs.get("password") : oldlocs.get("password"));
442 locations.put("portString", newlocs.containsKey("portString") ? newlocs.get("portString") : oldlocs.get("portString"));
443 locations.put("host", newlocs.containsKey("host") ? newlocs.get("host") : oldlocs.get("host"));
444 locations.put("nonProxyHosts", newlocs.containsKey("nonProxyHosts") ? newlocs.get("nonProxyHosts") : oldlocs.get("nonProxyHosts"));
445 return new Proxy(
446 id != null ? id : (base != null ? base.id : null),
447 activeString != null ? activeString : (base != null ? base.activeString : null),
448 protocol != null ? protocol : (base != null ? base.protocol : null),
449 username != null ? username : (base != null ? base.username : null),
450 password != null ? password : (base != null ? base.password : null),
451 portString != null ? portString : (base != null ? base.portString : null),
452 host != null ? host : (base != null ? base.host : null),
453 nonProxyHosts != null ? nonProxyHosts : (base != null ? base.nonProxyHosts : null),
454 locations
455 );
456 }
457 }
458
459
460
461
462
463
464
465
466
467
468 public boolean isActive() {
469 return (getActiveString() != null) ? Boolean.parseBoolean(getActiveString()) : true;
470 }
471
472
473
474
475
476
477
478
479
480 public int getPort() {
481 return (getPortString() != null) ? Integer.parseInt(getPortString()) : 8080;
482 }
483
484
485 }