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