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 public class MojoNotFoundException
29 extends Exception
30 {
31 private String goal;
32
33 private PluginDescriptor pluginDescriptor;
34
35 public MojoNotFoundException( String goal, PluginDescriptor pluginDescriptor )
36 {
37 super( toMessage( goal, pluginDescriptor ) );
38
39 this.goal = goal;
40 this.pluginDescriptor = pluginDescriptor;
41 }
42
43 public String getGoal()
44 {
45 return goal;
46 }
47
48 public PluginDescriptor getPluginDescriptor()
49 {
50 return pluginDescriptor;
51 }
52
53 private static String toMessage( String goal, PluginDescriptor pluginDescriptor )
54 {
55 StringBuilder buffer = new StringBuilder( 256 );
56
57 buffer.append( "Could not find goal '" ).append( goal ).append( "'" );
58
59 if ( pluginDescriptor != null )
60 {
61 buffer.append( " in plugin " ).append( pluginDescriptor.getId() );
62
63 buffer.append( " among available goals " );
64 List<MojoDescriptor> mojos = pluginDescriptor.getMojos();
65 if ( mojos != null )
66 {
67 for ( Iterator<MojoDescriptor> it = mojos.iterator(); it.hasNext(); )
68 {
69 MojoDescriptor mojo = it.next();
70 if ( mojo != null )
71 {
72 buffer.append( mojo.getGoal() );
73 }
74 if ( it.hasNext() )
75 {
76 buffer.append( ", " );
77 }
78 }
79 }
80 }
81
82 return buffer.toString();
83 }
84
85 }