Coverage Report - org.apache.maven.model.Plugin
 
Classes in this File Line Coverage Branch Coverage Complexity
Plugin
0%
0/69
0%
0/30
1.63
 
 1  
 /*
 2  
  * $Id$
 3  
  */
 4  
 
 5  
 package org.apache.maven.model;
 6  
 
 7  
   //---------------------------------/
 8  
  //- Imported classes and packages -/
 9  
 //---------------------------------/
 10  
 
 11  
 import java.util.Date;
 12  
 
 13  
 /**
 14  
  * 
 15  
  *         
 16  
  *         The <code>&lt;plugin&gt;</code> element contains
 17  
  * informations required for a plugin.
 18  
  *         
 19  
  *       
 20  
  * 
 21  
  * @version $Revision$ $Date$
 22  
  */
 23  0
 public class Plugin extends ConfigurationContainer 
 24  
 implements java.io.Serializable
 25  
 {
 26  
 
 27  
 
 28  
       //--------------------------/
 29  
      //- Class/Member Variables -/
 30  
     //--------------------------/
 31  
 
 32  
     /**
 33  
      * The group ID of the plugin in the repository.
 34  
      */
 35  0
     private String groupId = "org.apache.maven.plugins";
 36  
 
 37  
     /**
 38  
      * The artifact ID of the plugin in the repository.
 39  
      */
 40  
     private String artifactId;
 41  
 
 42  
     /**
 43  
      * The version (or valid range of versions) of the plugin to be
 44  
      * used.
 45  
      */
 46  
     private String version;
 47  
 
 48  
     /**
 49  
      * Whether to load Maven extensions (such as packaging and type
 50  
      * handlers) from
 51  
      *             this plugin. For performance reasons, this
 52  
      * should only be enabled when necessary.
 53  
      */
 54  0
     private boolean extensions = false;
 55  
 
 56  
     /**
 57  
      * Field executions.
 58  
      */
 59  
     private java.util.List executions;
 60  
 
 61  
     /**
 62  
      * Field dependencies.
 63  
      */
 64  
     private java.util.List dependencies;
 65  
 
 66  
     /**
 67  
      * 
 68  
      *             
 69  
      *             <b>Deprecated</b>. Unused by Maven.
 70  
      *             
 71  
      *           
 72  
      */
 73  
     private Object goals;
 74  
 
 75  
 
 76  
       //-----------/
 77  
      //- Methods -/
 78  
     //-----------/
 79  
 
 80  
     /**
 81  
      * Method addDependency.
 82  
      * 
 83  
      * @param dependency
 84  
      */
 85  
     public void addDependency( Dependency dependency )
 86  
     {
 87  0
         if ( !(dependency instanceof Dependency) )
 88  
         {
 89  0
             throw new ClassCastException( "Plugin.addDependencies(dependency) parameter must be instanceof " + Dependency.class.getName() );
 90  
         }
 91  0
         getDependencies().add( dependency );
 92  0
     } //-- void addDependency( Dependency ) 
 93  
 
 94  
     /**
 95  
      * Method addExecution.
 96  
      * 
 97  
      * @param pluginExecution
 98  
      */
 99  
     public void addExecution( PluginExecution pluginExecution )
 100  
     {
 101  0
         if ( !(pluginExecution instanceof PluginExecution) )
 102  
         {
 103  0
             throw new ClassCastException( "Plugin.addExecutions(pluginExecution) parameter must be instanceof " + PluginExecution.class.getName() );
 104  
         }
 105  0
         getExecutions().add( pluginExecution );
 106  0
     } //-- void addExecution( PluginExecution ) 
 107  
 
 108  
     /**
 109  
      * Get the artifact ID of the plugin in the repository.
 110  
      * 
 111  
      * @return String
 112  
      */
 113  
     public String getArtifactId()
 114  
     {
 115  0
         return this.artifactId;
 116  
     } //-- String getArtifactId() 
 117  
 
 118  
     /**
 119  
      * Method getDependencies.
 120  
      * 
 121  
      * @return java.util.List
 122  
      */
 123  
     public java.util.List getDependencies()
 124  
     {
 125  0
         if ( this.dependencies == null )
 126  
         {
 127  0
             this.dependencies = new java.util.ArrayList();
 128  
         }
 129  
     
 130  0
         return this.dependencies;
 131  
     } //-- java.util.List getDependencies() 
 132  
 
 133  
     /**
 134  
      * Method getExecutions.
 135  
      * 
 136  
      * @return java.util.List
 137  
      */
 138  
     public java.util.List getExecutions()
 139  
     {
 140  0
         if ( this.executions == null )
 141  
         {
 142  0
             this.executions = new java.util.ArrayList();
 143  
         }
 144  
     
 145  0
         return this.executions;
 146  
     } //-- java.util.List getExecutions() 
 147  
 
 148  
     /**
 149  
      * Get 
 150  
      *             
 151  
      *             <b>Deprecated</b>. Unused by Maven.
 152  
      *             
 153  
      *           
 154  
      * 
 155  
      * @return Object
 156  
      */
 157  
     public Object getGoals()
 158  
     {
 159  0
         return this.goals;
 160  
     } //-- Object getGoals() 
 161  
 
 162  
     /**
 163  
      * Get the group ID of the plugin in the repository.
 164  
      * 
 165  
      * @return String
 166  
      */
 167  
     public String getGroupId()
 168  
     {
 169  0
         return this.groupId;
 170  
     } //-- String getGroupId() 
 171  
 
 172  
     /**
 173  
      * Get the version (or valid range of versions) of the plugin
 174  
      * to be used.
 175  
      * 
 176  
      * @return String
 177  
      */
 178  
     public String getVersion()
 179  
     {
 180  0
         return this.version;
 181  
     } //-- String getVersion() 
 182  
 
 183  
     /**
 184  
      * Get whether to load Maven extensions (such as packaging and
 185  
      * type handlers) from
 186  
      *             this plugin. For performance reasons, this
 187  
      * should only be enabled when necessary.
 188  
      * 
 189  
      * @return boolean
 190  
      */
 191  
     public boolean isExtensions()
 192  
     {
 193  0
         return this.extensions;
 194  
     } //-- boolean isExtensions() 
 195  
 
 196  
     /**
 197  
      * Method removeDependency.
 198  
      * 
 199  
      * @param dependency
 200  
      */
 201  
     public void removeDependency( Dependency dependency )
 202  
     {
 203  0
         if ( !(dependency instanceof Dependency) )
 204  
         {
 205  0
             throw new ClassCastException( "Plugin.removeDependencies(dependency) parameter must be instanceof " + Dependency.class.getName() );
 206  
         }
 207  0
         getDependencies().remove( dependency );
 208  0
     } //-- void removeDependency( Dependency ) 
 209  
 
 210  
     /**
 211  
      * Method removeExecution.
 212  
      * 
 213  
      * @param pluginExecution
 214  
      */
 215  
     public void removeExecution( PluginExecution pluginExecution )
 216  
     {
 217  0
         if ( !(pluginExecution instanceof PluginExecution) )
 218  
         {
 219  0
             throw new ClassCastException( "Plugin.removeExecutions(pluginExecution) parameter must be instanceof " + PluginExecution.class.getName() );
 220  
         }
 221  0
         getExecutions().remove( pluginExecution );
 222  0
     } //-- void removeExecution( PluginExecution ) 
 223  
 
 224  
     /**
 225  
      * Set the artifact ID of the plugin in the repository.
 226  
      * 
 227  
      * @param artifactId
 228  
      */
 229  
     public void setArtifactId( String artifactId )
 230  
     {
 231  0
         this.artifactId = artifactId;
 232  0
     } //-- void setArtifactId( String ) 
 233  
 
 234  
     /**
 235  
      * Set additional dependencies that this project needs to
 236  
      * introduce to the plugin's
 237  
      *             classloader.
 238  
      * 
 239  
      * @param dependencies
 240  
      */
 241  
     public void setDependencies( java.util.List dependencies )
 242  
     {
 243  0
         this.dependencies = dependencies;
 244  0
     } //-- void setDependencies( java.util.List ) 
 245  
 
 246  
     /**
 247  
      * Set multiple specifications of a set of goals to execute
 248  
      * during the build
 249  
      *             lifecycle, each having (possibly) a different
 250  
      * configuration.
 251  
      * 
 252  
      * @param executions
 253  
      */
 254  
     public void setExecutions( java.util.List executions )
 255  
     {
 256  0
         this.executions = executions;
 257  0
     } //-- void setExecutions( java.util.List ) 
 258  
 
 259  
     /**
 260  
      * Set whether to load Maven extensions (such as packaging and
 261  
      * type handlers) from
 262  
      *             this plugin. For performance reasons, this
 263  
      * should only be enabled when necessary.
 264  
      * 
 265  
      * @param extensions
 266  
      */
 267  
     public void setExtensions( boolean extensions )
 268  
     {
 269  0
         this.extensions = extensions;
 270  0
     } //-- void setExtensions( boolean ) 
 271  
 
 272  
     /**
 273  
      * Set 
 274  
      *             
 275  
      *             <b>Deprecated</b>. Unused by Maven.
 276  
      *             
 277  
      *           
 278  
      * 
 279  
      * @param goals
 280  
      */
 281  
     public void setGoals( Object goals )
 282  
     {
 283  0
         this.goals = goals;
 284  0
     } //-- void setGoals( Object ) 
 285  
 
 286  
     /**
 287  
      * Set the group ID of the plugin in the repository.
 288  
      * 
 289  
      * @param groupId
 290  
      */
 291  
     public void setGroupId( String groupId )
 292  
     {
 293  0
         this.groupId = groupId;
 294  0
     } //-- void setGroupId( String ) 
 295  
 
 296  
     /**
 297  
      * Set the version (or valid range of versions) of the plugin
 298  
      * to be used.
 299  
      * 
 300  
      * @param version
 301  
      */
 302  
     public void setVersion( String version )
 303  
     {
 304  0
         this.version = version;
 305  0
     } //-- void setVersion( String ) 
 306  
 
 307  
 
 308  
             
 309  0
     private java.util.Map executionMap = null;
 310  
 
 311  
     /**
 312  
      * Reset the <code>executionMap</code> field to <code>null</code>
 313  
      */
 314  
     public void flushExecutionMap()
 315  
     {
 316  0
         this.executionMap = null;
 317  0
     }
 318  
 
 319  
     /**
 320  
      * @return a Map of executions field with <code>PluginExecution#getId()</code> as key
 321  
      * @see org.apache.maven.model.PluginExecution#getId()
 322  
      */
 323  
     public java.util.Map getExecutionsAsMap()
 324  
     {
 325  0
         if ( executionMap == null )
 326  
         {
 327  0
             executionMap = new java.util.LinkedHashMap();
 328  0
             if ( getExecutions() != null )
 329  
             {
 330  0
                 for ( java.util.Iterator i = getExecutions().iterator(); i.hasNext(); )
 331  
                 {
 332  0
                     PluginExecution exec = (PluginExecution) i.next();
 333  
 
 334  0
                     if ( executionMap.containsKey( exec.getId() ) )
 335  
                     {
 336  0
                         throw new IllegalStateException( "You cannot have two plugin executions with the same (or missing) <id/> elements.\nOffending execution\n\nId: \'" + exec.getId() + "\'\nPlugin:\'" + getKey() + "\'\n\n" );
 337  
                     }
 338  
 
 339  0
                     executionMap.put( exec.getId(), exec );
 340  0
                 }
 341  
             }
 342  
         }
 343  
 
 344  0
         return executionMap;
 345  
     }
 346  
 
 347  
     /**
 348  
      * @return the key of the plugin, ie <code>groupId:artifactId</code>
 349  
      */
 350  
     public String getKey()
 351  
     {
 352  0
         return constructKey( groupId, artifactId );
 353  
     }
 354  
 
 355  
     /**
 356  
      * @param groupId
 357  
      * @param artifactId
 358  
      * @return the key of the plugin, ie <code>groupId:artifactId</code>
 359  
      */
 360  
     public static String constructKey( String groupId, String artifactId )
 361  
     {
 362  0
         return groupId + ":" + artifactId;
 363  
     }
 364  
 
 365  
     /**
 366  
      * @see java.lang.Object#equals(java.lang.Object)
 367  
      */
 368  
     public boolean equals( Object other )
 369  
     {
 370  0
         if ( other instanceof Plugin )
 371  
         {
 372  0
             Plugin otherPlugin = (Plugin) other;
 373  
 
 374  0
             return getKey().equals( otherPlugin.getKey() );
 375  
         }
 376  
 
 377  0
         return false;
 378  
     }
 379  
 
 380  
     /**
 381  
      * @see java.lang.Object#hashCode()
 382  
      */
 383  
     public int hashCode()
 384  
     {
 385  0
         return getKey().hashCode();
 386  
     }
 387  
 
 388  
     /**
 389  
      * @see java.lang.Object#toString()
 390  
      */
 391  
     public String toString()
 392  
     {
 393  0
         return "Plugin [" + getKey() + "]";
 394  
     }
 395  
             
 396  
           
 397  0
     private String modelEncoding = "UTF-8";
 398  
 
 399  
     /**
 400  
      * Set an encoding used for reading/writing the model.
 401  
      *
 402  
      * @param modelEncoding the encoding used when reading/writing the model.
 403  
      */
 404  
     public void setModelEncoding( String modelEncoding )
 405  
     {
 406  0
         this.modelEncoding = modelEncoding;
 407  0
     }
 408  
 
 409  
     /**
 410  
      * @return the current encoding used when reading/writing this model.
 411  
      */
 412  
     public String getModelEncoding()
 413  
     {
 414  0
         return modelEncoding;
 415  
     }
 416  
 }