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