View Javadoc
1   // =================== DO NOT EDIT THIS FILE ====================
2   //   Generated by Maven, any modifications will be overwritten.
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   * Root element of the user configuration file.
22   */
23  @Experimental
24  @Generated @ThreadSafe @Immutable
25  public class Settings
26      extends TrackableBase
27      implements Serializable
28  {
29      final String modelEncoding;
30      /**
31       * The local repository.<br><b>Default value is:</b> <code>${user.home}/.m2/repository</code>
32       */
33      final String localRepository;
34      /**
35       * Whether Maven should attempt to interact with the user for input.
36       */
37      final boolean interactiveMode;
38      /**
39       * Whether Maven should use the plugin-registry.xml file to manage plugin versions.
40       */
41      final boolean usePluginRegistry;
42      /**
43       * Indicate whether maven should operate in offline mode full-time.
44       */
45      final boolean offline;
46      /**
47       * Configuration for different proxy profiles. Multiple proxy profiles
48       * might come in handy for anyone working from a notebook or other
49       * mobile platform, to enable easy switching of entire proxy
50       * configurations by simply specifying the profile id, again either from
51       * the command line or from the defaults section below.
52       */
53      final List<Proxy> proxies;
54      /**
55       * Configuration of server-specific settings, mainly authentication
56       * method. This allows configuration of authentication on a per-server
57       * basis.
58       */
59      final List<Server> servers;
60      /**
61       * Configuration of download mirrors for repositories.
62       */
63      final List<Mirror> mirrors;
64      /**
65       * Configuration of build profiles for adjusting the build
66       * according to environmental parameters.
67       */
68      final List<Profile> profiles;
69      /**
70       * List of manually-activated build profiles, specified in the order in which
71       * they should be applied.
72       */
73      final List<String> activeProfiles;
74      /**
75       * List of groupIds to search for a plugin when that plugin
76       * groupId is not explicitly provided.
77       */
78      final List<String> pluginGroups;
79  
80      /**
81        * Constructor for this class, package protected.
82        * @see Builder#build()
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      * The local repository.<br><b>Default value is:</b> <code>${user.home}/.m2/repository</code>
120      *
121      * @return a {@code String}
122      */
123     public String getLocalRepository()
124     {
125         return this.localRepository;
126     }
127 
128     /**
129      * Whether Maven should attempt to interact with the user for input.
130      *
131      * @return a {@code boolean}
132      */
133     public boolean isInteractiveMode()
134     {
135         return this.interactiveMode;
136     }
137 
138     /**
139      * Whether Maven should use the plugin-registry.xml file to manage plugin versions.
140      *
141      * @return a {@code boolean}
142      */
143     public boolean isUsePluginRegistry()
144     {
145         return this.usePluginRegistry;
146     }
147 
148     /**
149      * Indicate whether maven should operate in offline mode full-time.
150      *
151      * @return a {@code boolean}
152      */
153     public boolean isOffline()
154     {
155         return this.offline;
156     }
157 
158     /**
159      * Configuration for different proxy profiles. Multiple proxy profiles
160      * might come in handy for anyone working from a notebook or other
161      * mobile platform, to enable easy switching of entire proxy
162      * configurations by simply specifying the profile id, again either from
163      * the command line or from the defaults section below.
164      *
165      * @return a {@code List<Proxy>}
166      */
167     @Nonnull
168     public List<Proxy> getProxies()
169     {
170         return this.proxies;
171     }
172 
173     /**
174      * Configuration of server-specific settings, mainly authentication
175      * method. This allows configuration of authentication on a per-server
176      * basis.
177      *
178      * @return a {@code List<Server>}
179      */
180     @Nonnull
181     public List<Server> getServers()
182     {
183         return this.servers;
184     }
185 
186     /**
187      * Configuration of download mirrors for repositories.
188      *
189      * @return a {@code List<Mirror>}
190      */
191     @Nonnull
192     public List<Mirror> getMirrors()
193     {
194         return this.mirrors;
195     }
196 
197     /**
198      * Configuration of build profiles for adjusting the build
199      * according to environmental parameters.
200      *
201      * @return a {@code List<Profile>}
202      */
203     @Nonnull
204     public List<Profile> getProfiles()
205     {
206         return this.profiles;
207     }
208 
209     /**
210      * List of manually-activated build profiles, specified in the order in which
211      * they should be applied.
212      *
213      * @return a {@code List<String>}
214      */
215     @Nonnull
216     public List<String> getActiveProfiles()
217     {
218         return this.activeProfiles;
219     }
220 
221     /**
222      * List of groupIds to search for a plugin when that plugin
223      * groupId is not explicitly provided.
224      *
225      * @return a {@code List<String>}
226      */
227     @Nonnull
228     public List<String> getPluginGroups()
229     {
230         return this.pluginGroups;
231     }
232 
233     /**
234      * Creates a new builder with this object as the basis.
235      *
236      * @return a {@code Builder}
237      */
238     @Nonnull
239     public Builder with()
240     {
241         return newBuilder( this );
242     }
243     /**
244      * Creates a new {@code Settings} instance using the specified localRepository.
245      *
246      * @param localRepository the new {@code String} to use
247      * @return a {@code Settings} with the specified localRepository
248      */
249     @Nonnull
250     public Settings withLocalRepository( String localRepository )
251     {
252         return with().localRepository( localRepository ).build();
253     }
254     /**
255      * Creates a new {@code Settings} instance using the specified interactiveMode.
256      *
257      * @param interactiveMode the new {@code boolean} to use
258      * @return a {@code Settings} with the specified interactiveMode
259      */
260     @Nonnull
261     public Settings withInteractiveMode( boolean interactiveMode )
262     {
263         return with().interactiveMode( interactiveMode ).build();
264     }
265     /**
266      * Creates a new {@code Settings} instance using the specified usePluginRegistry.
267      *
268      * @param usePluginRegistry the new {@code boolean} to use
269      * @return a {@code Settings} with the specified usePluginRegistry
270      */
271     @Nonnull
272     public Settings withUsePluginRegistry( boolean usePluginRegistry )
273     {
274         return with().usePluginRegistry( usePluginRegistry ).build();
275     }
276     /**
277      * Creates a new {@code Settings} instance using the specified offline.
278      *
279      * @param offline the new {@code boolean} to use
280      * @return a {@code Settings} with the specified offline
281      */
282     @Nonnull
283     public Settings withOffline( boolean offline )
284     {
285         return with().offline( offline ).build();
286     }
287     /**
288      * Creates a new {@code Settings} instance using the specified proxies.
289      *
290      * @param proxies the new {@code Collection<Proxy>} to use
291      * @return a {@code Settings} with the specified proxies
292      */
293     @Nonnull
294     public Settings withProxies( Collection<Proxy> proxies )
295     {
296         return with().proxies( proxies ).build();
297     }
298     /**
299      * Creates a new {@code Settings} instance using the specified servers.
300      *
301      * @param servers the new {@code Collection<Server>} to use
302      * @return a {@code Settings} with the specified servers
303      */
304     @Nonnull
305     public Settings withServers( Collection<Server> servers )
306     {
307         return with().servers( servers ).build();
308     }
309     /**
310      * Creates a new {@code Settings} instance using the specified mirrors.
311      *
312      * @param mirrors the new {@code Collection<Mirror>} to use
313      * @return a {@code Settings} with the specified mirrors
314      */
315     @Nonnull
316     public Settings withMirrors( Collection<Mirror> mirrors )
317     {
318         return with().mirrors( mirrors ).build();
319     }
320     /**
321      * Creates a new {@code Settings} instance using the specified profiles.
322      *
323      * @param profiles the new {@code Collection<Profile>} to use
324      * @return a {@code Settings} with the specified profiles
325      */
326     @Nonnull
327     public Settings withProfiles( Collection<Profile> profiles )
328     {
329         return with().profiles( profiles ).build();
330     }
331     /**
332      * Creates a new {@code Settings} instance using the specified activeProfiles.
333      *
334      * @param activeProfiles the new {@code Collection<String>} to use
335      * @return a {@code Settings} with the specified activeProfiles
336      */
337     @Nonnull
338     public Settings withActiveProfiles( Collection<String> activeProfiles )
339     {
340         return with().activeProfiles( activeProfiles ).build();
341     }
342     /**
343      * Creates a new {@code Settings} instance using the specified pluginGroups.
344      *
345      * @param pluginGroups the new {@code Collection<String>} to use
346      * @return a {@code Settings} with the specified pluginGroups
347      */
348     @Nonnull
349     public Settings withPluginGroups( Collection<String> pluginGroups )
350     {
351         return with().pluginGroups( pluginGroups ).build();
352     }
353 
354     /**
355      * Creates a new {@code Settings} instance.
356      * Equivalent to {@code newInstance( true )}.
357      * @see #newInstance(boolean)
358      *
359      * @return a new {@code Settings}
360      */
361     @Nonnull
362     public static Settings newInstance()
363     {
364         return newInstance( true );
365     }
366 
367     /**
368      * Creates a new {@code Settings} instance using default values or not.
369      * Equivalent to {@code newBuilder( withDefaults ).build()}.
370      *
371      * @param withDefaults the boolean indicating whether default values should be used
372      * @return a new {@code Settings}
373      */
374     @Nonnull
375     public static Settings newInstance( boolean withDefaults )
376     {
377         return newBuilder( withDefaults ).build();
378     }
379 
380     /**
381      * Creates a new {@code Settings} builder instance.
382      * Equivalent to {@code newBuilder( true )}.
383      * @see #newBuilder(boolean)
384      *
385      * @return a new {@code Builder}
386      */
387     @Nonnull
388     public static Builder newBuilder()
389     {
390         return newBuilder( true );
391     }
392 
393     /**
394      * Creates a new {@code Settings} builder instance using default values or not.
395      *
396      * @param withDefaults the boolean indicating whether default values should be used
397      * @return a new {@code Builder}
398      */
399     @Nonnull
400     public static Builder newBuilder( boolean withDefaults )
401     {
402         return new Builder( withDefaults );
403     }
404 
405     /**
406      * Creates a new {@code Settings} builder instance using the specified object as a basis.
407      * Equivalent to {@code newBuilder( from, false )}.
408      *
409      * @param from the {@code Settings} instance to use as a basis
410      * @return a new {@code Builder}
411      */
412     @Nonnull
413     public static Builder newBuilder( Settings from )
414     {
415         return newBuilder( from, false );
416     }
417 
418     /**
419      * Creates a new {@code Settings} builder instance using the specified object as a basis.
420      *
421      * @param from the {@code Settings} instance to use as a basis
422      * @param forceCopy the boolean indicating if a copy should be forced
423      * @return a new {@code Builder}
424      */
425     @Nonnull
426     public static Builder newBuilder( Settings from, boolean forceCopy )
427     {
428         return new Builder( from, forceCopy );
429     }
430 
431     /**
432      * Builder class used to create Settings instances.
433      * @see #with()
434      * @see #newBuilder()
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      * Reset the <code>activeProxy</code> field to <code>null</code>
609      */
610     public void flushActiveProxy()
611     {
612         this.activeProxy = null;
613     }
614 
615     /**
616      * @return the first active proxy
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      * Reset the <code>profileMap</code> field to <code>null</code>
684      */
685     public void flushProfileMap()
686     {
687         this.profileMap = null;
688     }
689 
690     /**
691      * @return a Map of profiles field with <code>Profile#getId()</code> as key
692      * @see Profile#getId()
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 }