1 package org.apache.maven.plugins.help;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.IOException;
23 import java.lang.reflect.InvocationTargetException;
24 import java.lang.reflect.Method;
25 import java.util.Collections;
26 import java.util.Comparator;
27 import java.util.Iterator;
28 import java.util.List;
29 import java.util.StringTokenizer;
30
31 import org.apache.maven.artifact.Artifact;
32 import org.apache.maven.artifact.factory.ArtifactFactory;
33 import org.apache.maven.artifact.repository.ArtifactRepository;
34 import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
35 import org.apache.maven.artifact.resolver.ArtifactResolutionException;
36 import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
37 import org.apache.maven.artifact.versioning.VersionRange;
38 import org.apache.maven.execution.MavenSession;
39 import org.apache.maven.lifecycle.DefaultLifecycleExecutor;
40 import org.apache.maven.lifecycle.Lifecycle;
41 import org.apache.maven.lifecycle.LifecycleExecutionException;
42 import org.apache.maven.lifecycle.LifecycleExecutor;
43 import org.apache.maven.lifecycle.mapping.LifecycleMapping;
44 import org.apache.maven.model.Plugin;
45 import org.apache.maven.plugin.InvalidPluginException;
46 import org.apache.maven.plugin.MojoExecutionException;
47 import org.apache.maven.plugin.MojoFailureException;
48 import org.apache.maven.plugin.PluginManager;
49 import org.apache.maven.plugin.PluginManagerException;
50 import org.apache.maven.plugin.PluginNotFoundException;
51 import org.apache.maven.plugin.descriptor.MojoDescriptor;
52 import org.apache.maven.plugin.descriptor.Parameter;
53 import org.apache.maven.plugin.descriptor.PluginDescriptor;
54 import org.apache.maven.plugin.version.PluginVersionNotFoundException;
55 import org.apache.maven.plugin.version.PluginVersionResolutionException;
56 import org.apache.maven.project.MavenProject;
57 import org.apache.maven.project.MavenProjectBuilder;
58 import org.apache.maven.project.ProjectBuildingException;
59 import org.apache.maven.settings.Settings;
60 import org.apache.maven.tools.plugin.util.PluginUtils;
61 import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
62 import org.codehaus.plexus.util.StringUtils;
63
64
65
66
67
68
69
70
71
72
73
74 public class DescribeMojo
75 extends AbstractHelpMojo
76 {
77
78 private static final int INDENT_SIZE = 2;
79
80
81 private static final String UNKNOWN = "Unknown";
82
83
84 private static final String NOT_DEFINED = "Not defined";
85
86
87 private static final String NO_REASON = "No reason given";
88
89
90
91
92
93
94
95
96
97
98
99 private ArtifactFactory artifactFactory;
100
101
102
103
104
105
106 private PluginManager pluginManager;
107
108
109
110
111
112
113
114
115 private MavenProjectBuilder projectBuilder;
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130 private MavenProject project;
131
132
133
134
135
136
137
138
139
140 private Settings settings;
141
142
143
144
145
146
147
148
149
150 private MavenSession session;
151
152
153
154
155
156
157
158
159
160 private ArtifactRepository localRepository;
161
162
163
164
165
166
167
168
169
170 private List remoteRepositories;
171
172
173
174
175
176
177
178
179
180
181
182
183 private String plugin;
184
185
186
187
188
189
190
191
192 private String groupId;
193
194
195
196
197
198
199
200
201 private String artifactId;
202
203
204
205
206
207
208
209
210 private String version;
211
212
213
214
215
216
217
218
219
220 private String goal;
221
222
223
224
225
226
227
228 private boolean detail;
229
230
231
232
233
234
235
236 private boolean medium;
237
238
239
240
241
242
243
244 private boolean minimal;
245
246
247
248
249
250
251
252
253
254 private String cmd;
255
256
257
258
259
260
261 public void execute()
262 throws MojoExecutionException, MojoFailureException
263 {
264 validateParameters();
265
266 if ( project == null )
267 {
268 try
269 {
270 project = projectBuilder.buildStandaloneSuperProject( localRepository );
271 }
272 catch ( ProjectBuildingException e )
273 {
274 throw new MojoExecutionException( "Error while retrieving the super-project.", e );
275 }
276 }
277
278 StringBuffer descriptionBuffer = new StringBuffer();
279
280 boolean describePlugin = true;
281 if ( StringUtils.isNotEmpty( cmd ) )
282 {
283 describePlugin = describeCommand( descriptionBuffer );
284 }
285
286 if ( describePlugin )
287 {
288 PluginInfo pi = new PluginInfo();
289
290 parsePluginLookupInfo( pi );
291
292 PluginDescriptor descriptor = lookupPluginDescriptor( pi );
293
294 if ( StringUtils.isNotEmpty( goal ) )
295 {
296 MojoDescriptor mojo = descriptor.getMojo( goal );
297 if ( mojo == null )
298 {
299 throw new MojoFailureException(
300 "The mojo '" + goal + "' does not exist in the plugin '" + pi.getPrefix() + "'" );
301 }
302
303 describeMojo( mojo, descriptionBuffer );
304 }
305 else
306 {
307 describePlugin( descriptor, descriptionBuffer );
308 }
309 }
310
311 writeDescription( descriptionBuffer );
312 }
313
314
315
316
317
318
319
320
321 private void validateParameters()
322 {
323
324 if ( goal == null && session.getExecutionProperties().get( "mojo" ) != null )
325 {
326 goal = session.getExecutionProperties().getProperty( "mojo" );
327 }
328
329 if ( !detail && session.getExecutionProperties().get( "full" ) != null )
330 {
331 String full = session.getExecutionProperties().getProperty( "full" );
332 detail = new Boolean( full ).booleanValue();
333 }
334
335 if ( detail || minimal )
336 {
337 medium = false;
338 }
339 }
340
341
342
343
344
345
346
347 private void writeDescription( StringBuffer descriptionBuffer )
348 throws MojoExecutionException
349 {
350 if ( output != null )
351 {
352 try
353 {
354 writeFile( output, descriptionBuffer );
355 }
356 catch ( IOException e )
357 {
358 throw new MojoExecutionException( "Cannot write plugin/mojo description to output: " + output, e );
359 }
360
361 if ( getLog().isInfoEnabled() )
362 {
363 getLog().info( "Wrote descriptions to: " + output );
364 }
365 }
366 else
367 {
368 if ( getLog().isInfoEnabled() )
369 {
370 getLog().info( descriptionBuffer.toString() );
371 }
372 }
373 }
374
375
376
377
378
379
380
381
382
383 private PluginDescriptor lookupPluginDescriptor( PluginInfo pi )
384 throws MojoExecutionException, MojoFailureException
385 {
386 PluginDescriptor descriptor = null;
387
388 Plugin forLookup = null;
389
390 if ( StringUtils.isNotEmpty( pi.getPrefix() ) )
391 {
392 descriptor = pluginManager.getPluginDescriptorForPrefix( pi.getPrefix() );
393 if ( descriptor == null )
394 {
395 forLookup = pluginManager.getPluginDefinitionForPrefix( pi.getPrefix(), session, project );
396 }
397 }
398 else if ( StringUtils.isNotEmpty( pi.getGroupId() ) && StringUtils.isNotEmpty( pi.getArtifactId() ) )
399 {
400 forLookup = new Plugin();
401
402 forLookup.setGroupId( pi.getGroupId() );
403 forLookup.setArtifactId( pi.getArtifactId() );
404
405 if ( StringUtils.isNotEmpty( pi.getVersion() ) )
406 {
407 forLookup.setVersion( pi.getVersion() );
408 }
409 }
410 else
411 {
412 StringBuffer msg = new StringBuffer();
413 msg.append( "You must specify either: both 'groupId' and 'artifactId' parameters OR a 'plugin' parameter"
414 + " OR a 'cmd' parameter. For instance:\n" );
415 msg.append( " # mvn help:describe -Dcmd=install\n" );
416 msg.append( "or\n" );
417 msg.append( " # mvn help:describe -Dcmd=help:describe\n" );
418 msg.append( "or\n" );
419 msg.append( " # mvn help:describe -Dplugin=org.apache.maven.plugins:maven-help-plugin\n" );
420 msg.append( "or\n" );
421 msg.append( " # mvn help:describe -DgroupId=org.apache.maven.plugins -DartifactId=maven-help-plugin\n\n" );
422 msg.append( "Try 'mvn help:help -Ddetail=true' for more information." );
423
424 throw new MojoFailureException( msg.toString() );
425 }
426
427 if ( descriptor == null && forLookup != null )
428 {
429 try
430 {
431 descriptor = pluginManager.verifyPlugin( forLookup, project, settings, localRepository );
432 }
433 catch ( ArtifactResolutionException e )
434 {
435 throw new MojoExecutionException( "Error retrieving plugin descriptor for:\n\ngroupId: '"
436 + groupId + "'\nartifactId: '" + artifactId + "'\nversion: '" + version + "'\n\n", e );
437 }
438 catch ( PluginManagerException e )
439 {
440 throw new MojoExecutionException( "Error retrieving plugin descriptor for:\n\ngroupId: '"
441 + groupId + "'\nartifactId: '" + artifactId + "'\nversion: '" + version + "'\n\n", e );
442 }
443 catch ( PluginVersionResolutionException e )
444 {
445 throw new MojoExecutionException( "Error retrieving plugin descriptor for:\n\ngroupId: '"
446 + groupId + "'\nartifactId: '" + artifactId + "'\nversion: '" + version + "'\n\n", e );
447 }
448 catch ( ArtifactNotFoundException e )
449 {
450 throw new MojoExecutionException( "Plugin dependency does not exist: " + e.getMessage(), e );
451 }
452 catch ( InvalidVersionSpecificationException e )
453 {
454 throw new MojoExecutionException( "Error retrieving plugin descriptor for:\n\ngroupId: '"
455 + groupId + "'\nartifactId: '" + artifactId + "'\nversion: '" + version + "'\n\n", e );
456 }
457 catch ( InvalidPluginException e )
458 {
459 throw new MojoExecutionException( "Error retrieving plugin descriptor for:\n\ngroupId: '"
460 + groupId + "'\nartifactId: '" + artifactId + "'\nversion: '" + version + "'\n\n", e );
461 }
462 catch ( PluginNotFoundException e )
463 {
464 if ( getLog().isDebugEnabled() )
465 {
466 getLog().debug( "Unable to find plugin", e );
467 }
468 throw new MojoFailureException( "Plugin does not exist: " + e.getMessage() );
469 }
470 catch ( PluginVersionNotFoundException e )
471 {
472 if ( getLog().isDebugEnabled() )
473 {
474 getLog().debug( "Unable to find plugin version", e );
475 }
476 throw new MojoFailureException( e.getMessage() );
477 }
478 }
479
480 if ( descriptor == null )
481 {
482 throw new MojoFailureException( "Plugin could not be found. If you believe it is correct,"
483 + " check your pluginGroups setting, and run with -U to update the remote configuration" );
484 }
485
486 return descriptor;
487 }
488
489
490
491
492
493
494
495
496 private void parsePluginLookupInfo( PluginInfo pi )
497 throws MojoFailureException
498 {
499 if ( StringUtils.isNotEmpty( plugin ) )
500 {
501 if ( plugin.indexOf( ":" ) > -1 )
502 {
503 String[] pluginParts = plugin.split( ":" );
504
505 switch ( pluginParts.length )
506 {
507 case ( 1 ):
508 pi.setPrefix( pluginParts[0] );
509 break;
510 case ( 2 ):
511 pi.setGroupId( pluginParts[0] );
512 pi.setArtifactId( pluginParts[1] );
513 break;
514 case ( 3 ):
515 pi.setGroupId( pluginParts[0] );
516 pi.setArtifactId( pluginParts[1] );
517 pi.setVersion( pluginParts[2] );
518 break;
519 default:
520 throw new MojoFailureException( "plugin parameter must be a plugin prefix,"
521 + " or conform to: 'groupId:artifactId[:version]'." );
522 }
523 }
524 else
525 {
526 pi.setPrefix( plugin );
527 }
528 }
529 else
530 {
531 pi.setGroupId( groupId );
532 pi.setArtifactId( artifactId );
533 pi.setVersion( version );
534 }
535 }
536
537
538
539
540
541
542
543
544
545 private void describePlugin( PluginDescriptor pd, StringBuffer buffer )
546 throws MojoFailureException, MojoExecutionException
547 {
548 append( buffer, pd.getId(), 0 );
549 buffer.append( "\n" );
550
551 String name = pd.getName();
552 if ( name == null )
553 {
554
555
556 try
557 {
558 Artifact artifact =
559 artifactFactory.createPluginArtifact( pd.getGroupId(), pd.getArtifactId(),
560 VersionRange.createFromVersion( pd.getVersion() ) );
561 MavenProject pluginProject =
562 projectBuilder.buildFromRepository( artifact, remoteRepositories, localRepository );
563
564 name = pluginProject.getName();
565 }
566 catch ( ProjectBuildingException e )
567 {
568
569 name = pd.getId();
570 }
571 }
572 append( buffer, "Name", name, 0 );
573 appendAsParagraph( buffer, "Description", toDescription( pd.getDescription() ), 0 );
574 append( buffer, "Group Id", pd.getGroupId(), 0 );
575 append( buffer, "Artifact Id", pd.getArtifactId(), 0 );
576 append( buffer, "Version", pd.getVersion(), 0 );
577 append( buffer, "Goal Prefix", pd.getGoalPrefix(), 0 );
578 buffer.append( "\n" );
579
580 List mojos = pd.getMojos();
581
582 if ( mojos == null )
583 {
584 append( buffer, "This plugin has no goals.", 0 );
585 return;
586 }
587
588 if ( ( detail || medium ) && !minimal )
589 {
590 append( buffer, "This plugin has " + pd.getMojos().size() + " goal"
591 + ( pd.getMojos().size() > 1 ? "s" : "" ) + ":", 0 );
592 buffer.append( "\n" );
593
594 PluginUtils.sortMojos( mojos );
595
596 for ( Iterator it = mojos.iterator(); it.hasNext(); )
597 {
598 MojoDescriptor md = (MojoDescriptor) it.next();
599
600 if ( detail )
601 {
602 describeMojoGuts( md, buffer, true );
603 }
604 else
605 {
606 describeMojoGuts( md, buffer, false );
607 }
608
609 buffer.append( "\n" );
610 }
611 }
612
613 if ( !detail )
614 {
615 buffer.append( "For more information, run 'mvn help:describe [...] -Ddetail'" );
616 buffer.append( "\n" );
617 }
618 }
619
620
621
622
623
624
625
626
627
628 private void describeMojo( MojoDescriptor md, StringBuffer buffer )
629 throws MojoFailureException, MojoExecutionException
630 {
631 buffer.append( "Mojo: '" ).append( md.getFullGoalName() ).append( "'" );
632 buffer.append( '\n' );
633
634 describeMojoGuts( md, buffer, detail );
635 buffer.append( "\n" );
636
637 if ( !detail )
638 {
639 buffer.append( "For more information, run 'mvn help:describe [...] -Ddetail'" );
640 buffer.append( "\n" );
641 }
642 }
643
644
645
646
647
648
649
650
651
652
653 private void describeMojoGuts( MojoDescriptor md, StringBuffer buffer, boolean fullDescription )
654 throws MojoFailureException, MojoExecutionException
655 {
656 append( buffer, md.getFullGoalName(), 0 );
657
658
659 appendAsParagraph( buffer, "Description", toDescription( md.getDescription() ), 1 );
660
661 String deprecation = md.getDeprecated();
662 if ( deprecation != null && deprecation.length() <= 0 )
663 {
664 deprecation = NO_REASON;
665 }
666
667 if ( StringUtils.isNotEmpty( deprecation ) )
668 {
669 append( buffer, "Deprecated. " + deprecation, 1 );
670 }
671
672 if ( !fullDescription )
673 {
674 return;
675 }
676
677 append( buffer, "Implementation", md.getImplementation(), 1 );
678 append( buffer, "Language", md.getLanguage(), 1 );
679
680 String phase = md.getPhase();
681 if ( StringUtils.isNotEmpty( phase ) )
682 {
683 append( buffer, "Bound to phase", phase, 1 );
684 }
685
686 String eGoal = md.getExecuteGoal();
687 String eLife = md.getExecuteLifecycle();
688 String ePhase = md.getExecutePhase();
689
690 if ( StringUtils.isNotEmpty( eGoal ) || StringUtils.isNotEmpty( ePhase ) )
691 {
692 append( buffer, "Before this mojo executes, it will call:", 1 );
693
694 if ( StringUtils.isNotEmpty( eGoal ) )
695 {
696 append( buffer, "Single mojo", "'" + eGoal + "'", 2 );
697 }
698
699 if ( StringUtils.isNotEmpty( ePhase ) )
700 {
701 String s = "Phase: '" + ePhase + "'";
702
703 if ( StringUtils.isNotEmpty( eLife ) )
704 {
705 s += " in Lifecycle Overlay: '" + eLife + "'";
706 }
707
708 append( buffer, s, 2 );
709 }
710 }
711
712 buffer.append( "\n" );
713
714 describeMojoParameters( md, buffer );
715 }
716
717
718
719
720
721
722
723
724
725 private void describeMojoParameters( MojoDescriptor md, StringBuffer buffer )
726 throws MojoFailureException, MojoExecutionException
727 {
728 List params = md.getParameters();
729
730 if ( params == null || params.isEmpty() )
731 {
732 append( buffer, "This mojo doesn't use any parameters.", 1 );
733 return;
734 }
735
736
737 Collections.sort( params, new Comparator()
738 {
739
740 public int compare( Object o1, Object o2 )
741 {
742 Parameter parameter1 = (Parameter) o1;
743 Parameter parameter2 = (Parameter) o2;
744
745 return parameter1.getName().compareToIgnoreCase( parameter2.getName() );
746 }
747 } );
748
749 append( buffer, "Available parameters:", 1 );
750
751
752 for ( Iterator it = params.iterator(); it.hasNext(); )
753 {
754 Parameter parameter = (Parameter) it.next();
755 if ( !parameter.isEditable() )
756 {
757 continue;
758 }
759
760 buffer.append( "\n" );
761
762
763 String defaultVal = parameter.getDefaultValue();
764 if ( defaultVal == null )
765 {
766
767 defaultVal =
768 md.getMojoConfiguration().getChild( parameter.getName() ).getAttribute( "default-value", null );
769 }
770
771 if ( StringUtils.isNotEmpty( defaultVal ) )
772 {
773 defaultVal = " (Default: " + defaultVal + ")";
774 }
775 else
776 {
777 defaultVal = "";
778 }
779 append( buffer, parameter.getName() + defaultVal, 2 );
780
781 String expression = parameter.getExpression();
782 if ( StringUtils.isNotEmpty( expression ) )
783 {
784 append( buffer, "Expression", expression, 3 );
785 }
786
787 append( buffer, toDescription( parameter.getDescription() ), 3 );
788
789 String deprecation = parameter.getDeprecated();
790 if ( deprecation != null && deprecation.length() <= 0 )
791 {
792 deprecation = NO_REASON;
793 }
794
795 if ( StringUtils.isNotEmpty( deprecation ) )
796 {
797 append( buffer, "Deprecated. " + deprecation, 3 );
798 }
799 }
800 }
801
802
803
804
805
806
807
808
809
810 private boolean describeCommand( StringBuffer descriptionBuffer )
811 throws MojoFailureException, MojoExecutionException
812 {
813 if ( cmd.indexOf( ":" ) == -1 )
814 {
815
816 try
817 {
818 DefaultLifecycleExecutor lifecycleExecutor =
819 (DefaultLifecycleExecutor) session.lookup( LifecycleExecutor.ROLE );
820
821 Lifecycle lifecycle = (Lifecycle) lifecycleExecutor.getPhaseToLifecycleMap().get( cmd );
822 if ( lifecycle == null )
823 {
824 throw new MojoExecutionException( "The given phase '" + cmd + "' is an unknown phase." );
825 }
826
827 LifecycleMapping lifecycleMapping =
828 (LifecycleMapping) session.lookup( LifecycleMapping.ROLE, project.getPackaging() );
829 if ( lifecycle.getDefaultPhases() == null )
830 {
831 descriptionBuffer.append( "'" + cmd + "' is a phase corresponding to this plugin:\n" );
832 for ( Iterator it = lifecycle.getPhases().iterator(); it.hasNext(); )
833 {
834 String key = (String) it.next();
835
836 if ( !key.equals( cmd ) )
837 {
838 continue;
839 }
840
841 if ( lifecycleMapping.getPhases( "default" ).get( key ) != null )
842 {
843 descriptionBuffer.append( lifecycleMapping.getPhases( "default" ).get( key ) );
844 descriptionBuffer.append( "\n" );
845 }
846 }
847
848 descriptionBuffer.append( "\n" );
849 descriptionBuffer.append( "It is a part of the lifecycle for the POM packaging '"
850 + project.getPackaging() + "'. This lifecycle includes the following phases:" );
851 descriptionBuffer.append( "\n" );
852 for ( Iterator it = lifecycle.getPhases().iterator(); it.hasNext(); )
853 {
854 String key = (String) it.next();
855
856 descriptionBuffer.append( "* " + key + ": " );
857 String value = (String) lifecycleMapping.getPhases( "default" ).get( key );
858 if ( StringUtils.isNotEmpty( value ) )
859 {
860 for ( StringTokenizer tok = new StringTokenizer( value, "," ); tok.hasMoreTokens(); )
861 {
862 descriptionBuffer.append( tok.nextToken().trim() );
863
864 if ( !tok.hasMoreTokens() )
865 {
866 descriptionBuffer.append( "\n" );
867 }
868 else
869 {
870 descriptionBuffer.append( ", " );
871 }
872 }
873 }
874 else
875 {
876 descriptionBuffer.append( NOT_DEFINED ).append( "\n" );
877 }
878 }
879 }
880 else
881 {
882 descriptionBuffer.append( "'" + cmd + "' is a lifecycle with the following phases: " );
883 descriptionBuffer.append( "\n" );
884
885 for ( Iterator it = lifecycle.getPhases().iterator(); it.hasNext(); )
886 {
887 String key = (String) it.next();
888
889 descriptionBuffer.append( "* " + key + ": " );
890 if ( lifecycle.getDefaultPhases().get( key ) != null )
891 {
892 descriptionBuffer.append( lifecycle.getDefaultPhases().get( key ) ).append( "\n" );
893 }
894 else
895 {
896 descriptionBuffer.append( NOT_DEFINED ).append( "\n" );
897 }
898 }
899 }
900 }
901 catch ( ComponentLookupException e )
902 {
903 throw new MojoFailureException( "ComponentLookupException: " + e.getMessage() );
904 }
905 catch ( LifecycleExecutionException e )
906 {
907 throw new MojoFailureException( "LifecycleExecutionException: " + e.getMessage() );
908 }
909
910 return false;
911 }
912
913
914 MojoDescriptor mojoDescriptor = HelpUtil.getMojoDescriptor( cmd, session, project, cmd, true, false );
915
916 descriptionBuffer.append( "'" + cmd + "' is a plugin goal (aka mojo)" ).append( ".\n" );
917 plugin = mojoDescriptor.getPluginDescriptor().getId();
918 goal = mojoDescriptor.getGoal();
919
920 return true;
921 }
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936 private static List toLines( String text, int indent, int indentSize, int lineLength )
937 throws MojoFailureException, MojoExecutionException
938 {
939 try
940 {
941 Method m =
942 HelpMojo.class.getDeclaredMethod( "toLines", new Class[] { String.class, Integer.TYPE,
943 Integer.TYPE, Integer.TYPE } );
944 m.setAccessible( true );
945 List output =
946 (List) m.invoke( HelpMojo.class, new Object[] { text, new Integer( indent ),
947 new Integer( indentSize ), new Integer( lineLength ) } );
948
949 if ( output == null )
950 {
951 throw new MojoExecutionException( "No output was specified." );
952 }
953
954 return output;
955 }
956 catch ( SecurityException e )
957 {
958 throw new MojoFailureException( "SecurityException: " + e.getMessage() );
959 }
960 catch ( IllegalArgumentException e )
961 {
962 throw new MojoFailureException( "IllegalArgumentException: " + e.getMessage() );
963 }
964 catch ( NoSuchMethodException e )
965 {
966 throw new MojoFailureException( "NoSuchMethodException: " + e.getMessage() );
967 }
968 catch ( IllegalAccessException e )
969 {
970 throw new MojoFailureException( "IllegalAccessException: " + e.getMessage() );
971 }
972 catch ( InvocationTargetException e )
973 {
974 Throwable cause = e.getCause();
975
976 if ( cause instanceof NegativeArraySizeException )
977 {
978 throw new MojoFailureException( "NegativeArraySizeException: " + cause.getMessage() );
979 }
980
981 throw new MojoFailureException( "InvocationTargetException: " + e.getMessage() );
982 }
983 }
984
985
986
987
988
989
990
991
992
993
994
995
996 private static void append( StringBuffer sb, String description, int indent )
997 throws MojoFailureException, MojoExecutionException
998 {
999 if ( StringUtils.isEmpty( description ) )
1000 {
1001 sb.append( UNKNOWN ).append( '\n' );
1002 return;
1003 }
1004
1005 for ( Iterator it = toLines( description, indent, INDENT_SIZE, LINE_LENGTH ).iterator(); it.hasNext(); )
1006 {
1007 sb.append( it.next().toString() ).append( '\n' );
1008 }
1009 }
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023 private static void append( StringBuffer sb, String key, String value, int indent )
1024 throws MojoFailureException, MojoExecutionException
1025 {
1026 if ( StringUtils.isEmpty( key ) )
1027 {
1028 throw new IllegalArgumentException( "Key is required!" );
1029 }
1030
1031 if ( StringUtils.isEmpty( value ) )
1032 {
1033 value = UNKNOWN;
1034 }
1035
1036 String description = key + ": " + value;
1037 for ( Iterator it = toLines( description, indent, INDENT_SIZE, LINE_LENGTH ).iterator(); it.hasNext(); )
1038 {
1039 sb.append( it.next().toString() ).append( '\n' );
1040 }
1041 }
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056 private static void appendAsParagraph( StringBuffer sb, String key, String value, int indent )
1057 throws MojoFailureException, MojoExecutionException
1058 {
1059 if ( StringUtils.isEmpty( value ) )
1060 {
1061 value = UNKNOWN;
1062 }
1063
1064 String description;
1065 if ( key == null )
1066 {
1067 description = value;
1068 }
1069 else
1070 {
1071 description = key + ": " + value;
1072 }
1073
1074 List l1 = toLines( description, indent, INDENT_SIZE, LINE_LENGTH - INDENT_SIZE );
1075 List l2 = toLines( description, indent + 1, INDENT_SIZE, LINE_LENGTH );
1076 l2.set( 0, l1.get( 0 ) );
1077 for ( Iterator it = l2.iterator(); it.hasNext(); )
1078 {
1079 sb.append( it.next().toString() ).append( '\n' );
1080 }
1081 }
1082
1083
1084
1085
1086
1087
1088
1089 private static String toDescription( String description )
1090 {
1091 if ( StringUtils.isNotEmpty( description ) )
1092 {
1093 return PluginUtils.toText( description );
1094 }
1095
1096 return "(no description available)";
1097 }
1098
1099
1100
1101
1102 static class PluginInfo
1103 {
1104 private String prefix;
1105
1106 private String groupId;
1107
1108 private String artifactId;
1109
1110 private String version;
1111
1112 private String mojo;
1113
1114 private Plugin plugin;
1115
1116 private PluginDescriptor pluginDescriptor;
1117
1118
1119
1120
1121 public String getPrefix()
1122 {
1123 return prefix;
1124 }
1125
1126
1127
1128
1129 public void setPrefix( String prefix )
1130 {
1131 this.prefix = prefix;
1132 }
1133
1134
1135
1136
1137 public String getGroupId()
1138 {
1139 return groupId;
1140 }
1141
1142
1143
1144
1145 public void setGroupId( String groupId )
1146 {
1147 this.groupId = groupId;
1148 }
1149
1150
1151
1152
1153 public String getArtifactId()
1154 {
1155 return artifactId;
1156 }
1157
1158
1159
1160
1161 public void setArtifactId( String artifactId )
1162 {
1163 this.artifactId = artifactId;
1164 }
1165
1166
1167
1168
1169 public String getVersion()
1170 {
1171 return version;
1172 }
1173
1174
1175
1176
1177 public void setVersion( String version )
1178 {
1179 this.version = version;
1180 }
1181
1182
1183
1184
1185 public String getMojo()
1186 {
1187 return mojo;
1188 }
1189
1190
1191
1192
1193 public void setMojo( String mojo )
1194 {
1195 this.mojo = mojo;
1196 }
1197
1198
1199
1200
1201 public Plugin getPlugin()
1202 {
1203 return plugin;
1204 }
1205
1206
1207
1208
1209 public void setPlugin( Plugin plugin )
1210 {
1211 this.plugin = plugin;
1212 }
1213
1214
1215
1216
1217 public PluginDescriptor getPluginDescriptor()
1218 {
1219 return pluginDescriptor;
1220 }
1221
1222
1223
1224
1225 public void setPluginDescriptor( PluginDescriptor pluginDescriptor )
1226 {
1227 this.pluginDescriptor = pluginDescriptor;
1228 }
1229 }
1230 }