View Javadoc

1   package org.apache.maven.lifecycle;
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 org.apache.maven.plugin.MojoExecution;
23  import org.apache.maven.project.MavenProject;
24  
25  /**
26   * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
27   * @version $Id: LifecycleExecutionException.java 935748 2010-04-19 21:14:33Z bentmann $
28   */
29  public class LifecycleExecutionException
30      extends Exception
31  {
32      private MavenProject project;
33      
34      public LifecycleExecutionException( String message )
35      {
36          super( message );
37      }
38  
39      public LifecycleExecutionException( Throwable cause )
40      {
41          super( cause );
42      }
43  
44      public LifecycleExecutionException( String message, Throwable cause )
45      {
46          super( message, cause );
47      }
48      
49      public LifecycleExecutionException( String message, MavenProject project )
50      {
51          super( message );
52          this.project = project;
53      }
54  
55      public LifecycleExecutionException( String message, MojoExecution execution, MavenProject project )
56      {
57          super( message );
58          this.project = project;
59      }
60  
61      public LifecycleExecutionException( String message, MojoExecution execution, MavenProject project, Throwable cause )
62      {
63          super( message, cause );
64          this.project = project;
65      }
66  
67      public LifecycleExecutionException( MojoExecution execution, MavenProject project, Throwable cause )
68      {
69          this( createMessage( execution, project, cause ), execution, project, cause );
70      }
71  
72      public MavenProject getProject()
73      {
74          return project;
75      }
76  
77      private static String createMessage( MojoExecution execution, MavenProject project, Throwable cause )
78      {
79          StringBuilder buffer = new StringBuilder( 256 );
80  
81          buffer.append( "Failed to execute goal" );
82  
83          if ( execution != null )
84          {
85              buffer.append( ' ' );
86              buffer.append( execution.getGroupId() );
87              buffer.append( ':' );
88              buffer.append( execution.getArtifactId() );
89              buffer.append( ':' );
90              buffer.append( execution.getVersion() );
91              buffer.append( ':' );
92              buffer.append( execution.getGoal() );
93              buffer.append( " (" );
94              buffer.append( execution.getExecutionId() );
95              buffer.append( ")" );
96          }
97  
98          if ( project != null )
99          {
100             buffer.append( " on project " );
101             buffer.append( project.getArtifactId() );
102         }
103 
104         if ( cause != null )
105         {
106             buffer.append( ": " ).append( cause.getMessage() );
107         }
108 
109         return buffer.toString();
110     }
111 
112 }