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