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