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