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  
27  
28  
29  public class PluginExecutionException
30      extends PluginManagerException
31  {
32  
33      private final MojoExecution mojoExecution;
34  
35      public PluginExecutionException( MojoExecution mojoExecution, MavenProject project, String message )
36      {
37          super( mojoExecution.getMojoDescriptor(), project, message );
38          this.mojoExecution = mojoExecution;
39      }
40  
41      public PluginExecutionException( MojoExecution mojoExecution, MavenProject project, String message,
42                                       Throwable cause )
43      {
44          super( mojoExecution.getMojoDescriptor(), project, message, cause );
45          this.mojoExecution = mojoExecution;
46      }
47  
48      public PluginExecutionException( MojoExecution mojoExecution, MavenProject project, Exception cause )
49      {
50          super( mojoExecution.getMojoDescriptor(), project, constructMessage( mojoExecution, cause ), cause );
51          this.mojoExecution = mojoExecution;
52      }
53  
54      public PluginExecutionException( MojoExecution mojoExecution, MavenProject project,
55                                       DuplicateArtifactAttachmentException cause )
56      {
57          super( mojoExecution.getMojoDescriptor(), project, constructMessage( mojoExecution, cause ), cause );
58          this.mojoExecution = mojoExecution;
59      }
60  
61      public MojoExecution getMojoExecution()
62      {
63          return mojoExecution;
64      }
65  
66      private static String constructMessage( MojoExecution mojoExecution, Throwable cause )
67      {
68          String message;
69  
70          if ( mojoExecution != null )
71          {
72              message =
73                  "Execution " + mojoExecution.getExecutionId() + " of goal " + mojoExecution.getMojoDescriptor().getId()
74                      + " failed";
75          }
76          else
77          {
78              message = "Mojo execution failed";
79          }
80  
81          if ( cause != null && StringUtils.isNotEmpty( cause.getMessage() ) )
82          {
83              message += ": " + cause.getMessage();
84          }
85          else
86          {
87              message += ".";
88          }
89  
90          return message;
91      }
92  
93  }