001// =================== DO NOT EDIT THIS FILE ====================
002// Generated by Modello 1.8.1,
003// any modifications will be overwritten.
004// ==============================================================
005
006package org.apache.maven.model;
007
008/**
009 * 
010 *         
011 *         The <code>&lt;plugin&gt;</code> element contains
012 * informations required for a plugin.
013 *         
014 *       
015 * 
016 * @version $Revision$ $Date$
017 */
018@SuppressWarnings( "all" )
019public class Plugin
020    extends ConfigurationContainer
021    implements java.io.Serializable, java.lang.Cloneable
022{
023
024      //--------------------------/
025     //- Class/Member Variables -/
026    //--------------------------/
027
028    /**
029     * The group ID of the plugin in the repository.
030     */
031    private String groupId = "org.apache.maven.plugins";
032
033    /**
034     * The artifact ID of the plugin in the repository.
035     */
036    private String artifactId;
037
038    /**
039     * The version (or valid range of versions) of the plugin to be
040     * used.
041     */
042    private String version;
043
044    /**
045     * 
046     *             
047     *             Whether to load Maven extensions (such as
048     * packaging and type handlers) from
049     *             this plugin. For performance reasons, this
050     * should only be enabled when necessary. Note: While the type
051     *             of this field is <code>String</code> for
052     * technical reasons, the semantic type is actually
053     *             <code>Boolean</code>. Default value is
054     * <code>false</code>.
055     *             
056     *           
057     */
058    private String extensions;
059
060    /**
061     * Field executions.
062     */
063    private java.util.List<PluginExecution> executions;
064
065    /**
066     * Field dependencies.
067     */
068    private java.util.List<Dependency> dependencies;
069
070    /**
071     * 
072     *             
073     *             <b>Deprecated</b>. Unused by Maven.
074     *             
075     *           
076     */
077    private Object goals;
078
079
080      //-----------/
081     //- Methods -/
082    //-----------/
083
084    /**
085     * Method addDependency.
086     * 
087     * @param dependency
088     */
089    public void addDependency( Dependency dependency )
090    {
091        getDependencies().add( dependency );
092    } //-- void addDependency( Dependency )
093
094    /**
095     * Method addExecution.
096     * 
097     * @param pluginExecution
098     */
099    public void addExecution( PluginExecution pluginExecution )
100    {
101        getExecutions().add( pluginExecution );
102    } //-- void addExecution( PluginExecution )
103
104    /**
105     * Method clone.
106     * 
107     * @return Plugin
108     */
109    public Plugin clone()
110    {
111        try
112        {
113            Plugin copy = (Plugin) super.clone();
114
115            if ( this.executions != null )
116            {
117                copy.executions = new java.util.ArrayList<PluginExecution>();
118                for ( PluginExecution item : this.executions )
119                {
120                    copy.executions.add( ( (PluginExecution) item).clone() );
121                }
122            }
123
124            if ( this.dependencies != null )
125            {
126                copy.dependencies = new java.util.ArrayList<Dependency>();
127                for ( Dependency item : this.dependencies )
128                {
129                    copy.dependencies.add( ( (Dependency) item).clone() );
130                }
131            }
132
133            if ( this.goals != null )
134            {
135                copy.goals = new org.codehaus.plexus.util.xml.Xpp3Dom( (org.codehaus.plexus.util.xml.Xpp3Dom) this.goals );
136            }
137
138            return copy;
139        }
140        catch ( java.lang.Exception ex )
141        {
142            throw (java.lang.RuntimeException) new java.lang.UnsupportedOperationException( getClass().getName()
143                + " does not support clone()" ).initCause( ex );
144        }
145    } //-- Plugin clone()
146
147    /**
148     * Get the artifact ID of the plugin in the repository.
149     * 
150     * @return String
151     */
152    public String getArtifactId()
153    {
154        return this.artifactId;
155    } //-- String getArtifactId()
156
157    /**
158     * Method getDependencies.
159     * 
160     * @return List
161     */
162    public java.util.List<Dependency> getDependencies()
163    {
164        if ( this.dependencies == null )
165        {
166            this.dependencies = new java.util.ArrayList<Dependency>();
167        }
168
169        return this.dependencies;
170    } //-- java.util.List<Dependency> getDependencies()
171
172    /**
173     * Method getExecutions.
174     * 
175     * @return List
176     */
177    public java.util.List<PluginExecution> getExecutions()
178    {
179        if ( this.executions == null )
180        {
181            this.executions = new java.util.ArrayList<PluginExecution>();
182        }
183
184        return this.executions;
185    } //-- java.util.List<PluginExecution> getExecutions()
186
187    /**
188     * Get whether to load Maven extensions (such as packaging and
189     * type handlers) from
190     *             this plugin. For performance reasons, this
191     * should only be enabled when necessary. Note: While the type
192     *             of this field is <code>String</code> for
193     * technical reasons, the semantic type is actually
194     *             <code>Boolean</code>. Default value is
195     * <code>false</code>.
196     * 
197     * @return String
198     */
199    public String getExtensions()
200    {
201        return this.extensions;
202    } //-- String getExtensions()
203
204    /**
205     * Get <b>Deprecated</b>. Unused by Maven.
206     * 
207     * @return Object
208     */
209    public Object getGoals()
210    {
211        return this.goals;
212    } //-- Object getGoals()
213
214    /**
215     * Get the group ID of the plugin in the repository.
216     * 
217     * @return String
218     */
219    public String getGroupId()
220    {
221        return this.groupId;
222    } //-- String getGroupId()
223
224    /**
225     * Get the version (or valid range of versions) of the plugin
226     * to be used.
227     * 
228     * @return String
229     */
230    public String getVersion()
231    {
232        return this.version;
233    } //-- String getVersion()
234
235    /**
236     * Method removeDependency.
237     * 
238     * @param dependency
239     */
240    public void removeDependency( Dependency dependency )
241    {
242        getDependencies().remove( dependency );
243    } //-- void removeDependency( Dependency )
244
245    /**
246     * Method removeExecution.
247     * 
248     * @param pluginExecution
249     */
250    public void removeExecution( PluginExecution pluginExecution )
251    {
252        getExecutions().remove( pluginExecution );
253    } //-- void removeExecution( PluginExecution )
254
255    /**
256     * Set the artifact ID of the plugin in the repository.
257     * 
258     * @param artifactId
259     */
260    public void setArtifactId( String artifactId )
261    {
262        this.artifactId = artifactId;
263    } //-- void setArtifactId( String )
264
265    /**
266     * Set additional dependencies that this project needs to
267     * introduce to the plugin's
268     *             classloader.
269     * 
270     * @param dependencies
271     */
272    public void setDependencies( java.util.List<Dependency> dependencies )
273    {
274        this.dependencies = dependencies;
275    } //-- void setDependencies( java.util.List )
276
277    /**
278     * Set multiple specifications of a set of goals to execute
279     * during the build
280     *             lifecycle, each having (possibly) a different
281     * configuration.
282     * 
283     * @param executions
284     */
285    public void setExecutions( java.util.List<PluginExecution> executions )
286    {
287        this.executions = executions;
288    } //-- void setExecutions( java.util.List )
289
290    /**
291     * Set whether to load Maven extensions (such as packaging and
292     * type handlers) from
293     *             this plugin. For performance reasons, this
294     * should only be enabled when necessary. Note: While the type
295     *             of this field is <code>String</code> for
296     * technical reasons, the semantic type is actually
297     *             <code>Boolean</code>. Default value is
298     * <code>false</code>.
299     * 
300     * @param extensions
301     */
302    public void setExtensions( String extensions )
303    {
304        this.extensions = extensions;
305    } //-- void setExtensions( String )
306
307    /**
308     * Set <b>Deprecated</b>. Unused by Maven.
309     * 
310     * @param goals
311     */
312    public void setGoals( Object goals )
313    {
314        this.goals = goals;
315    } //-- void setGoals( Object )
316
317    /**
318     * Set the group ID of the plugin in the repository.
319     * 
320     * @param groupId
321     */
322    public void setGroupId( String groupId )
323    {
324        this.groupId = groupId;
325    } //-- void setGroupId( String )
326
327    /**
328     * Set the version (or valid range of versions) of the plugin
329     * to be used.
330     * 
331     * @param version
332     */
333    public void setVersion( String version )
334    {
335        this.version = version;
336    } //-- void setVersion( String )
337
338    
339            
340    public boolean isExtensions()
341    {
342        return ( extensions != null ) ? Boolean.parseBoolean( extensions ) : false;
343    }
344
345    public void setExtensions( boolean extensions )
346    {
347        this.extensions = String.valueOf( extensions );
348    }
349
350    private java.util.Map<String, PluginExecution> executionMap = null;
351
352    /**
353     * Reset the <code>executionMap</code> field to <code>null</code>
354     */
355    public void flushExecutionMap()
356    {
357        this.executionMap = null;
358    }
359
360    /**
361     * @return a Map of executions field with <code>PluginExecution#getId()</code> as key
362     * @see org.apache.maven.model.PluginExecution#getId()
363     */
364    public java.util.Map<String, PluginExecution> getExecutionsAsMap()
365    {
366        if ( executionMap == null )
367        {
368            executionMap = new java.util.LinkedHashMap<String, PluginExecution>();
369            if ( getExecutions() != null )
370            {
371                for ( java.util.Iterator<PluginExecution> i = getExecutions().iterator(); i.hasNext(); )
372                {
373                    PluginExecution exec = (PluginExecution) i.next();
374
375                    if ( executionMap.containsKey( exec.getId() ) )
376                    {
377                        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" );
378                    }
379
380                    executionMap.put( exec.getId(), exec );
381                }
382            }
383        }
384
385        return executionMap;
386    }
387
388    /**
389     * Gets the identifier of the plugin.
390     *
391     * @return The plugin id in the form {@code <groupId>:<artifactId>:<version>}, never {@code null}.
392     */
393    public String getId()
394    {
395        StringBuilder id = new StringBuilder( 128 );
396
397        id.append( ( getGroupId() == null ) ? "[unknown-group-id]" : getGroupId() );
398        id.append( ":" );
399        id.append( ( getArtifactId() == null ) ? "[unknown-artifact-id]" : getArtifactId() );
400        id.append( ":" );
401        id.append( ( getVersion() == null ) ? "[unknown-version]" : getVersion() );
402
403        return id.toString();
404    }
405
406    //TODO we shall reset key variable when groupId/artifactId change
407    private String key = null;
408    /**
409     * @return the key of the plugin, ie <code>groupId:artifactId</code>
410     */
411    public String getKey()
412    {
413        if ( key == null )
414        {
415            key = constructKey( groupId, artifactId );
416        }
417        return key;
418    }
419
420    /**
421     * @param groupId
422     * @param artifactId
423     * @return the key of the plugin, ie <code>groupId:artifactId</code>
424     */
425    public static String constructKey( String groupId, String artifactId )
426    {
427        return groupId + ":" + artifactId;
428    }
429
430    /**
431     * @see java.lang.Object#equals(java.lang.Object)
432     */
433    public boolean equals( Object other )
434    {
435        if ( other instanceof Plugin )
436        {
437            Plugin otherPlugin = (Plugin) other;
438
439            return getKey().equals( otherPlugin.getKey() );
440        }
441
442        return false;
443    }
444
445    /**
446     * @see java.lang.Object#hashCode()
447     */
448    public int hashCode()
449    {
450        return getKey().hashCode();
451    }
452
453    /**
454     * @see java.lang.Object#toString()
455     */
456    public String toString()
457    {
458        return "Plugin [" + getKey() + "]";
459    }
460            
461          
462}