1
2
3
4
5
6
7
8
9
10
11
12
13 package org.codehaus.plexus.build.connect.messages;
14
15 import java.io.File;
16 import java.nio.file.Path;
17 import java.util.HashMap;
18 import java.util.Map;
19
20 import org.apache.maven.execution.ExecutionEvent.Type;
21 import org.apache.maven.project.MavenProject;
22
23
24
25
26 public class ProjectMessage extends Message {
27
28 private static final String BASE_DIR = "baseDir";
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 ProjectMessage(String sessionId, long threadId, Map<String, String> payload) {
35 super(sessionId, threadId, payload);
36 }
37
38
39
40
41
42
43
44 public ProjectMessage(MavenProject mavenProject, Type eventtype) {
45 super(toMap(mavenProject, eventtype));
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 Path getBaseDir() {
73 return new File(getProperty(BASE_DIR)).toPath();
74 }
75
76
77
78
79 public EventType getType() {
80 try {
81 return EventType.valueOf(getProperty(EVENT_TYPE));
82 } catch (RuntimeException e) {
83 return EventType.Unknown;
84 }
85 }
86
87 private static Map<String, String> toMap(MavenProject mavenProject, Type eventtype) {
88 Map<String, String> map = new HashMap<>();
89 map.put(EVENT_TYPE, eventtype.name());
90 map.put(GROUP_ID, mavenProject.getGroupId());
91 map.put(ARTIFACT_ID, mavenProject.getArtifactId());
92 map.put(VERSION, mavenProject.getVersion());
93 map.put(BASE_DIR, mavenProject.getBasedir().getAbsolutePath());
94 return map;
95 }
96
97
98
99
100 public static enum EventType {
101
102
103
104 ProjectStarted,
105
106
107
108 ProjectFailed,
109
110
111
112 ProjectSkipped,
113
114
115
116 ProjectSucceeded,
117
118
119
120 Unknown;
121 }
122 }