1 /*
2 Copyright (c) 2025 Christoph Läubrich All rights reserved.
3
4 This program is licensed to you under the Apache License Version 2.0,
5 and you may not use this file except in compliance with the Apache License Version 2.0.
6 You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
7
8 Unless required by applicable law or agreed to in writing,
9 software distributed under the Apache License Version 2.0 is distributed on an
10 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
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.MavenSession;
19
20 /**
21 * Event that is received / send when a session starts/end
22 */
23 public class SessionMessage extends Message {
24
25 private static final String SESSION_EXECUTION_ROOT_DIRECTORY = "sessionExecutionRootDirectory";
26 private static final String SESSION_START = "sessionStart";
27
28 /**
29 * Creates a new session message
30 *
31 * @param session the session to use
32 * @param start <code>true</code> if it is a start of the session or
33 * <code>false</code> if it is the end of a session
34 */
35 public SessionMessage(MavenSession session, boolean start) {
36 super(buildMap(session, start));
37 }
38
39 SessionMessage(String sessionId, long threadId, Map<String, String> payload) {
40 super(sessionId, threadId, payload);
41 }
42
43 /**
44 * @return <code>true</code> if this is a session start event
45 */
46 public boolean isSessionStart() {
47 return getBooleanProperty(SESSION_START);
48 }
49
50 /**
51 * @return the value of the ExecutionRootDirectory of this session
52 */
53 public String getExecutionRootDirectory() {
54 return getProperty(SESSION_EXECUTION_ROOT_DIRECTORY);
55 }
56
57 private static Map<String, String> buildMap(MavenSession session, boolean start) {
58 Map<String, String> map = new HashMap<>(2);
59 map.put(SESSION_START, Boolean.toString(start));
60 map.put(SESSION_EXECUTION_ROOT_DIRECTORY, session.getExecutionRootDirectory());
61 return map;
62 }
63 }