View Javadoc

1   /*
2    * $Id$
3    */
4   
5   package org.apache.maven.settings;
6   
7     //---------------------------------/
8    //- Imported classes and packages -/
9   //---------------------------------/
10  
11  import java.util.Date;
12  
13  /**
14   * 
15   *         Root element of the user configuration file.
16   *       
17   * 
18   * @version $Revision$ $Date$
19   */
20  public class Settings extends TrackableBase 
21  implements java.io.Serializable
22  {
23  
24  
25        //--------------------------/
26       //- Class/Member Variables -/
27      //--------------------------/
28  
29      /**
30       * 
31       *             
32       *             The local repository.
33       *             
34       *           
35       */
36      private String localRepository;
37  
38      /**
39       * 
40       *             
41       *             Whether Maven should attempt to interact with
42       * the user for input.
43       *             
44       *           
45       */
46      private boolean interactiveMode = true;
47  
48      /**
49       * 
50       *             
51       *             Whether Maven should use the plugin-registry.xml
52       * file to manage plugin versions.
53       *             
54       *           
55       */
56      private boolean usePluginRegistry = false;
57  
58      /**
59       * 
60       *             
61       *             Indicate whether maven should operate in offline
62       * mode full-time.
63       *             
64       *           
65       */
66      private boolean offline = false;
67  
68      /**
69       * Field proxies.
70       */
71      private java.util.List proxies;
72  
73      /**
74       * Field servers.
75       */
76      private java.util.List servers;
77  
78      /**
79       * Field mirrors.
80       */
81      private java.util.List mirrors;
82  
83      /**
84       * Field profiles.
85       */
86      private java.util.List profiles;
87  
88      /**
89       * Field activeProfiles.
90       */
91      private java.util.List activeProfiles;
92  
93      /**
94       * Field pluginGroups.
95       */
96      private java.util.List pluginGroups;
97  
98  
99        //-----------/
100      //- Methods -/
101     //-----------/
102 
103     /**
104      * Method addActiveProfile.
105      * 
106      * @param string
107      */
108     public void addActiveProfile( String string )
109     {
110         if ( !(string instanceof String) )
111         {
112             throw new ClassCastException( "Settings.addActiveProfiles(string) parameter must be instanceof " + String.class.getName() );
113         }
114         getActiveProfiles().add( string );
115     } //-- void addActiveProfile( String ) 
116 
117     /**
118      * Method addMirror.
119      * 
120      * @param mirror
121      */
122     public void addMirror( Mirror mirror )
123     {
124         if ( !(mirror instanceof Mirror) )
125         {
126             throw new ClassCastException( "Settings.addMirrors(mirror) parameter must be instanceof " + Mirror.class.getName() );
127         }
128         getMirrors().add( mirror );
129     } //-- void addMirror( Mirror ) 
130 
131     /**
132      * Method addPluginGroup.
133      * 
134      * @param string
135      */
136     public void addPluginGroup( String string )
137     {
138         if ( !(string instanceof String) )
139         {
140             throw new ClassCastException( "Settings.addPluginGroups(string) parameter must be instanceof " + String.class.getName() );
141         }
142         getPluginGroups().add( string );
143     } //-- void addPluginGroup( String ) 
144 
145     /**
146      * Method addProfile.
147      * 
148      * @param profile
149      */
150     public void addProfile( Profile profile )
151     {
152         if ( !(profile instanceof Profile) )
153         {
154             throw new ClassCastException( "Settings.addProfiles(profile) parameter must be instanceof " + Profile.class.getName() );
155         }
156         getProfiles().add( profile );
157     } //-- void addProfile( Profile ) 
158 
159     /**
160      * Method addProxy.
161      * 
162      * @param proxy
163      */
164     public void addProxy( Proxy proxy )
165     {
166         if ( !(proxy instanceof Proxy) )
167         {
168             throw new ClassCastException( "Settings.addProxies(proxy) parameter must be instanceof " + Proxy.class.getName() );
169         }
170         getProxies().add( proxy );
171     } //-- void addProxy( Proxy ) 
172 
173     /**
174      * Method addServer.
175      * 
176      * @param server
177      */
178     public void addServer( Server server )
179     {
180         if ( !(server instanceof Server) )
181         {
182             throw new ClassCastException( "Settings.addServers(server) parameter must be instanceof " + Server.class.getName() );
183         }
184         getServers().add( server );
185     } //-- void addServer( Server ) 
186 
187     /**
188      * Method getActiveProfiles.
189      * 
190      * @return java.util.List
191      */
192     public java.util.List getActiveProfiles()
193     {
194         if ( this.activeProfiles == null )
195         {
196             this.activeProfiles = new java.util.ArrayList();
197         }
198     
199         return this.activeProfiles;
200     } //-- java.util.List getActiveProfiles() 
201 
202     /**
203      * Get 
204      *             
205      *             The local repository.
206      *             
207      *           
208      * 
209      * @return String
210      */
211     public String getLocalRepository()
212     {
213         return this.localRepository;
214     } //-- String getLocalRepository() 
215 
216     /**
217      * Method getMirrors.
218      * 
219      * @return java.util.List
220      */
221     public java.util.List getMirrors()
222     {
223         if ( this.mirrors == null )
224         {
225             this.mirrors = new java.util.ArrayList();
226         }
227     
228         return this.mirrors;
229     } //-- java.util.List getMirrors() 
230 
231     /**
232      * Method getPluginGroups.
233      * 
234      * @return java.util.List
235      */
236     public java.util.List getPluginGroups()
237     {
238         if ( this.pluginGroups == null )
239         {
240             this.pluginGroups = new java.util.ArrayList();
241         }
242     
243         return this.pluginGroups;
244     } //-- java.util.List getPluginGroups() 
245 
246     /**
247      * Method getProfiles.
248      * 
249      * @return java.util.List
250      */
251     public java.util.List getProfiles()
252     {
253         if ( this.profiles == null )
254         {
255             this.profiles = new java.util.ArrayList();
256         }
257     
258         return this.profiles;
259     } //-- java.util.List getProfiles() 
260 
261     /**
262      * Method getProxies.
263      * 
264      * @return java.util.List
265      */
266     public java.util.List getProxies()
267     {
268         if ( this.proxies == null )
269         {
270             this.proxies = new java.util.ArrayList();
271         }
272     
273         return this.proxies;
274     } //-- java.util.List getProxies() 
275 
276     /**
277      * Method getServers.
278      * 
279      * @return java.util.List
280      */
281     public java.util.List getServers()
282     {
283         if ( this.servers == null )
284         {
285             this.servers = new java.util.ArrayList();
286         }
287     
288         return this.servers;
289     } //-- java.util.List getServers() 
290 
291     /**
292      * Get 
293      *             
294      *             Whether Maven should attempt to interact with
295      * the user for input.
296      *             
297      *           
298      * 
299      * @return boolean
300      */
301     public boolean isInteractiveMode()
302     {
303         return this.interactiveMode;
304     } //-- boolean isInteractiveMode() 
305 
306     /**
307      * Get 
308      *             
309      *             Indicate whether maven should operate in offline
310      * mode full-time.
311      *             
312      *           
313      * 
314      * @return boolean
315      */
316     public boolean isOffline()
317     {
318         return this.offline;
319     } //-- boolean isOffline() 
320 
321     /**
322      * Get 
323      *             
324      *             Whether Maven should use the plugin-registry.xml
325      * file to manage plugin versions.
326      *             
327      *           
328      * 
329      * @return boolean
330      */
331     public boolean isUsePluginRegistry()
332     {
333         return this.usePluginRegistry;
334     } //-- boolean isUsePluginRegistry() 
335 
336     /**
337      * Method removeActiveProfile.
338      * 
339      * @param string
340      */
341     public void removeActiveProfile( String string )
342     {
343         if ( !(string instanceof String) )
344         {
345             throw new ClassCastException( "Settings.removeActiveProfiles(string) parameter must be instanceof " + String.class.getName() );
346         }
347         getActiveProfiles().remove( string );
348     } //-- void removeActiveProfile( String ) 
349 
350     /**
351      * Method removeMirror.
352      * 
353      * @param mirror
354      */
355     public void removeMirror( Mirror mirror )
356     {
357         if ( !(mirror instanceof Mirror) )
358         {
359             throw new ClassCastException( "Settings.removeMirrors(mirror) parameter must be instanceof " + Mirror.class.getName() );
360         }
361         getMirrors().remove( mirror );
362     } //-- void removeMirror( Mirror ) 
363 
364     /**
365      * Method removePluginGroup.
366      * 
367      * @param string
368      */
369     public void removePluginGroup( String string )
370     {
371         if ( !(string instanceof String) )
372         {
373             throw new ClassCastException( "Settings.removePluginGroups(string) parameter must be instanceof " + String.class.getName() );
374         }
375         getPluginGroups().remove( string );
376     } //-- void removePluginGroup( String ) 
377 
378     /**
379      * Method removeProfile.
380      * 
381      * @param profile
382      */
383     public void removeProfile( Profile profile )
384     {
385         if ( !(profile instanceof Profile) )
386         {
387             throw new ClassCastException( "Settings.removeProfiles(profile) parameter must be instanceof " + Profile.class.getName() );
388         }
389         getProfiles().remove( profile );
390     } //-- void removeProfile( Profile ) 
391 
392     /**
393      * Method removeProxy.
394      * 
395      * @param proxy
396      */
397     public void removeProxy( Proxy proxy )
398     {
399         if ( !(proxy instanceof Proxy) )
400         {
401             throw new ClassCastException( "Settings.removeProxies(proxy) parameter must be instanceof " + Proxy.class.getName() );
402         }
403         getProxies().remove( proxy );
404     } //-- void removeProxy( Proxy ) 
405 
406     /**
407      * Method removeServer.
408      * 
409      * @param server
410      */
411     public void removeServer( Server server )
412     {
413         if ( !(server instanceof Server) )
414         {
415             throw new ClassCastException( "Settings.removeServers(server) parameter must be instanceof " + Server.class.getName() );
416         }
417         getServers().remove( server );
418     } //-- void removeServer( Server ) 
419 
420     /**
421      * Set 
422      *             
423      *             List of manually-activated build profiles,
424      * specified in the order in which
425      *             they should be applied.
426      *             
427      *           
428      * 
429      * @param activeProfiles
430      */
431     public void setActiveProfiles( java.util.List activeProfiles )
432     {
433         this.activeProfiles = activeProfiles;
434     } //-- void setActiveProfiles( java.util.List ) 
435 
436     /**
437      * Set 
438      *             
439      *             Whether Maven should attempt to interact with
440      * the user for input.
441      *             
442      *           
443      * 
444      * @param interactiveMode
445      */
446     public void setInteractiveMode( boolean interactiveMode )
447     {
448         this.interactiveMode = interactiveMode;
449     } //-- void setInteractiveMode( boolean ) 
450 
451     /**
452      * Set 
453      *             
454      *             The local repository.
455      *             
456      *           
457      * 
458      * @param localRepository
459      */
460     public void setLocalRepository( String localRepository )
461     {
462         this.localRepository = localRepository;
463     } //-- void setLocalRepository( String ) 
464 
465     /**
466      * Set 
467      *             Configuration of download mirrors for
468      * repositories.
469      *           
470      * 
471      * @param mirrors
472      */
473     public void setMirrors( java.util.List mirrors )
474     {
475         this.mirrors = mirrors;
476     } //-- void setMirrors( java.util.List ) 
477 
478     /**
479      * Set 
480      *             
481      *             Indicate whether maven should operate in offline
482      * mode full-time.
483      *             
484      *           
485      * 
486      * @param offline
487      */
488     public void setOffline( boolean offline )
489     {
490         this.offline = offline;
491     } //-- void setOffline( boolean ) 
492 
493     /**
494      * Set 
495      *             List of groupIds to search for a plugin when
496      * that plugin
497      *             groupId is not explicitly provided.
498      *           
499      * 
500      * @param pluginGroups
501      */
502     public void setPluginGroups( java.util.List pluginGroups )
503     {
504         this.pluginGroups = pluginGroups;
505     } //-- void setPluginGroups( java.util.List ) 
506 
507     /**
508      * Set 
509      *             
510      *             Configuration of build profiles for adjusting
511      * the build
512      *             according to environmental parameters.
513      *             
514      *           
515      * 
516      * @param profiles
517      */
518     public void setProfiles( java.util.List profiles )
519     {
520         this.profiles = profiles;
521     } //-- void setProfiles( java.util.List ) 
522 
523     /**
524      * Set 
525      *             
526      *             Configuration for different proxy profiles.
527      * Multiple proxy profiles
528      *             might come in handy for anyone working from a
529      * notebook or other
530      *             mobile platform, to enable easy switching of
531      * entire proxy
532      *             configurations by simply specifying the profile
533      * id, again either from
534      *             the command line or from the defaults section
535      * below.
536      *             
537      *           
538      * 
539      * @param proxies
540      */
541     public void setProxies( java.util.List proxies )
542     {
543         this.proxies = proxies;
544     } //-- void setProxies( java.util.List ) 
545 
546     /**
547      * Set 
548      *             
549      *             Configuration of server-specific settings,
550      * mainly authentication
551      *             method. This allows configuration of
552      * authentication on a per-server
553      *             basis.
554      *             
555      *           
556      * 
557      * @param servers
558      */
559     public void setServers( java.util.List servers )
560     {
561         this.servers = servers;
562     } //-- void setServers( java.util.List ) 
563 
564     /**
565      * Set 
566      *             
567      *             Whether Maven should use the plugin-registry.xml
568      * file to manage plugin versions.
569      *             
570      *           
571      * 
572      * @param usePluginRegistry
573      */
574     public void setUsePluginRegistry( boolean usePluginRegistry )
575     {
576         this.usePluginRegistry = usePluginRegistry;
577     } //-- void setUsePluginRegistry( boolean ) 
578 
579 
580             
581     public Boolean getInteractiveMode()
582     {
583         return Boolean.valueOf( isInteractiveMode() );
584     }
585 
586     private Proxy activeProxy;
587 
588     /**
589      * Reset the <code>activeProxy</code> field to <code>null</code>
590      */
591     public void flushActiveProxy()
592     {
593         this.activeProxy = null;
594     }
595 
596     /**
597      * @return the first active proxy
598      */
599     public synchronized Proxy getActiveProxy()
600     {
601         if(activeProxy == null)
602         {
603             java.util.List proxies = getProxies();
604             if ( proxies != null && !proxies.isEmpty() )
605             {
606                 for ( java.util.Iterator it = proxies.iterator(); it.hasNext(); )
607                 {
608                     Proxy proxy = (Proxy) it.next();
609                     if ( proxy.isActive() )
610                     {
611                         activeProxy = proxy;
612                         break;
613                     }
614                 }
615             }
616         }
617 
618         return activeProxy;
619     }
620 
621     public Server getServer( String serverId )
622     {
623         Server match = null;
624 
625         java.util.List servers = getServers();
626         if ( servers != null && serverId != null )
627         {
628             for ( java.util.Iterator it = servers.iterator(); it.hasNext(); )
629             {
630                 Server server = (Server) it.next();
631                 if ( serverId.equals( server.getId() ) )
632                 {
633                     match = server;
634                     break;
635                 }
636             }
637         }
638 
639         return match;
640     }
641 
642     public Mirror getMirrorOf( String repositoryId )
643     {
644         Mirror match = null;
645 
646         java.util.List mirrors = getMirrors();
647         if ( mirrors != null && repositoryId != null )
648         {
649             for ( java.util.Iterator it = mirrors.iterator(); it.hasNext(); )
650             {
651                 Mirror mirror = (Mirror) it.next();
652                 if ( repositoryId.equals( mirror.getMirrorOf() ) )
653                 {
654                     match = mirror;
655                     break;
656                 }
657             }
658         }
659 
660         return match;
661     }
662 
663     private java.util.Map profileMap;
664 
665     /**
666      * Reset the <code>profileMap</code> field to <code>null</code>
667      */
668     public void flushProfileMap()
669     {
670         this.profileMap = null;
671     }
672 
673     /**
674      * @return a Map of profiles field with <code>Profile#getId()</code> as key
675      * @see org.apache.maven.settings.Profile#getId()
676      */
677     public java.util.Map getProfilesAsMap()
678     {
679         if ( profileMap == null )
680         {
681             profileMap = new java.util.LinkedHashMap();
682 
683             if ( getProfiles() != null )
684             {
685                 for ( java.util.Iterator it = getProfiles().iterator(); it.hasNext(); )
686                 {
687                     Profile profile = (Profile) it.next();
688 
689                     profileMap.put( profile.getId(), profile );
690                 }
691             }
692         }
693 
694         return profileMap;
695     }
696 
697     private RuntimeInfo runtimeInfo;
698 
699     public void setRuntimeInfo( RuntimeInfo runtimeInfo )
700     {
701         this.runtimeInfo = runtimeInfo;
702     }
703 
704     public RuntimeInfo getRuntimeInfo()
705     {
706         return runtimeInfo;
707     }
708             
709           
710     private String modelEncoding = "UTF-8";
711 
712     /**
713      * Set an encoding used for reading/writing the model.
714      *
715      * @param modelEncoding the encoding used when reading/writing the model.
716      */
717     public void setModelEncoding( String modelEncoding )
718     {
719         this.modelEncoding = modelEncoding;
720     }
721 
722     /**
723      * @return the current encoding used when reading/writing this model.
724      */
725     public String getModelEncoding()
726     {
727         return modelEncoding;
728     }
729 }