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