1
2
3
4
5 package org.apache.maven.api.settings;
6
7 import java.io.Serializable;
8 import java.util.ArrayList;
9 import java.util.Collection;
10 import java.util.Collections;
11 import java.util.HashMap;
12 import java.util.List;
13 import java.util.Map;
14 import java.util.Set;
15 import org.apache.maven.api.annotations.Experimental;
16 import org.apache.maven.api.annotations.Generated;
17 import org.apache.maven.api.annotations.Immutable;
18 import org.apache.maven.api.annotations.Nonnull;
19 import org.apache.maven.api.annotations.NotThreadSafe;
20 import org.apache.maven.api.annotations.ThreadSafe;
21
22
23
24
25 @Experimental
26 @Generated @ThreadSafe @Immutable
27 public class Settings
28 extends TrackableBase
29 implements Serializable, InputLocationTracker
30 {
31 final String namespaceUri;
32 final String modelEncoding;
33
34
35
36 final String localRepository;
37
38
39
40 final boolean interactiveMode;
41
42
43
44 final boolean usePluginRegistry;
45
46
47
48 final boolean offline;
49
50
51
52
53
54
55
56 final List<Proxy> proxies;
57
58
59
60
61
62 final List<Server> servers;
63
64
65
66 final List<Mirror> mirrors;
67
68
69
70 final List<Repository> repositories;
71
72
73
74 final List<Repository> pluginRepositories;
75
76
77
78
79 final List<Profile> profiles;
80
81
82
83
84 final List<String> activeProfiles;
85
86
87
88
89 final List<String> pluginGroups;
90
91 final Map<Object, InputLocation> locations;
92
93
94
95
96
97 protected Settings(Builder builder) {
98 super(builder);
99 this.namespaceUri = builder.namespaceUri != null ? builder.namespaceUri : (builder.base != null ? builder.base.namespaceUri : null);
100 this.modelEncoding = builder.modelEncoding != null ? builder.modelEncoding : (builder.base != null ? builder.base.modelEncoding : "UTF-8");
101 this.localRepository = builder.localRepository != null ? builder.localRepository : (builder.base != null ? builder.base.localRepository : null);
102 this.interactiveMode = builder.interactiveMode != null ? builder.interactiveMode : (builder.base != null ? builder.base.interactiveMode : true);
103 this.usePluginRegistry = builder.usePluginRegistry != null ? builder.usePluginRegistry : (builder.base != null ? builder.base.usePluginRegistry : false);
104 this.offline = builder.offline != null ? builder.offline : (builder.base != null ? builder.base.offline : false);
105 this.proxies = ImmutableCollections.copy(builder.proxies != null ? builder.proxies : (builder.base != null ? builder.base.proxies : null));
106 this.servers = ImmutableCollections.copy(builder.servers != null ? builder.servers : (builder.base != null ? builder.base.servers : null));
107 this.mirrors = ImmutableCollections.copy(builder.mirrors != null ? builder.mirrors : (builder.base != null ? builder.base.mirrors : null));
108 this.repositories = ImmutableCollections.copy(builder.repositories != null ? builder.repositories : (builder.base != null ? builder.base.repositories : null));
109 this.pluginRepositories = ImmutableCollections.copy(builder.pluginRepositories != null ? builder.pluginRepositories : (builder.base != null ? builder.base.pluginRepositories : null));
110 this.profiles = ImmutableCollections.copy(builder.profiles != null ? builder.profiles : (builder.base != null ? builder.base.profiles : null));
111 this.activeProfiles = ImmutableCollections.copy(builder.activeProfiles != null ? builder.activeProfiles : (builder.base != null ? builder.base.activeProfiles : null));
112 this.pluginGroups = ImmutableCollections.copy(builder.pluginGroups != null ? builder.pluginGroups : (builder.base != null ? builder.base.pluginGroups : null));
113 Map<Object, InputLocation> newlocs = builder.locations != null ? builder.locations : Collections.emptyMap();
114 Map<Object, InputLocation> oldlocs = builder.base != null && builder.base.locations != null ? builder.base.locations : Collections.emptyMap();
115 Map<Object, InputLocation> mutableLocations = new HashMap<>(super.locations);
116 mutableLocations.put("localRepository", newlocs.containsKey("localRepository") ? newlocs.get("localRepository") : oldlocs.get("localRepository"));
117 mutableLocations.put("interactiveMode", newlocs.containsKey("interactiveMode") ? newlocs.get("interactiveMode") : oldlocs.get("interactiveMode"));
118 mutableLocations.put("usePluginRegistry", newlocs.containsKey("usePluginRegistry") ? newlocs.get("usePluginRegistry") : oldlocs.get("usePluginRegistry"));
119 mutableLocations.put("offline", newlocs.containsKey("offline") ? newlocs.get("offline") : oldlocs.get("offline"));
120 mutableLocations.put("proxies", newlocs.containsKey("proxies") ? newlocs.get("proxies") : oldlocs.get("proxies"));
121 mutableLocations.put("servers", newlocs.containsKey("servers") ? newlocs.get("servers") : oldlocs.get("servers"));
122 mutableLocations.put("mirrors", newlocs.containsKey("mirrors") ? newlocs.get("mirrors") : oldlocs.get("mirrors"));
123 mutableLocations.put("repositories", newlocs.containsKey("repositories") ? newlocs.get("repositories") : oldlocs.get("repositories"));
124 mutableLocations.put("pluginRepositories", newlocs.containsKey("pluginRepositories") ? newlocs.get("pluginRepositories") : oldlocs.get("pluginRepositories"));
125 mutableLocations.put("profiles", newlocs.containsKey("profiles") ? newlocs.get("profiles") : oldlocs.get("profiles"));
126 mutableLocations.put("activeProfiles", newlocs.containsKey("activeProfiles") ? newlocs.get("activeProfiles") : oldlocs.get("activeProfiles"));
127 mutableLocations.put("pluginGroups", newlocs.containsKey("pluginGroups") ? newlocs.get("pluginGroups") : oldlocs.get("pluginGroups"));
128 this.locations = Collections.unmodifiableMap(mutableLocations);
129 }
130
131 public String getNamespaceUri() {
132 return namespaceUri;
133 }
134
135 public String getModelEncoding() {
136 return modelEncoding;
137 }
138
139
140
141
142
143
144 public String getLocalRepository() {
145 return this.localRepository;
146 }
147
148
149
150
151
152
153 public boolean isInteractiveMode() {
154 return this.interactiveMode;
155 }
156
157
158
159
160
161
162 public boolean isUsePluginRegistry() {
163 return this.usePluginRegistry;
164 }
165
166
167
168
169
170
171 public boolean isOffline() {
172 return this.offline;
173 }
174
175
176
177
178
179
180
181
182
183
184 @Nonnull
185 public List<Proxy> getProxies() {
186 return this.proxies;
187 }
188
189
190
191
192
193
194
195
196 @Nonnull
197 public List<Server> getServers() {
198 return this.servers;
199 }
200
201
202
203
204
205
206 @Nonnull
207 public List<Mirror> getMirrors() {
208 return this.mirrors;
209 }
210
211
212
213
214
215
216 @Nonnull
217 public List<Repository> getRepositories() {
218 return this.repositories;
219 }
220
221
222
223
224
225
226 @Nonnull
227 public List<Repository> getPluginRepositories() {
228 return this.pluginRepositories;
229 }
230
231
232
233
234
235
236
237 @Nonnull
238 public List<Profile> getProfiles() {
239 return this.profiles;
240 }
241
242
243
244
245
246
247
248 @Nonnull
249 public List<String> getActiveProfiles() {
250 return this.activeProfiles;
251 }
252
253
254
255
256
257
258
259 @Nonnull
260 public List<String> getPluginGroups() {
261 return this.pluginGroups;
262 }
263
264
265
266
267 public InputLocation getLocation(Object key) {
268 return locations != null ? locations.get(key) : null;
269 }
270
271
272
273
274 public Set<Object> getLocationKeys() {
275 return locations != null ? locations.keySet() : null;
276 }
277
278
279
280
281
282
283 @Nonnull
284 public Builder with() {
285 return newBuilder(this);
286 }
287
288
289
290
291
292
293 @Nonnull
294 public Settings withLocalRepository(String localRepository) {
295 return newBuilder(this, true).localRepository(localRepository).build();
296 }
297
298
299
300
301
302
303 @Nonnull
304 public Settings withInteractiveMode(boolean interactiveMode) {
305 return newBuilder(this, true).interactiveMode(interactiveMode).build();
306 }
307
308
309
310
311
312
313 @Nonnull
314 public Settings withUsePluginRegistry(boolean usePluginRegistry) {
315 return newBuilder(this, true).usePluginRegistry(usePluginRegistry).build();
316 }
317
318
319
320
321
322
323 @Nonnull
324 public Settings withOffline(boolean offline) {
325 return newBuilder(this, true).offline(offline).build();
326 }
327
328
329
330
331
332
333 @Nonnull
334 public Settings withProxies(Collection<Proxy> proxies) {
335 return newBuilder(this, true).proxies(proxies).build();
336 }
337
338
339
340
341
342
343 @Nonnull
344 public Settings withServers(Collection<Server> servers) {
345 return newBuilder(this, true).servers(servers).build();
346 }
347
348
349
350
351
352
353 @Nonnull
354 public Settings withMirrors(Collection<Mirror> mirrors) {
355 return newBuilder(this, true).mirrors(mirrors).build();
356 }
357
358
359
360
361
362
363 @Nonnull
364 public Settings withRepositories(Collection<Repository> repositories) {
365 return newBuilder(this, true).repositories(repositories).build();
366 }
367
368
369
370
371
372
373 @Nonnull
374 public Settings withPluginRepositories(Collection<Repository> pluginRepositories) {
375 return newBuilder(this, true).pluginRepositories(pluginRepositories).build();
376 }
377
378
379
380
381
382
383 @Nonnull
384 public Settings withProfiles(Collection<Profile> profiles) {
385 return newBuilder(this, true).profiles(profiles).build();
386 }
387
388
389
390
391
392
393 @Nonnull
394 public Settings withActiveProfiles(Collection<String> activeProfiles) {
395 return newBuilder(this, true).activeProfiles(activeProfiles).build();
396 }
397
398
399
400
401
402
403 @Nonnull
404 public Settings withPluginGroups(Collection<String> pluginGroups) {
405 return newBuilder(this, true).pluginGroups(pluginGroups).build();
406 }
407
408
409
410
411
412
413
414
415 @Nonnull
416 public static Settings newInstance() {
417 return newInstance(true);
418 }
419
420
421
422
423
424
425
426
427 @Nonnull
428 public static Settings newInstance(boolean withDefaults) {
429 return newBuilder(withDefaults).build();
430 }
431
432
433
434
435
436
437
438
439 @Nonnull
440 public static Builder newBuilder() {
441 return newBuilder(true);
442 }
443
444
445
446
447
448
449
450 @Nonnull
451 public static Builder newBuilder(boolean withDefaults) {
452 return new Builder(withDefaults);
453 }
454
455
456
457
458
459
460
461
462 @Nonnull
463 public static Builder newBuilder(Settings from) {
464 return newBuilder(from, false);
465 }
466
467
468
469
470
471
472
473
474 @Nonnull
475 public static Builder newBuilder(Settings from, boolean forceCopy) {
476 return new Builder(from, forceCopy);
477 }
478
479
480
481
482
483
484 @NotThreadSafe
485 public static class Builder
486 extends TrackableBase.Builder
487 {
488 Settings base;
489 String namespaceUri;
490 String modelEncoding;
491 String localRepository;
492 Boolean interactiveMode;
493 Boolean usePluginRegistry;
494 Boolean offline;
495 Collection<Proxy> proxies;
496 Collection<Server> servers;
497 Collection<Mirror> mirrors;
498 Collection<Repository> repositories;
499 Collection<Repository> pluginRepositories;
500 Collection<Profile> profiles;
501 Collection<String> activeProfiles;
502 Collection<String> pluginGroups;
503
504 protected Builder(boolean withDefaults) {
505 super(withDefaults);
506 if (withDefaults) {
507 this.interactiveMode = true;
508 this.usePluginRegistry = false;
509 this.offline = false;
510 }
511 }
512
513 protected Builder(Settings base, boolean forceCopy) {
514 super(base, forceCopy);
515 this.namespaceUri = base.namespaceUri;
516 this.modelEncoding = base.modelEncoding;
517 if (forceCopy) {
518 this.localRepository = base.localRepository;
519 this.interactiveMode = base.interactiveMode;
520 this.usePluginRegistry = base.usePluginRegistry;
521 this.offline = base.offline;
522 this.proxies = base.proxies;
523 this.servers = base.servers;
524 this.mirrors = base.mirrors;
525 this.repositories = base.repositories;
526 this.pluginRepositories = base.pluginRepositories;
527 this.profiles = base.profiles;
528 this.activeProfiles = base.activeProfiles;
529 this.pluginGroups = base.pluginGroups;
530 this.locations = base.locations;
531 this.importedFrom = base.importedFrom;
532 } else {
533 this.base = base;
534 }
535 }
536
537 @Nonnull
538 public Builder namespaceUri(String namespaceUri) {
539 this.namespaceUri = namespaceUri;
540 return this;
541 }
542
543 @Nonnull
544 public Builder modelEncoding(String modelEncoding) {
545 this.modelEncoding = modelEncoding;
546 return this;
547 }
548
549 @Nonnull
550 public Builder localRepository(String localRepository) {
551 this.localRepository = localRepository;
552 return this;
553 }
554
555 @Nonnull
556 public Builder interactiveMode(boolean interactiveMode) {
557 this.interactiveMode = interactiveMode;
558 return this;
559 }
560
561 @Nonnull
562 public Builder usePluginRegistry(boolean usePluginRegistry) {
563 this.usePluginRegistry = usePluginRegistry;
564 return this;
565 }
566
567 @Nonnull
568 public Builder offline(boolean offline) {
569 this.offline = offline;
570 return this;
571 }
572
573 @Nonnull
574 public Builder proxies(Collection<Proxy> proxies) {
575 this.proxies = proxies;
576 return this;
577 }
578
579 @Nonnull
580 public Builder servers(Collection<Server> servers) {
581 this.servers = servers;
582 return this;
583 }
584
585 @Nonnull
586 public Builder mirrors(Collection<Mirror> mirrors) {
587 this.mirrors = mirrors;
588 return this;
589 }
590
591 @Nonnull
592 public Builder repositories(Collection<Repository> repositories) {
593 this.repositories = repositories;
594 return this;
595 }
596
597 @Nonnull
598 public Builder pluginRepositories(Collection<Repository> pluginRepositories) {
599 this.pluginRepositories = pluginRepositories;
600 return this;
601 }
602
603 @Nonnull
604 public Builder profiles(Collection<Profile> profiles) {
605 this.profiles = profiles;
606 return this;
607 }
608
609 @Nonnull
610 public Builder activeProfiles(Collection<String> activeProfiles) {
611 this.activeProfiles = activeProfiles;
612 return this;
613 }
614
615 @Nonnull
616 public Builder pluginGroups(Collection<String> pluginGroups) {
617 this.pluginGroups = pluginGroups;
618 return this;
619 }
620
621
622 @Nonnull
623 public Builder location(Object key, InputLocation location) {
624 if (location != null) {
625 if (!(this.locations instanceof HashMap)) {
626 this.locations = this.locations != null ? new HashMap<>(this.locations) : new HashMap<>();
627 }
628 this.locations.put(key, location);
629 }
630 return this;
631 }
632
633 @Nonnull
634 public Builder importedFrom(InputLocation importedFrom) {
635 this.importedFrom = importedFrom;
636 return this;
637 }
638
639 @Nonnull
640 public Settings build() {
641
642 if (base != null
643 && (localRepository == null || localRepository == base.localRepository)
644 && (interactiveMode == null || interactiveMode == base.interactiveMode)
645 && (usePluginRegistry == null || usePluginRegistry == base.usePluginRegistry)
646 && (offline == null || offline == base.offline)
647 && (proxies == null || proxies == base.proxies)
648 && (servers == null || servers == base.servers)
649 && (mirrors == null || mirrors == base.mirrors)
650 && (repositories == null || repositories == base.repositories)
651 && (pluginRepositories == null || pluginRepositories == base.pluginRepositories)
652 && (profiles == null || profiles == base.profiles)
653 && (activeProfiles == null || activeProfiles == base.activeProfiles)
654 && (pluginGroups == null || pluginGroups == base.pluginGroups)
655 ) {
656 return base;
657 }
658 return new Settings(this);
659 }
660 }
661
662 }