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