View Javadoc

1   /*
2    =================== DO NOT EDIT THIS FILE ====================
3    Generated by Modello 1.4.1 on 2013-02-24 03:32:14,
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  @SuppressWarnings( "all" )
21  public class Plugin
22      extends ConfigurationContainer
23      implements java.io.Serializable, java.lang.Cloneable
24  {
25  
26        //--------------------------/
27       //- Class/Member Variables -/
28      //--------------------------/
29  
30      /**
31       * The group ID of the plugin in the repository.
32       */
33      private String groupId = "org.apache.maven.plugins";
34  
35      /**
36       * The artifact ID of the plugin in the repository.
37       */
38      private String artifactId;
39  
40      /**
41       * The version (or valid range of versions) of the plugin to be
42       * used.
43       */
44      private String version;
45  
46      /**
47       * 
48       *             
49       *             Whether to load Maven extensions (such as
50       * packaging and type handlers) from
51       *             this plugin. For performance reasons, this
52       * should only be enabled when necessary. Note: While the type
53       *             of this field is <code>String</code> for
54       * technical reasons, the semantic type is actually
55       *             <code>Boolean</code>. Default value is
56       * <code>false</code>.
57       *             
58       *           
59       */
60      private String extensions;
61  
62      /**
63       * Field executions.
64       */
65      private java.util.List<PluginExecution> executions;
66  
67      /**
68       * Field dependencies.
69       */
70      private java.util.List<Dependency> dependencies;
71  
72      /**
73       * 
74       *             
75       *             <b>Deprecated</b>. Unused by Maven.
76       *             
77       *           
78       */
79      private Object goals;
80  
81  
82        //-----------/
83       //- Methods -/
84      //-----------/
85  
86      /**
87       * Method addDependency.
88       * 
89       * @param dependency
90       */
91      public void addDependency( Dependency dependency )
92      {
93          getDependencies().add( dependency );
94      } //-- void addDependency( Dependency )
95  
96      /**
97       * Method addExecution.
98       * 
99       * @param pluginExecution
100      */
101     public void addExecution( PluginExecution pluginExecution )
102     {
103         getExecutions().add( pluginExecution );
104     } //-- void addExecution( PluginExecution )
105 
106     /**
107      * Method clone.
108      * 
109      * @return Plugin
110      */
111     public Plugin clone()
112     {
113         try
114         {
115             Plugin copy = (Plugin) super.clone();
116 
117             if ( this.executions != null )
118             {
119                 copy.executions = new java.util.ArrayList<PluginExecution>();
120                 for ( PluginExecution item : this.executions )
121                 {
122                     copy.executions.add( ( (PluginExecution) item).clone() );
123                 }
124             }
125 
126             if ( this.dependencies != null )
127             {
128                 copy.dependencies = new java.util.ArrayList<Dependency>();
129                 for ( Dependency item : this.dependencies )
130                 {
131                     copy.dependencies.add( ( (Dependency) item).clone() );
132                 }
133             }
134 
135             if ( this.goals != null )
136             {
137                 copy.goals = new org.codehaus.plexus.util.xml.Xpp3Dom( (org.codehaus.plexus.util.xml.Xpp3Dom) this.goals );
138             }
139 
140             return copy;
141         }
142         catch ( java.lang.Exception ex )
143         {
144             throw (java.lang.RuntimeException) new java.lang.UnsupportedOperationException( getClass().getName()
145                 + " does not support clone()" ).initCause( ex );
146         }
147     } //-- Plugin clone()
148 
149     /**
150      * Get the artifact ID of the plugin in the repository.
151      * 
152      * @return String
153      */
154     public String getArtifactId()
155     {
156         return this.artifactId;
157     } //-- String getArtifactId()
158 
159     /**
160      * Method getDependencies.
161      * 
162      * @return List
163      */
164     public java.util.List<Dependency> getDependencies()
165     {
166         if ( this.dependencies == null )
167         {
168             this.dependencies = new java.util.ArrayList<Dependency>();
169         }
170 
171         return this.dependencies;
172     } //-- java.util.List<Dependency> getDependencies()
173 
174     /**
175      * Method getExecutions.
176      * 
177      * @return List
178      */
179     public java.util.List<PluginExecution> getExecutions()
180     {
181         if ( this.executions == null )
182         {
183             this.executions = new java.util.ArrayList<PluginExecution>();
184         }
185 
186         return this.executions;
187     } //-- java.util.List<PluginExecution> getExecutions()
188 
189     /**
190      * Get whether to load Maven extensions (such as packaging and
191      * type handlers) from
192      *             this plugin. For performance reasons, this
193      * should only be enabled when necessary. Note: While the type
194      *             of this field is <code>String</code> for
195      * technical reasons, the semantic type is actually
196      *             <code>Boolean</code>. Default value is
197      * <code>false</code>.
198      * 
199      * @return String
200      */
201     public String getExtensions()
202     {
203         return this.extensions;
204     } //-- String getExtensions()
205 
206     /**
207      * Get <b>Deprecated</b>. Unused by Maven.
208      * 
209      * @return Object
210      */
211     public Object getGoals()
212     {
213         return this.goals;
214     } //-- Object getGoals()
215 
216     /**
217      * Get the group ID of the plugin in the repository.
218      * 
219      * @return String
220      */
221     public String getGroupId()
222     {
223         return this.groupId;
224     } //-- String getGroupId()
225 
226     /**
227      * Get the version (or valid range of versions) of the plugin
228      * to be used.
229      * 
230      * @return String
231      */
232     public String getVersion()
233     {
234         return this.version;
235     } //-- String getVersion()
236 
237     /**
238      * Method removeDependency.
239      * 
240      * @param dependency
241      */
242     public void removeDependency( Dependency dependency )
243     {
244         getDependencies().remove( dependency );
245     } //-- void removeDependency( Dependency )
246 
247     /**
248      * Method removeExecution.
249      * 
250      * @param pluginExecution
251      */
252     public void removeExecution( PluginExecution pluginExecution )
253     {
254         getExecutions().remove( pluginExecution );
255     } //-- void removeExecution( PluginExecution )
256 
257     /**
258      * Set the artifact ID of the plugin in the repository.
259      * 
260      * @param artifactId
261      */
262     public void setArtifactId( String artifactId )
263     {
264         this.artifactId = artifactId;
265     } //-- void setArtifactId( String )
266 
267     /**
268      * Set additional dependencies that this project needs to
269      * introduce to the plugin's
270      *             classloader.
271      * 
272      * @param dependencies
273      */
274     public void setDependencies( java.util.List<Dependency> dependencies )
275     {
276         this.dependencies = dependencies;
277     } //-- void setDependencies( java.util.List )
278 
279     /**
280      * Set multiple specifications of a set of goals to execute
281      * during the build
282      *             lifecycle, each having (possibly) a different
283      * configuration.
284      * 
285      * @param executions
286      */
287     public void setExecutions( java.util.List<PluginExecution> executions )
288     {
289         this.executions = executions;
290     } //-- void setExecutions( java.util.List )
291 
292     /**
293      * Set whether to load Maven extensions (such as packaging and
294      * type handlers) from
295      *             this plugin. For performance reasons, this
296      * should only be enabled when necessary. Note: While the type
297      *             of this field is <code>String</code> for
298      * technical reasons, the semantic type is actually
299      *             <code>Boolean</code>. Default value is
300      * <code>false</code>.
301      * 
302      * @param extensions
303      */
304     public void setExtensions( String extensions )
305     {
306         this.extensions = extensions;
307     } //-- void setExtensions( String )
308 
309     /**
310      * Set <b>Deprecated</b>. Unused by Maven.
311      * 
312      * @param goals
313      */
314     public void setGoals( Object goals )
315     {
316         this.goals = goals;
317     } //-- void setGoals( Object )
318 
319     /**
320      * Set the group ID of the plugin in the repository.
321      * 
322      * @param groupId
323      */
324     public void setGroupId( String groupId )
325     {
326         this.groupId = groupId;
327     } //-- void setGroupId( String )
328 
329     /**
330      * Set the version (or valid range of versions) of the plugin
331      * to be used.
332      * 
333      * @param version
334      */
335     public void setVersion( String version )
336     {
337         this.version = version;
338     } //-- void setVersion( String )
339 
340     
341             
342     public boolean isExtensions()
343     {
344         return ( extensions != null ) ? Boolean.parseBoolean( extensions ) : false;
345     }
346 
347     public void setExtensions( boolean extensions )
348     {
349         this.extensions = String.valueOf( extensions );
350     }
351 
352     private java.util.Map<String, PluginExecution> executionMap = null;
353 
354     /**
355      * Reset the <code>executionMap</code> field to <code>null</code>
356      */
357     public void flushExecutionMap()
358     {
359         this.executionMap = null;
360     }
361 
362     /**
363      * @return a Map of executions field with <code>PluginExecution#getId()</code> as key
364      * @see org.apache.maven.model.PluginExecution#getId()
365      */
366     public java.util.Map<String, PluginExecution> getExecutionsAsMap()
367     {
368         if ( executionMap == null )
369         {
370             executionMap = new java.util.LinkedHashMap<String, PluginExecution>();
371             if ( getExecutions() != null )
372             {
373                 for ( java.util.Iterator<PluginExecution> i = getExecutions().iterator(); i.hasNext(); )
374                 {
375                     PluginExecution exec = (PluginExecution) i.next();
376 
377                     if ( executionMap.containsKey( exec.getId() ) )
378                     {
379                         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" );
380                     }
381 
382                     executionMap.put( exec.getId(), exec );
383                 }
384             }
385         }
386 
387         return executionMap;
388     }
389 
390     /**
391      * Gets the identifier of the plugin.
392      *
393      * @return The plugin id in the form {@code <groupId>:<artifactId>:<version>}, never {@code null}.
394      */
395     public String getId()
396     {
397         StringBuilder id = new StringBuilder( 128 );
398 
399         id.append( ( getGroupId() == null ) ? "[unknown-group-id]" : getGroupId() );
400         id.append( ":" );
401         id.append( ( getArtifactId() == null ) ? "[unknown-artifact-id]" : getArtifactId() );
402         id.append( ":" );
403         id.append( ( getVersion() == null ) ? "[unknown-version]" : getVersion() );
404 
405         return id.toString();
406     }
407 
408     //TODO we shall reset key variable when groupId/artifactId change
409     private String key = null;
410     /**
411      * @return the key of the plugin, ie <code>groupId:artifactId</code>
412      */
413     public String getKey()
414     {
415         if ( key == null )
416         {
417             key = constructKey( groupId, artifactId );
418         }
419         return key;
420     }
421 
422     /**
423      * @param groupId
424      * @param artifactId
425      * @return the key of the plugin, ie <code>groupId:artifactId</code>
426      */
427     public static String constructKey( String groupId, String artifactId )
428     {
429         return groupId + ":" + artifactId;
430     }
431 
432     /**
433      * @see java.lang.Object#equals(java.lang.Object)
434      */
435     public boolean equals( Object other )
436     {
437         if ( other instanceof Plugin )
438         {
439             Plugin otherPlugin = (Plugin) other;
440 
441             return getKey().equals( otherPlugin.getKey() );
442         }
443 
444         return false;
445     }
446 
447     /**
448      * @see java.lang.Object#hashCode()
449      */
450     public int hashCode()
451     {
452         return getKey().hashCode();
453     }
454 
455     /**
456      * @see java.lang.Object#toString()
457      */
458     public String toString()
459     {
460         return "Plugin [" + getKey() + "]";
461     }
462             
463           
464 }