1
2
3
4
5
6
7
8
9
10
11
12
13 package org.codehaus.plexus.build.connect.messages;
14
15 import java.util.HashMap;
16 import java.util.Map;
17
18 import org.apache.maven.execution.ExecutionEvent.Type;
19 import org.apache.maven.plugin.MojoExecution;
20
21
22
23
24 public class MojoMessage extends Message {
25
26 private static final String GOAL = "goal";
27 private static final String LIFECYCLE_PHASE = "lifecyclePhase";
28 private static final String EXECUTION_ID = "executionId";
29 private static final String VERSION = "version";
30 private static final String ARTIFACT_ID = "artifactId";
31 private static final String GROUP_ID = "groupId";
32 private static final String EVENT_TYPE = "eventType";
33
34 MojoMessage(String sessionId, long threadId, Map<String, String> payload) {
35 super(sessionId, threadId, payload);
36 }
37
38
39
40
41
42
43
44 public MojoMessage(MojoExecution mojoExecution, Type type) {
45 super(toMap(mojoExecution, type));
46 }
47
48
49
50
51 public String getGroupId() {
52 return getProperty(GROUP_ID);
53 }
54
55
56
57
58 public String getArtifactId() {
59 return getProperty(ARTIFACT_ID);
60 }
61
62
63
64
65 public String getVersion() {
66 return getProperty(VERSION);
67 }
68
69
70
71
72 public String getExecutionId() {
73 return getProperty(EXECUTION_ID);
74 }
75
76
77
78
79 public String getLifecyclePhase() {
80 return getProperty(LIFECYCLE_PHASE);
81 }
82
83
84
85
86 public String getGoal() {
87 return getProperty(GOAL);
88 }
89
90
91
92
93 public EventType getType() {
94 try {
95 return EventType.valueOf(getProperty(EVENT_TYPE));
96 } catch (RuntimeException e) {
97 return EventType.Unknown;
98 }
99 }
100
101 private static Map<String, String> toMap(MojoExecution mojoExecution, Type type) {
102 Map<String, String> map = new HashMap<>();
103 map.put(EVENT_TYPE, type.name());
104 map.put(GROUP_ID, mojoExecution.getGroupId());
105 map.put(ARTIFACT_ID, mojoExecution.getArtifactId());
106 map.put(VERSION, mojoExecution.getVersion());
107 map.put(EXECUTION_ID, mojoExecution.getExecutionId());
108 map.put(LIFECYCLE_PHASE, mojoExecution.getLifecyclePhase());
109 map.put(GOAL, mojoExecution.getGoal());
110 return map;
111 }
112
113
114
115
116 public static enum EventType {
117
118
119
120 MojoStarted,
121
122
123
124 MojoFailed,
125
126
127
128 MojoSkipped,
129
130
131
132 MojoSucceeded,
133
134
135
136 Unknown;
137 }
138 }