1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.lifecycle;
20
21 import org.apache.maven.api.services.MessageBuilder;
22 import org.apache.maven.api.services.MessageBuilderFactory;
23 import org.apache.maven.internal.impl.DefaultMessageBuilderFactory;
24 import org.apache.maven.plugin.MojoExecution;
25 import org.apache.maven.project.MavenProject;
26
27
28
29 public class LifecycleExecutionException extends Exception {
30 private MavenProject project;
31
32 public LifecycleExecutionException(String message) {
33 super(message);
34 }
35
36 public LifecycleExecutionException(Throwable cause) {
37 super(cause);
38 }
39
40 public LifecycleExecutionException(String message, Throwable cause) {
41 super(message, cause);
42 }
43
44 public LifecycleExecutionException(String message, MavenProject project) {
45 super(message);
46 this.project = project;
47 }
48
49 public LifecycleExecutionException(String message, MojoExecution execution, MavenProject project) {
50 super(message);
51 this.project = project;
52 }
53
54 public LifecycleExecutionException(String message, MojoExecution execution, MavenProject project, Throwable cause) {
55 super(message, cause);
56 this.project = project;
57 }
58
59 public LifecycleExecutionException(MojoExecution execution, MavenProject project, Throwable cause) {
60 this(new DefaultMessageBuilderFactory(), execution, project, cause);
61 }
62
63 public LifecycleExecutionException(
64 MessageBuilderFactory messageBuilderFactory,
65 MojoExecution execution,
66 MavenProject project,
67 Throwable cause) {
68 this(createMessage(messageBuilderFactory, execution, project, cause), execution, project, cause);
69 }
70
71 public MavenProject getProject() {
72 return project;
73 }
74
75 private static String createMessage(
76 MessageBuilderFactory messageBuilderFactory,
77 MojoExecution execution,
78 MavenProject project,
79 Throwable cause) {
80 MessageBuilder buffer = messageBuilderFactory.builder(256);
81
82 buffer.a("Failed to execute goal");
83
84 if (execution != null) {
85 buffer.a(' ');
86 buffer.mojo(execution.getGroupId()
87 + ':'
88 + execution.getArtifactId()
89 + ':'
90 + execution.getVersion()
91 + ':'
92 + execution.getGoal());
93 buffer.a(' ').strong('(' + execution.getExecutionId() + ')');
94 }
95
96 if (project != null) {
97 buffer.a(" on project ");
98 buffer.project(project.getArtifactId());
99 }
100
101 if (cause != null) {
102 buffer.a(": ").failure(cause.getMessage());
103 }
104
105 return buffer.toString();
106 }
107 }