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  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  }