View Javadoc
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.LinkedHashMap;
16  import java.util.Map;
17  import java.util.Properties;
18  
19  import org.apache.maven.eventspy.EventSpy.Context;
20  
21  /**
22   * Message send to init the inital communication with the endpoints
23   */
24  public class InitMessage extends Message {
25  
26      /**
27       * Creates a message with inital information about the running maven system
28       *
29       * @param context the context settings to send to the endpoint
30       */
31      public InitMessage(Context context) {
32          super(toMap(context));
33      }
34  
35      private static Map<String, String> toMap(Context context) {
36          Map<String, String> data = new LinkedHashMap<>();
37          context.getData().forEach((k, v) -> {
38              if (v instanceof String) {
39                  data.put(k, (String) v);
40              }
41              if (v instanceof Properties) {
42                  Properties properties = (Properties) v;
43                  for (String p : properties.stringPropertyNames()) {
44                      data.put(k + "." + p, properties.getProperty(p));
45                  }
46              }
47          });
48          return data;
49      }
50  
51      InitMessage(String sessionId, long threadId, Map<String, String> payload) {
52          super(sessionId, threadId, payload);
53      }
54  }