1   package org.apache.maven.plugin;
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  import org.apache.maven.project.DuplicateArtifactAttachmentException;
23  import org.apache.maven.project.MavenProject;
24  import org.codehaus.plexus.util.StringUtils;
25  
26  public class PluginExecutionException
27      extends PluginManagerException
28  {
29  
30      private final MojoExecution mojoExecution;
31  
32      public PluginExecutionException( MojoExecution mojoExecution, MavenProject project, String message )
33      {
34          super( mojoExecution.getMojoDescriptor(), project, message );
35          this.mojoExecution = mojoExecution;
36      }
37  
38      public PluginExecutionException( MojoExecution mojoExecution, MavenProject project, String message, Throwable cause )
39      {
40          super( mojoExecution.getMojoDescriptor(), project, message, cause );
41          this.mojoExecution = mojoExecution;
42      }
43  
44      public PluginExecutionException( MojoExecution mojoExecution, MavenProject project, Exception cause )
45      {
46          super( mojoExecution.getMojoDescriptor(), project, constructMessage( mojoExecution, cause ), cause );
47          this.mojoExecution = mojoExecution;
48      }
49  
50      public PluginExecutionException( MojoExecution mojoExecution, MavenProject project,
51                                       DuplicateArtifactAttachmentException cause )
52      {
53          super( mojoExecution.getMojoDescriptor(), project, constructMessage( mojoExecution, cause ), cause );
54          this.mojoExecution = mojoExecution;
55      }
56  
57      public MojoExecution getMojoExecution()
58      {
59          return mojoExecution;
60      }
61  
62      private static String constructMessage( MojoExecution mojoExecution, Throwable cause )
63      {
64          String message;
65  
66          if ( mojoExecution != null )
67          {
68              message =
69                  "Execution " + mojoExecution.getExecutionId() + " of goal " + mojoExecution.getMojoDescriptor().getId()
70                      + " failed";
71          }
72          else
73          {
74              message = "Mojo execution failed";
75          }
76  
77          if ( cause != null && StringUtils.isNotEmpty( cause.getMessage() ) )
78          {
79              message += ": " + cause.getMessage();
80          }
81          else
82          {
83              message += ".";
84          }
85  
86          return message;
87      }
88  
89  }