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