1 package org.apache.maven.plugin;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.Iterator;
23 import java.util.List;
24
25 import org.apache.maven.plugin.descriptor.MojoDescriptor;
26 import org.apache.maven.plugin.descriptor.PluginDescriptor;
27
28
29
30
31 public class MojoNotFoundException
32 extends Exception
33 {
34 private String goal;
35
36 private PluginDescriptor pluginDescriptor;
37
38 public MojoNotFoundException( String goal, PluginDescriptor pluginDescriptor )
39 {
40 super( toMessage( goal, pluginDescriptor ) );
41
42 this.goal = goal;
43 this.pluginDescriptor = pluginDescriptor;
44 }
45
46 public String getGoal()
47 {
48 return goal;
49 }
50
51 public PluginDescriptor getPluginDescriptor()
52 {
53 return pluginDescriptor;
54 }
55
56 private static String toMessage( String goal, PluginDescriptor pluginDescriptor )
57 {
58 StringBuilder buffer = new StringBuilder( 256 );
59
60 buffer.append( "Could not find goal '" ).append( goal ).append( '\'' );
61
62 if ( pluginDescriptor != null )
63 {
64 buffer.append( " in plugin " ).append( pluginDescriptor.getId() );
65
66 buffer.append( " among available goals " );
67 List<MojoDescriptor> mojos = pluginDescriptor.getMojos();
68 if ( mojos != null )
69 {
70 for ( Iterator<MojoDescriptor> it = mojos.iterator(); it.hasNext(); )
71 {
72 MojoDescriptor mojo = it.next();
73 if ( mojo != null )
74 {
75 buffer.append( mojo.getGoal() );
76 }
77 if ( it.hasNext() )
78 {
79 buffer.append( ", " );
80 }
81 }
82 }
83 }
84
85 return buffer.toString();
86 }
87
88 }