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