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