View Javadoc
1   package org.apache.maven.plugin;
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 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   * MojoNotFoundException
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  }