Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
MojoDescriptor |
|
| 1.4313725490196079;1.431 |
1 | package org.apache.maven.plugin.descriptor; | |
2 | ||
3 | /* | |
4 | * Licensed to the Apache Software Foundation (ASF) under one | |
5 | * or more contributor license agreements. See the NOTICE file | |
6 | * distributed with this work for additional information | |
7 | * regarding copyright ownership. The ASF licenses this file | |
8 | * to you under the Apache License, Version 2.0 (the | |
9 | * "License"); you may not use this file except in compliance | |
10 | * with the License. You may obtain a copy of the License at | |
11 | * | |
12 | * http://www.apache.org/licenses/LICENSE-2.0 | |
13 | * | |
14 | * Unless required by applicable law or agreed to in writing, | |
15 | * software distributed under the License is distributed on an | |
16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
17 | * KIND, either express or implied. See the License for the | |
18 | * specific language governing permissions and limitations | |
19 | * under the License. | |
20 | */ | |
21 | ||
22 | import org.apache.maven.plugin.Mojo; | |
23 | import org.codehaus.plexus.component.repository.ComponentDescriptor; | |
24 | import org.codehaus.plexus.configuration.PlexusConfiguration; | |
25 | import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration; | |
26 | ||
27 | import java.util.HashMap; | |
28 | import java.util.Iterator; | |
29 | import java.util.LinkedList; | |
30 | import java.util.List; | |
31 | import java.util.Map; | |
32 | ||
33 | /** | |
34 | * The bean containing the Mojo descriptor. | |
35 | * <br/> | |
36 | * For more information about the usage tag, have a look to: | |
37 | * <a href="http://maven.apache.org/developers/mojo-api-specification.html">http://maven.apache.org/developers/mojo-api-specification.html</a> | |
38 | * | |
39 | * @todo is there a need for the delegation of MavenMojoDescriptor to this? | |
40 | * Why not just extend ComponentDescriptor here? | |
41 | * @version $Id: MojoDescriptor.java 640545 2008-03-24 19:50:56Z bentmann $ | |
42 | */ | |
43 | public class MojoDescriptor | |
44 | extends ComponentDescriptor | |
45 | implements Cloneable | |
46 | { | |
47 | /** The Plexus component type */ | |
48 | 0 | public static String MAVEN_PLUGIN = "maven-plugin"; |
49 | ||
50 | /** "once-per-session" execution strategy */ | |
51 | public static final String SINGLE_PASS_EXEC_STRATEGY = "once-per-session"; | |
52 | ||
53 | /** "always" execution strategy */ | |
54 | public static final String MULTI_PASS_EXEC_STRATEGY = "always"; | |
55 | ||
56 | private static final String DEFAULT_INSTANTIATION_STRATEGY = "per-lookup"; | |
57 | ||
58 | private static final String DEFAULT_LANGUAGE = "java"; | |
59 | ||
60 | private List parameters; | |
61 | ||
62 | private Map parameterMap; | |
63 | ||
64 | /** By default, the execution strategy is "once-per-session" */ | |
65 | 0 | private String executionStrategy = SINGLE_PASS_EXEC_STRATEGY; |
66 | ||
67 | /** The goal name of the Mojo */ | |
68 | private String goal; | |
69 | ||
70 | /** Reference the binded phase name of the Mojo */ | |
71 | private String phase; | |
72 | ||
73 | /** Specify the version when the Mojo was added to the API. Similar to Javadoc since. */ | |
74 | private String since; | |
75 | ||
76 | /** Reference the invocation phase of the Mojo */ | |
77 | private String executePhase; | |
78 | ||
79 | /** Reference the invocation goal of the Mojo */ | |
80 | private String executeGoal; | |
81 | ||
82 | /** Reference the invocation lifecycle of the Mojo */ | |
83 | private String executeLifecycle; | |
84 | ||
85 | /** Specify the version when the Mojo was deprecated to the API. Similar to Javadoc deprecated. */ | |
86 | private String deprecated; | |
87 | ||
88 | /** By default, no need to aggregate the Maven project and its child modules */ | |
89 | 0 | private boolean aggregator = false; |
90 | ||
91 | // ---------------------------------------------------------------------- | |
92 | // | |
93 | // ---------------------------------------------------------------------- | |
94 | ||
95 | /** Specify the required dependencies in a specified scope */ | |
96 | 0 | private String dependencyResolutionRequired = null; |
97 | ||
98 | /** By default, the Mojo needs a Maven project to be executed */ | |
99 | 0 | private boolean projectRequired = true; |
100 | ||
101 | /** By default, the Mojo is online */ | |
102 | 0 | private boolean onlineRequired = false; |
103 | ||
104 | /** Plugin configuration */ | |
105 | private PlexusConfiguration mojoConfiguration; | |
106 | ||
107 | /** Plugin descriptor */ | |
108 | private PluginDescriptor pluginDescriptor; | |
109 | ||
110 | /** By default, the Mojo is herited */ | |
111 | 0 | private boolean inheritedByDefault = true; |
112 | ||
113 | /** By default, the Mojo could not be invoke directly */ | |
114 | 0 | private boolean directInvocationOnly = false; |
115 | ||
116 | /** By default, the Mojo don't need reports to run */ | |
117 | 0 | private boolean requiresReports = false; |
118 | ||
119 | /** | |
120 | * Default constructor. | |
121 | */ | |
122 | public MojoDescriptor() | |
123 | 0 | { |
124 | 0 | setInstantiationStrategy( DEFAULT_INSTANTIATION_STRATEGY ); |
125 | 0 | setComponentFactory( DEFAULT_LANGUAGE ); |
126 | 0 | } |
127 | ||
128 | // ---------------------------------------------------------------------- | |
129 | // | |
130 | // ---------------------------------------------------------------------- | |
131 | ||
132 | /** | |
133 | * @return the language of this Mojo, i.e. <code>java</code> | |
134 | */ | |
135 | public String getLanguage() | |
136 | { | |
137 | 0 | return getComponentFactory(); |
138 | } | |
139 | ||
140 | /** | |
141 | * @param language the new language | |
142 | */ | |
143 | public void setLanguage( String language ) | |
144 | { | |
145 | 0 | setComponentFactory( language ); |
146 | 0 | } |
147 | ||
148 | /** | |
149 | * @return <code>true</code> if the Mojo is deprecated, <code>false</code> otherwise. | |
150 | */ | |
151 | public String getDeprecated() | |
152 | { | |
153 | 0 | return deprecated; |
154 | } | |
155 | ||
156 | /** | |
157 | * @param deprecated <code>true</code> to deprecate the Mojo, <code>false</code> otherwise. | |
158 | */ | |
159 | public void setDeprecated( String deprecated ) | |
160 | { | |
161 | 0 | this.deprecated = deprecated; |
162 | 0 | } |
163 | ||
164 | /** | |
165 | * @return the list of parameters | |
166 | */ | |
167 | public List getParameters() | |
168 | { | |
169 | 0 | return parameters; |
170 | } | |
171 | ||
172 | /** | |
173 | * @param parameters the new list of parameters | |
174 | * @throws DuplicateParameterException if any | |
175 | */ | |
176 | public void setParameters( List parameters ) | |
177 | throws DuplicateParameterException | |
178 | { | |
179 | 0 | for ( Iterator it = parameters.iterator(); it.hasNext(); ) |
180 | { | |
181 | 0 | Parameter parameter = (Parameter) it.next(); |
182 | 0 | addParameter( parameter ); |
183 | 0 | } |
184 | 0 | } |
185 | ||
186 | /** | |
187 | * @param parameter add a new parameter | |
188 | * @throws DuplicateParameterException if any | |
189 | */ | |
190 | public void addParameter( Parameter parameter ) | |
191 | throws DuplicateParameterException | |
192 | { | |
193 | 0 | if ( parameters != null && parameters.contains( parameter ) ) |
194 | { | |
195 | 0 | throw new DuplicateParameterException( parameter.getName() + |
196 | " has been declared multiple times in mojo with goal: " + getGoal() + " (implementation: " + | |
197 | getImplementation() + ")" ); | |
198 | } | |
199 | ||
200 | 0 | if ( parameters == null ) |
201 | { | |
202 | 0 | parameters = new LinkedList(); |
203 | } | |
204 | ||
205 | 0 | parameters.add( parameter ); |
206 | 0 | } |
207 | ||
208 | /** | |
209 | * @return the list parameters as a Map | |
210 | */ | |
211 | public Map getParameterMap() | |
212 | { | |
213 | 0 | if ( parameterMap == null ) |
214 | { | |
215 | 0 | parameterMap = new HashMap(); |
216 | ||
217 | 0 | if ( parameters != null ) |
218 | { | |
219 | 0 | for ( Iterator iterator = parameters.iterator(); iterator.hasNext(); ) |
220 | { | |
221 | 0 | Parameter pd = (Parameter) iterator.next(); |
222 | ||
223 | 0 | parameterMap.put( pd.getName(), pd ); |
224 | 0 | } |
225 | } | |
226 | } | |
227 | ||
228 | 0 | return parameterMap; |
229 | } | |
230 | ||
231 | // ---------------------------------------------------------------------- | |
232 | // Dependency requirement | |
233 | // ---------------------------------------------------------------------- | |
234 | ||
235 | /** | |
236 | * @param requiresDependencyResolution the new required dependencies in a specified scope | |
237 | */ | |
238 | public void setDependencyResolutionRequired( String requiresDependencyResolution ) | |
239 | { | |
240 | 0 | this.dependencyResolutionRequired = requiresDependencyResolution; |
241 | 0 | } |
242 | ||
243 | /** | |
244 | * @return the required dependencies in a specified scope | |
245 | * @TODO the name is not intelligible | |
246 | */ | |
247 | public String isDependencyResolutionRequired() | |
248 | { | |
249 | 0 | return dependencyResolutionRequired; |
250 | } | |
251 | ||
252 | // ---------------------------------------------------------------------- | |
253 | // Project requirement | |
254 | // ---------------------------------------------------------------------- | |
255 | ||
256 | /** | |
257 | * @param requiresProject <code>true</code> if the Mojo needs a Maven project to be executed, <code>false</code> otherwise. | |
258 | */ | |
259 | public void setProjectRequired( boolean requiresProject ) | |
260 | { | |
261 | 0 | this.projectRequired = requiresProject; |
262 | 0 | } |
263 | ||
264 | /** | |
265 | * @return <code>true</code> if the Mojo needs a Maven project to be executed, <code>false</code> otherwise. | |
266 | */ | |
267 | public boolean isProjectRequired() | |
268 | { | |
269 | 0 | return projectRequired; |
270 | } | |
271 | ||
272 | // ---------------------------------------------------------------------- | |
273 | // Online vs. Offline requirement | |
274 | // ---------------------------------------------------------------------- | |
275 | ||
276 | /** | |
277 | * @param requiresOnline <code>true</code> if the Mojo is online, <code>false</code> otherwise. | |
278 | */ | |
279 | public void setOnlineRequired( boolean requiresOnline ) | |
280 | { | |
281 | 0 | this.onlineRequired = requiresOnline; |
282 | 0 | } |
283 | ||
284 | /** | |
285 | * @return <code>true</code> if the Mojo is online, <code>false</code> otherwise. | |
286 | */ | |
287 | // blech! this isn't even intelligible as a method name. provided for | |
288 | // consistency... | |
289 | public boolean isOnlineRequired() | |
290 | { | |
291 | 0 | return onlineRequired; |
292 | } | |
293 | ||
294 | /** | |
295 | * @return <code>true</code> if the Mojo is online, <code>false</code> otherwise. | |
296 | */ | |
297 | // more english-friendly method...keep the code clean! :) | |
298 | public boolean requiresOnline() | |
299 | { | |
300 | 0 | return onlineRequired; |
301 | } | |
302 | ||
303 | /** | |
304 | * @return the binded phase name of the Mojo | |
305 | */ | |
306 | public String getPhase() | |
307 | { | |
308 | 0 | return phase; |
309 | } | |
310 | ||
311 | /** | |
312 | * @param phase the new binded phase name of the Mojo | |
313 | */ | |
314 | public void setPhase( String phase ) | |
315 | { | |
316 | 0 | this.phase = phase; |
317 | 0 | } |
318 | ||
319 | /** | |
320 | * @return the version when the Mojo was added to the API | |
321 | */ | |
322 | public String getSince() | |
323 | { | |
324 | 0 | return since; |
325 | } | |
326 | ||
327 | /** | |
328 | * @param since the new version when the Mojo was added to the API | |
329 | */ | |
330 | public void setSince( String since ) | |
331 | { | |
332 | 0 | this.since = since; |
333 | 0 | } |
334 | ||
335 | /** | |
336 | * @return The goal name of the Mojo | |
337 | */ | |
338 | public String getGoal() | |
339 | { | |
340 | 0 | return goal; |
341 | } | |
342 | ||
343 | /** | |
344 | * @param goal The new goal name of the Mojo | |
345 | */ | |
346 | public void setGoal( String goal ) | |
347 | { | |
348 | 0 | this.goal = goal; |
349 | 0 | } |
350 | ||
351 | /** | |
352 | * @return the invocation phase of the Mojo | |
353 | */ | |
354 | public String getExecutePhase() | |
355 | { | |
356 | 0 | return executePhase; |
357 | } | |
358 | ||
359 | /** | |
360 | * @param executePhase the new invocation phase of the Mojo | |
361 | */ | |
362 | public void setExecutePhase( String executePhase ) | |
363 | { | |
364 | 0 | this.executePhase = executePhase; |
365 | 0 | } |
366 | ||
367 | /** | |
368 | * @return <code>true</code> if the Mojo uses <code>always</code> for the <code>executionStrategy</code> | |
369 | */ | |
370 | public boolean alwaysExecute() | |
371 | { | |
372 | 0 | return MULTI_PASS_EXEC_STRATEGY.equals( executionStrategy ); |
373 | } | |
374 | ||
375 | /** | |
376 | * @return the execution strategy | |
377 | */ | |
378 | public String getExecutionStrategy() | |
379 | { | |
380 | 0 | return executionStrategy; |
381 | } | |
382 | ||
383 | /** | |
384 | * @param executionStrategy the new execution strategy | |
385 | */ | |
386 | public void setExecutionStrategy( String executionStrategy ) | |
387 | { | |
388 | 0 | this.executionStrategy = executionStrategy; |
389 | 0 | } |
390 | ||
391 | /** | |
392 | * @return the mojo configuration | |
393 | */ | |
394 | public PlexusConfiguration getMojoConfiguration() | |
395 | { | |
396 | 0 | if ( mojoConfiguration == null ) |
397 | { | |
398 | 0 | mojoConfiguration = new XmlPlexusConfiguration( "configuration" ); |
399 | } | |
400 | 0 | return mojoConfiguration; |
401 | } | |
402 | ||
403 | /** | |
404 | * @param mojoConfiguration a new mojo configuration | |
405 | */ | |
406 | public void setMojoConfiguration( PlexusConfiguration mojoConfiguration ) | |
407 | { | |
408 | 0 | this.mojoConfiguration = mojoConfiguration; |
409 | 0 | } |
410 | ||
411 | /** {@inheritDoc} */ | |
412 | public String getRole() | |
413 | { | |
414 | 0 | return Mojo.ROLE; |
415 | } | |
416 | ||
417 | /** {@inheritDoc} */ | |
418 | public String getRoleHint() | |
419 | { | |
420 | 0 | return getId(); |
421 | } | |
422 | ||
423 | /** | |
424 | * @return the id of the mojo, based on the goal name | |
425 | */ | |
426 | public String getId() | |
427 | { | |
428 | 0 | return getPluginDescriptor().getId() + ":" + getGoal(); |
429 | } | |
430 | ||
431 | /** | |
432 | * @return the full goal name | |
433 | * @see PluginDescriptor#getGoalPrefix() | |
434 | * @see #getGoal() | |
435 | */ | |
436 | public String getFullGoalName() | |
437 | { | |
438 | 0 | return getPluginDescriptor().getGoalPrefix() + ":" + getGoal(); |
439 | } | |
440 | ||
441 | /** {@inheritDoc} */ | |
442 | public String getComponentType() | |
443 | { | |
444 | 0 | return MAVEN_PLUGIN; |
445 | } | |
446 | ||
447 | /** | |
448 | * @return the plugin descriptor | |
449 | */ | |
450 | public PluginDescriptor getPluginDescriptor() | |
451 | { | |
452 | 0 | return pluginDescriptor; |
453 | } | |
454 | ||
455 | /** | |
456 | * @param pluginDescriptor the new plugin descriptor | |
457 | */ | |
458 | public void setPluginDescriptor( PluginDescriptor pluginDescriptor ) | |
459 | { | |
460 | 0 | this.pluginDescriptor = pluginDescriptor; |
461 | 0 | } |
462 | ||
463 | /** | |
464 | * @return <code>true</code> if the Mojo is herited, <code>false</code> otherwise. | |
465 | */ | |
466 | public boolean isInheritedByDefault() | |
467 | { | |
468 | 0 | return inheritedByDefault; |
469 | } | |
470 | ||
471 | /** | |
472 | * @param inheritedByDefault <code>true</code> if the Mojo is herited, <code>false</code> otherwise. | |
473 | */ | |
474 | public void setInheritedByDefault( boolean inheritedByDefault ) | |
475 | { | |
476 | 0 | this.inheritedByDefault = inheritedByDefault; |
477 | 0 | } |
478 | ||
479 | /** {@inheritDoc} */ | |
480 | public boolean equals( Object object ) | |
481 | { | |
482 | 0 | if ( this == object ) |
483 | { | |
484 | 0 | return true; |
485 | } | |
486 | ||
487 | 0 | if ( object instanceof MojoDescriptor ) |
488 | { | |
489 | 0 | MojoDescriptor other = (MojoDescriptor) object; |
490 | ||
491 | 0 | if ( !compareObjects( getPluginDescriptor(), other.getPluginDescriptor() ) ) |
492 | { | |
493 | 0 | return false; |
494 | } | |
495 | ||
496 | 0 | if ( !compareObjects( getGoal(), other.getGoal() ) ) |
497 | { | |
498 | 0 | return false; |
499 | } | |
500 | ||
501 | 0 | return true; |
502 | } | |
503 | ||
504 | 0 | return false; |
505 | } | |
506 | ||
507 | private boolean compareObjects( Object first, Object second ) | |
508 | { | |
509 | 0 | if ( ( first == null && second != null ) || ( first != null && second == null ) ) |
510 | { | |
511 | 0 | return false; |
512 | } | |
513 | ||
514 | 0 | if ( !first.equals( second ) ) |
515 | { | |
516 | 0 | return false; |
517 | } | |
518 | ||
519 | 0 | return true; |
520 | } | |
521 | ||
522 | /** {@inheritDoc} */ | |
523 | public int hashCode() | |
524 | { | |
525 | 0 | int result = 1; |
526 | ||
527 | 0 | String goal = getGoal(); |
528 | ||
529 | 0 | if ( goal != null ) |
530 | { | |
531 | 0 | result += goal.hashCode(); |
532 | } | |
533 | ||
534 | 0 | PluginDescriptor pd = getPluginDescriptor(); |
535 | ||
536 | 0 | if ( pd != null ) |
537 | { | |
538 | 0 | result -= pd.hashCode(); |
539 | } | |
540 | ||
541 | 0 | return result; |
542 | } | |
543 | ||
544 | /** | |
545 | * @return the invocation lifecycle of the Mojo | |
546 | */ | |
547 | public String getExecuteLifecycle() | |
548 | { | |
549 | 0 | return executeLifecycle; |
550 | } | |
551 | ||
552 | /** | |
553 | * @param executeLifecycle the new invocation lifecycle of the Mojo | |
554 | */ | |
555 | public void setExecuteLifecycle( String executeLifecycle ) | |
556 | { | |
557 | 0 | this.executeLifecycle = executeLifecycle; |
558 | 0 | } |
559 | ||
560 | /** | |
561 | * @param aggregator <code>true</code> if the Mojo uses the Maven project and its child modules, <code>false</code> otherwise. | |
562 | */ | |
563 | public void setAggregator( boolean aggregator ) | |
564 | { | |
565 | 0 | this.aggregator = aggregator; |
566 | 0 | } |
567 | ||
568 | /** | |
569 | * @return <code>true</code> if the Mojo uses the Maven project and its child modules, <code>false</code> otherwise. | |
570 | */ | |
571 | public boolean isAggregator() | |
572 | { | |
573 | 0 | return aggregator; |
574 | } | |
575 | ||
576 | /** | |
577 | * @return <code>true</code> if the Mojo could not be invoke directly, <code>false</code> otherwise. | |
578 | */ | |
579 | public boolean isDirectInvocationOnly() | |
580 | { | |
581 | 0 | return directInvocationOnly; |
582 | } | |
583 | ||
584 | /** | |
585 | * @param directInvocationOnly <code>true</code> if the Mojo could not be invoke directly, <code>false</code> otherwise. | |
586 | */ | |
587 | public void setDirectInvocationOnly( boolean directInvocationOnly ) | |
588 | { | |
589 | 0 | this.directInvocationOnly = directInvocationOnly; |
590 | 0 | } |
591 | ||
592 | /** | |
593 | * @return <code>true</code> if the Mojo needs reports to run, <code>false</code> otherwise. | |
594 | */ | |
595 | public boolean isRequiresReports() | |
596 | { | |
597 | 0 | return requiresReports; |
598 | } | |
599 | ||
600 | /** | |
601 | * @param requiresReports <code>true</code> if the Mojo needs reports to run, <code>false</code> otherwise. | |
602 | */ | |
603 | public void setRequiresReports( boolean requiresReports ) | |
604 | { | |
605 | 0 | this.requiresReports = requiresReports; |
606 | 0 | } |
607 | ||
608 | /** | |
609 | * @param executeGoal the new invocation goal of the Mojo | |
610 | */ | |
611 | public void setExecuteGoal( String executeGoal ) | |
612 | { | |
613 | 0 | this.executeGoal = executeGoal; |
614 | 0 | } |
615 | ||
616 | /** | |
617 | * @return the invocation goal of the Mojo | |
618 | */ | |
619 | public String getExecuteGoal() | |
620 | { | |
621 | 0 | return executeGoal; |
622 | } | |
623 | } |