Merge "Bug 116 - Revisit SanityTest"
[controller.git] / opendaylight / commons / controller-maven-plugin / src / main / java / org / opendaylight / controller / maven / plugin / util / JavaProcess.java
1
2 /*
3  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
4  *
5  * This program and the accompanying materials are made available under the
6  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7  * and is available at http://www.eclipse.org/legal/epl-v10.html
8  */
9 package org.opendaylight.controller.maven.plugin.util;
10
11 import java.util.Properties;
12
13 public class JavaProcess {
14     private final int pid;
15     private final String mainClass;
16     private final Properties systemProperties = new Properties();
17
18     public JavaProcess(int id, String cls) {
19         this.pid = id;
20         this.mainClass = cls;
21     }
22
23     public void setSystemProperties(String line) {
24         if (line == null || line.length() == 0) return;
25         String[] tokens = line.split("\\s");
26         for (String t : tokens) setSystemProperty(t);
27     }
28
29     public void setSystemProperty(String line) {
30         if (line.startsWith("-D")) {
31             int x = line.indexOf('=');
32             if (x > -1) {
33                 systemProperties.put(line.substring(2, x), line.substring(x+1));
34             } else {
35                 systemProperties.put(line.substring(2), "");
36             }
37         }
38     }
39
40     public int getPid() {
41         return pid;
42     }
43
44     public String getMainClass() {
45         return mainClass;
46     }
47
48     public Properties getSystemProperties() {
49         return systemProperties;
50     }
51
52     @Override
53     public String toString() {
54         return "pid:" + pid + " class:" + mainClass +
55                 " system-properties:" + systemProperties.toString();
56     }
57 }