View Javadoc

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