KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > maven > plugin > descriptor > MojoDescriptor


1 package org.apache.maven.plugin.descriptor;
2
3 /*
4  * Copyright 2001-2004 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * 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, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 import org.apache.maven.plugin.Mojo;
20 import org.codehaus.plexus.component.repository.ComponentDescriptor;
21 import org.codehaus.plexus.configuration.PlexusConfiguration;
22 import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration;
23
24 import java.util.HashMap JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import java.util.LinkedList JavaDoc;
27 import java.util.List JavaDoc;
28 import java.util.Map JavaDoc;
29
30 /**
31  * The bean containing the mojo descriptor.
32  *
33  * @todo is there a need for the delegation of MavenMojoDescriptor to this? Why not just extend ComponentDescriptor here?
34  */

35 public class MojoDescriptor
36     extends ComponentDescriptor
37     implements Cloneable JavaDoc
38 {
39     public static String JavaDoc MAVEN_PLUGIN = "maven-plugin";
40
41     public static final String JavaDoc SINGLE_PASS_EXEC_STRATEGY = "once-per-session";
42
43     public static final String JavaDoc MULTI_PASS_EXEC_STRATEGY = "always";
44
45     private static final String JavaDoc DEFAULT_INSTANTIATION_STRATEGY = "per-lookup";
46
47     private static final String JavaDoc DEFAULT_LANGUAGE = "java";
48
49     private List JavaDoc parameters;
50
51     private Map JavaDoc parameterMap;
52
53     private String JavaDoc executionStrategy = SINGLE_PASS_EXEC_STRATEGY;
54
55     private String JavaDoc goal;
56
57     private String JavaDoc phase;
58
59     private String JavaDoc executePhase;
60
61     private String JavaDoc executeGoal;
62
63     private String JavaDoc executeLifecycle;
64
65     private String JavaDoc deprecated;
66
67     private boolean aggregator = false;
68
69     // ----------------------------------------------------------------------
70
//
71
// ----------------------------------------------------------------------
72

73     private String JavaDoc dependencyResolutionRequired = null;
74
75     private boolean projectRequired = true;
76
77     private boolean onlineRequired = false;
78
79     private PlexusConfiguration mojoConfiguration;
80
81     private PluginDescriptor pluginDescriptor;
82
83     private boolean inheritedByDefault = true;
84
85     private boolean directInvocationOnly = false;
86
87     private boolean requiresReports = false;
88
89     public MojoDescriptor()
90     {
91         setInstantiationStrategy( DEFAULT_INSTANTIATION_STRATEGY );
92         setComponentFactory( DEFAULT_LANGUAGE );
93     }
94
95     // ----------------------------------------------------------------------
96
//
97
// ----------------------------------------------------------------------
98

99     public String JavaDoc getLanguage()
100     {
101         return getComponentFactory();
102     }
103
104     public void setLanguage( String JavaDoc language )
105     {
106         setComponentFactory( language );
107     }
108
109     public String JavaDoc getDeprecated()
110     {
111         return deprecated;
112     }
113
114     public void setDeprecated( String JavaDoc deprecated )
115     {
116         this.deprecated = deprecated;
117     }
118
119     public List JavaDoc getParameters()
120     {
121         return parameters;
122     }
123
124     public void setParameters( List JavaDoc parameters )
125         throws DuplicateParameterException
126     {
127         for ( Iterator JavaDoc it = parameters.iterator(); it.hasNext(); )
128         {
129             Parameter parameter = (Parameter) it.next();
130             addParameter( parameter );
131         }
132     }
133
134     public void addParameter( Parameter parameter )
135         throws DuplicateParameterException
136     {
137         if ( parameters != null && parameters.contains( parameter ) )
138         {
139             throw new DuplicateParameterException( parameter.getName() +
140                 " has been declared multiple times in mojo with goal: " + getGoal() + " (implementation: " +
141                 getImplementation() + ")" );
142         }
143         else
144         {
145             if ( parameters == null )
146             {
147                 parameters = new LinkedList JavaDoc();
148             }
149
150             parameters.add( parameter );
151         }
152     }
153
154     public Map JavaDoc getParameterMap()
155     {
156         if ( parameterMap == null )
157         {
158             parameterMap = new HashMap JavaDoc();
159
160             if ( parameters != null )
161             {
162                 for ( Iterator JavaDoc iterator = parameters.iterator(); iterator.hasNext(); )
163                 {
164                     Parameter pd = (Parameter) iterator.next();
165
166                     parameterMap.put( pd.getName(), pd );
167                 }
168             }
169         }
170
171         return parameterMap;
172     }
173
174     // ----------------------------------------------------------------------
175
// Dependency requirement
176
// ----------------------------------------------------------------------
177

178     public void setDependencyResolutionRequired( String JavaDoc requiresDependencyResolution )
179     {
180         this.dependencyResolutionRequired = requiresDependencyResolution;
181     }
182
183     public String JavaDoc isDependencyResolutionRequired()
184     {
185         return dependencyResolutionRequired;
186     }
187
188     // ----------------------------------------------------------------------
189
// Project requirement
190
// ----------------------------------------------------------------------
191

192     public void setProjectRequired( boolean requiresProject )
193     {
194         this.projectRequired = requiresProject;
195     }
196
197     public boolean isProjectRequired()
198     {
199         return projectRequired;
200     }
201
202     // ----------------------------------------------------------------------
203
// Online vs. Offline requirement
204
// ----------------------------------------------------------------------
205

206     public void setOnlineRequired( boolean requiresOnline )
207     {
208         this.onlineRequired = requiresOnline;
209     }
210
211     // blech! this isn't even intelligible as a method name. provided for
212
// consistency...
213
public boolean isOnlineRequired()
214     {
215         return onlineRequired;
216     }
217
218     // more english-friendly method...keep the code clean! :)
219
public boolean requiresOnline()
220     {
221         return onlineRequired;
222     }
223
224     public String JavaDoc getPhase()
225     {
226         return phase;
227     }
228
229     public void setPhase( String JavaDoc phase )
230     {
231         this.phase = phase;
232     }
233
234     public String JavaDoc getGoal()
235     {
236         return goal;
237     }
238
239     public void setGoal( String JavaDoc goal )
240     {
241         this.goal = goal;
242     }
243
244     public String JavaDoc getExecutePhase()
245     {
246         return executePhase;
247     }
248
249     public void setExecutePhase( String JavaDoc executePhase )
250     {
251         this.executePhase = executePhase;
252     }
253
254     public boolean alwaysExecute()
255     {
256         return MULTI_PASS_EXEC_STRATEGY.equals( executionStrategy );
257     }
258
259     public String JavaDoc getExecutionStrategy()
260     {
261         return executionStrategy;
262     }
263
264     public void setExecutionStrategy( String JavaDoc executionStrategy )
265     {
266         this.executionStrategy = executionStrategy;
267     }
268
269     public PlexusConfiguration getMojoConfiguration()
270     {
271         if ( mojoConfiguration == null )
272         {
273             mojoConfiguration = new XmlPlexusConfiguration( "configuration" );
274         }
275         return mojoConfiguration;
276     }
277
278     public void setMojoConfiguration( PlexusConfiguration mojoConfiguration )
279     {
280         this.mojoConfiguration = mojoConfiguration;
281     }
282
283     public String JavaDoc getRole()
284     {
285         return Mojo.ROLE;
286     }
287
288     public String JavaDoc getRoleHint()
289     {
290         return getId();
291     }
292
293     public String JavaDoc getId()
294     {
295         return getPluginDescriptor().getId() + ":" + getGoal();
296     }
297
298     public String JavaDoc getFullGoalName()
299     {
300         return getPluginDescriptor().getGoalPrefix() + ":" + getGoal();
301     }
302
303     public String JavaDoc getComponentType()
304     {
305         return MAVEN_PLUGIN;
306     }
307
308     public PluginDescriptor getPluginDescriptor()
309     {
310         return pluginDescriptor;
311     }
312
313     public void setPluginDescriptor( PluginDescriptor pluginDescriptor )
314     {
315         this.pluginDescriptor = pluginDescriptor;
316     }
317
318     public boolean isInheritedByDefault()
319     {
320         return inheritedByDefault;
321     }
322
323     public void setInheritedByDefault( boolean inheritedByDefault )
324     {
325         this.inheritedByDefault = inheritedByDefault;
326     }
327
328     public boolean equals( Object JavaDoc object )
329     {
330         if ( this == object )
331         {
332             return true;
333         }
334
335         if ( object instanceof MojoDescriptor )
336         {
337             MojoDescriptor other = (MojoDescriptor) object;
338
339             if ( !compareObjects( getPluginDescriptor(), other.getPluginDescriptor() ) )
340             {
341                 return false;
342             }
343
344             if ( !compareObjects( getGoal(), other.getGoal() ) )
345             {
346                 return false;
347             }
348
349             return true;
350         }
351
352         return false;
353     }
354
355     private boolean compareObjects( Object JavaDoc first, Object JavaDoc second )
356     {
357         if ( ( first == null && second != null ) || ( first != null && second == null ) )
358         {
359             return false;
360         }
361
362         if ( !first.equals( second ) )
363         {
364             return false;
365         }
366
367         return true;
368     }
369
370     public int hashCode()
371     {
372         int result = 1;
373
374         String JavaDoc goal = getGoal();
375
376         if ( goal != null )
377         {
378             result += goal.hashCode();
379         }
380
381         PluginDescriptor pd = getPluginDescriptor();
382
383         if ( pd != null )
384         {
385             result -= pd.hashCode();
386         }
387
388         return result;
389     }
390
391     public String JavaDoc getExecuteLifecycle()
392     {
393         return executeLifecycle;
394     }
395
396     public void setExecuteLifecycle( String JavaDoc executeLifecycle )
397     {
398         this.executeLifecycle = executeLifecycle;
399     }
400
401     public void setAggregator( boolean aggregator )
402     {
403         this.aggregator = aggregator;
404     }
405
406     public boolean isAggregator()
407     {
408         return aggregator;
409     }
410
411     public boolean isDirectInvocationOnly()
412     {
413         return directInvocationOnly;
414     }
415
416     public void setDirectInvocationOnly( boolean directInvocationOnly )
417     {
418         this.directInvocationOnly = directInvocationOnly;
419     }
420
421     public boolean isRequiresReports()
422     {
423         return requiresReports;
424     }
425
426     public void setRequiresReports( boolean requiresReports )
427     {
428         this.requiresReports = requiresReports;
429     }
430
431     public void setExecuteGoal( String JavaDoc executeGoal )
432     {
433         this.executeGoal = executeGoal;
434     }
435
436     public String JavaDoc getExecuteGoal()
437     {
438         return executeGoal;
439     }
440 }
441
Popular Tags