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