Coverage Report - org.apache.maven.settings.Settings
 
Classes in this File Line Coverage Branch Coverage Complexity
Settings
0%
0/144
0%
0/92
2
 
 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  0
 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  0
     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  0
     private boolean usePluginRegistry = false;
 57  
 
 58  
     /**
 59  
      * 
 60  
      *             
 61  
      *             Indicate whether maven should operate in offline
 62  
      * mode full-time.
 63  
      *             
 64  
      *           
 65  
      */
 66  0
     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  0
         if ( !(string instanceof String) )
 111  
         {
 112  0
             throw new ClassCastException( "Settings.addActiveProfiles(string) parameter must be instanceof " + String.class.getName() );
 113  
         }
 114  0
         getActiveProfiles().add( string );
 115  0
     } //-- void addActiveProfile( String ) 
 116  
 
 117  
     /**
 118  
      * Method addMirror.
 119  
      * 
 120  
      * @param mirror
 121  
      */
 122  
     public void addMirror( Mirror mirror )
 123  
     {
 124  0
         if ( !(mirror instanceof Mirror) )
 125  
         {
 126  0
             throw new ClassCastException( "Settings.addMirrors(mirror) parameter must be instanceof " + Mirror.class.getName() );
 127  
         }
 128  0
         getMirrors().add( mirror );
 129  0
     } //-- void addMirror( Mirror ) 
 130  
 
 131  
     /**
 132  
      * Method addPluginGroup.
 133  
      * 
 134  
      * @param string
 135  
      */
 136  
     public void addPluginGroup( String string )
 137  
     {
 138  0
         if ( !(string instanceof String) )
 139  
         {
 140  0
             throw new ClassCastException( "Settings.addPluginGroups(string) parameter must be instanceof " + String.class.getName() );
 141  
         }
 142  0
         getPluginGroups().add( string );
 143  0
     } //-- void addPluginGroup( String ) 
 144  
 
 145  
     /**
 146  
      * Method addProfile.
 147  
      * 
 148  
      * @param profile
 149  
      */
 150  
     public void addProfile( Profile profile )
 151  
     {
 152  0
         if ( !(profile instanceof Profile) )
 153  
         {
 154  0
             throw new ClassCastException( "Settings.addProfiles(profile) parameter must be instanceof " + Profile.class.getName() );
 155  
         }
 156  0
         getProfiles().add( profile );
 157  0
     } //-- void addProfile( Profile ) 
 158  
 
 159  
     /**
 160  
      * Method addProxy.
 161  
      * 
 162  
      * @param proxy
 163  
      */
 164  
     public void addProxy( Proxy proxy )
 165  
     {
 166  0
         if ( !(proxy instanceof Proxy) )
 167  
         {
 168  0
             throw new ClassCastException( "Settings.addProxies(proxy) parameter must be instanceof " + Proxy.class.getName() );
 169  
         }
 170  0
         getProxies().add( proxy );
 171  0
     } //-- void addProxy( Proxy ) 
 172  
 
 173  
     /**
 174  
      * Method addServer.
 175  
      * 
 176  
      * @param server
 177  
      */
 178  
     public void addServer( Server server )
 179  
     {
 180  0
         if ( !(server instanceof Server) )
 181  
         {
 182  0
             throw new ClassCastException( "Settings.addServers(server) parameter must be instanceof " + Server.class.getName() );
 183  
         }
 184  0
         getServers().add( server );
 185  0
     } //-- void addServer( Server ) 
 186  
 
 187  
     /**
 188  
      * Method getActiveProfiles.
 189  
      * 
 190  
      * @return java.util.List
 191  
      */
 192  
     public java.util.List getActiveProfiles()
 193  
     {
 194  0
         if ( this.activeProfiles == null )
 195  
         {
 196  0
             this.activeProfiles = new java.util.ArrayList();
 197  
         }
 198  
     
 199  0
         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  0
         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  0
         if ( this.mirrors == null )
 224  
         {
 225  0
             this.mirrors = new java.util.ArrayList();
 226  
         }
 227  
     
 228  0
         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  0
         if ( this.pluginGroups == null )
 239  
         {
 240  0
             this.pluginGroups = new java.util.ArrayList();
 241  
         }
 242  
     
 243  0
         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  0
         if ( this.profiles == null )
 254  
         {
 255  0
             this.profiles = new java.util.ArrayList();
 256  
         }
 257  
     
 258  0
         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  0
         if ( this.proxies == null )
 269  
         {
 270  0
             this.proxies = new java.util.ArrayList();
 271  
         }
 272  
     
 273  0
         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  0
         if ( this.servers == null )
 284  
         {
 285  0
             this.servers = new java.util.ArrayList();
 286  
         }
 287  
     
 288  0
         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  0
         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  0
         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  0
         return this.usePluginRegistry;
 334  
     } //-- boolean isUsePluginRegistry() 
 335  
 
 336  
     /**
 337  
      * Method removeActiveProfile.
 338  
      * 
 339  
      * @param string
 340  
      */
 341  
     public void removeActiveProfile( String string )
 342  
     {
 343  0
         if ( !(string instanceof String) )
 344  
         {
 345  0
             throw new ClassCastException( "Settings.removeActiveProfiles(string) parameter must be instanceof " + String.class.getName() );
 346  
         }
 347  0
         getActiveProfiles().remove( string );
 348  0
     } //-- void removeActiveProfile( String ) 
 349  
 
 350  
     /**
 351  
      * Method removeMirror.
 352  
      * 
 353  
      * @param mirror
 354  
      */
 355  
     public void removeMirror( Mirror mirror )
 356  
     {
 357  0
         if ( !(mirror instanceof Mirror) )
 358  
         {
 359  0
             throw new ClassCastException( "Settings.removeMirrors(mirror) parameter must be instanceof " + Mirror.class.getName() );
 360  
         }
 361  0
         getMirrors().remove( mirror );
 362  0
     } //-- void removeMirror( Mirror ) 
 363  
 
 364  
     /**
 365  
      * Method removePluginGroup.
 366  
      * 
 367  
      * @param string
 368  
      */
 369  
     public void removePluginGroup( String string )
 370  
     {
 371  0
         if ( !(string instanceof String) )
 372  
         {
 373  0
             throw new ClassCastException( "Settings.removePluginGroups(string) parameter must be instanceof " + String.class.getName() );
 374  
         }
 375  0
         getPluginGroups().remove( string );
 376  0
     } //-- void removePluginGroup( String ) 
 377  
 
 378  
     /**
 379  
      * Method removeProfile.
 380  
      * 
 381  
      * @param profile
 382  
      */
 383  
     public void removeProfile( Profile profile )
 384  
     {
 385  0
         if ( !(profile instanceof Profile) )
 386  
         {
 387  0
             throw new ClassCastException( "Settings.removeProfiles(profile) parameter must be instanceof " + Profile.class.getName() );
 388  
         }
 389  0
         getProfiles().remove( profile );
 390  0
     } //-- void removeProfile( Profile ) 
 391  
 
 392  
     /**
 393  
      * Method removeProxy.
 394  
      * 
 395  
      * @param proxy
 396  
      */
 397  
     public void removeProxy( Proxy proxy )
 398  
     {
 399  0
         if ( !(proxy instanceof Proxy) )
 400  
         {
 401  0
             throw new ClassCastException( "Settings.removeProxies(proxy) parameter must be instanceof " + Proxy.class.getName() );
 402  
         }
 403  0
         getProxies().remove( proxy );
 404  0
     } //-- void removeProxy( Proxy ) 
 405  
 
 406  
     /**
 407  
      * Method removeServer.
 408  
      * 
 409  
      * @param server
 410  
      */
 411  
     public void removeServer( Server server )
 412  
     {
 413  0
         if ( !(server instanceof Server) )
 414  
         {
 415  0
             throw new ClassCastException( "Settings.removeServers(server) parameter must be instanceof " + Server.class.getName() );
 416  
         }
 417  0
         getServers().remove( server );
 418  0
     } //-- 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  0
         this.activeProfiles = activeProfiles;
 434  0
     } //-- 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  0
         this.interactiveMode = interactiveMode;
 449  0
     } //-- 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  0
         this.localRepository = localRepository;
 463  0
     } //-- 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  0
         this.mirrors = mirrors;
 476  0
     } //-- 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  0
         this.offline = offline;
 491  0
     } //-- 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  0
         this.pluginGroups = pluginGroups;
 505  0
     } //-- 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  0
         this.profiles = profiles;
 521  0
     } //-- 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  0
         this.proxies = proxies;
 544  0
     } //-- 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  0
         this.servers = servers;
 562  0
     } //-- 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  0
         this.usePluginRegistry = usePluginRegistry;
 577  0
     } //-- void setUsePluginRegistry( boolean ) 
 578  
 
 579  
 
 580  
             
 581  
     public Boolean getInteractiveMode()
 582  
     {
 583  0
         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  0
         this.activeProxy = null;
 594  0
     }
 595  
 
 596  
     /**
 597  
      * @return the first active proxy
 598  
      */
 599  
     public synchronized Proxy getActiveProxy()
 600  
     {
 601  0
         if(activeProxy == null)
 602  
         {
 603  0
             java.util.List proxies = getProxies();
 604  0
             if ( proxies != null && !proxies.isEmpty() )
 605  
             {
 606  0
                 for ( java.util.Iterator it = proxies.iterator(); it.hasNext(); )
 607  
                 {
 608  0
                     Proxy proxy = (Proxy) it.next();
 609  0
                     if ( proxy.isActive() )
 610  
                     {
 611  0
                         activeProxy = proxy;
 612  0
                         break;
 613  
                     }
 614  0
                 }
 615  
             }
 616  
         }
 617  
 
 618  0
         return activeProxy;
 619  
     }
 620  
 
 621  
     public Server getServer( String serverId )
 622  
     {
 623  0
         Server match = null;
 624  
 
 625  0
         java.util.List servers = getServers();
 626  0
         if ( servers != null && serverId != null )
 627  
         {
 628  0
             for ( java.util.Iterator it = servers.iterator(); it.hasNext(); )
 629  
             {
 630  0
                 Server server = (Server) it.next();
 631  0
                 if ( serverId.equals( server.getId() ) )
 632  
                 {
 633  0
                     match = server;
 634  0
                     break;
 635  
                 }
 636  0
             }
 637  
         }
 638  
 
 639  0
         return match;
 640  
     }
 641  
 
 642  
     public Mirror getMirrorOf( String repositoryId )
 643  
     {
 644  0
         Mirror match = null;
 645  
 
 646  0
         java.util.List mirrors = getMirrors();
 647  0
         if ( mirrors != null && repositoryId != null )
 648  
         {
 649  0
             for ( java.util.Iterator it = mirrors.iterator(); it.hasNext(); )
 650  
             {
 651  0
                 Mirror mirror = (Mirror) it.next();
 652  0
                 if ( repositoryId.equals( mirror.getMirrorOf() ) )
 653  
                 {
 654  0
                     match = mirror;
 655  0
                     break;
 656  
                 }
 657  0
             }
 658  
         }
 659  
 
 660  0
         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  0
         this.profileMap = null;
 671  0
     }
 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  0
         if ( profileMap == null )
 680  
         {
 681  0
             profileMap = new java.util.LinkedHashMap();
 682  
 
 683  0
             if ( getProfiles() != null )
 684  
             {
 685  0
                 for ( java.util.Iterator it = getProfiles().iterator(); it.hasNext(); )
 686  
                 {
 687  0
                     Profile profile = (Profile) it.next();
 688  
 
 689  0
                     profileMap.put( profile.getId(), profile );
 690  0
                 }
 691  
             }
 692  
         }
 693  
 
 694  0
         return profileMap;
 695  
     }
 696  
 
 697  
     private RuntimeInfo runtimeInfo;
 698  
 
 699  
     public void setRuntimeInfo( RuntimeInfo runtimeInfo )
 700  
     {
 701  0
         this.runtimeInfo = runtimeInfo;
 702  0
     }
 703  
 
 704  
     public RuntimeInfo getRuntimeInfo()
 705  
     {
 706  0
         return runtimeInfo;
 707  
     }
 708  
             
 709  
           
 710  0
     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  0
         this.modelEncoding = modelEncoding;
 720  0
     }
 721  
 
 722  
     /**
 723  
      * @return the current encoding used when reading/writing this model.
 724  
      */
 725  
     public String getModelEncoding()
 726  
     {
 727  0
         return modelEncoding;
 728  
     }
 729  
 }