1
19
20 package com.liferay.portal.kernel.util;
21
22 import java.io.BufferedReader;
23 import java.io.IOException;
24 import java.io.InputStreamReader;
25
26 import java.util.Enumeration;
27 import java.util.Properties;
28
29
35 public class SystemEnv {
36
37 public static Properties getProperties() {
38 Properties props = new Properties();
39
40 try {
41 Runtime runtime = Runtime.getRuntime();
42 Process process = null;
43
44 String osName = System.getProperty("os.name").toLowerCase();
45
46 if (osName.indexOf("windows ") > -1) {
47 if (osName.indexOf("windows 9") > -1) {
48 process = runtime.exec("command.com /c set");
49 }
50 else {
51 process = runtime.exec("cmd.exe /c set");
52 }
53 }
54 else {
55 process = runtime.exec("env");
56 }
57
58 BufferedReader br = new BufferedReader(
59 new InputStreamReader(process.getInputStream()));
60
61 String line;
62
63 while ((line = br.readLine()) != null) {
64 int pos = line.indexOf(StringPool.EQUAL);
65
66 if (pos != -1) {
67 String key = line.substring(0, pos);
68 String value = line.substring(pos + 1);
69
70 props.setProperty(key, value);
71 }
72 }
73 }
74 catch (IOException ioe) {
75 ioe.printStackTrace();
76 }
77
78 return props;
79 }
80
81 public static void setProperties(Properties props) {
82 Properties envProps = getProperties();
83
84 Enumeration<String> enu = (Enumeration<String>)envProps.propertyNames();
85
86 while (enu.hasMoreElements()) {
87 String key = enu.nextElement();
88
89 props.setProperty("env." + key, (String)envProps.get(key));
90 }
91 }
92
93 }