2 * environment information
\r
4 * License : The MIT License
\r
5 * Copyright(c) 2009 olyutorskii
\r
8 package jp.sourceforge.jindolf;
\r
10 import java.io.File;
\r
11 import java.text.NumberFormat;
\r
12 import java.util.Set;
\r
13 import java.util.SortedMap;
\r
14 import java.util.TreeMap;
\r
19 public final class EnvInfo{
\r
22 public static final String OS_NAME;
\r
24 public static final String OS_VERSION;
\r
26 public static final String OS_ARCH;
\r
28 public static final String JAVA_VENDOR;
\r
29 /** Java実行形バージョン。 */
\r
30 public static final String JAVA_VERSION;
\r
32 private static final SortedMap<String, String> propertyMap =
\r
33 new TreeMap<String, String>();
\r
35 private static final SortedMap<String, String> environmentMap =
\r
36 new TreeMap<String, String>();
\r
38 private static final String[] classpaths;
\r
41 OS_NAME = getSecureProperty("os.name");
\r
42 OS_VERSION = getSecureProperty("os.version");
\r
43 OS_ARCH = getSecureProperty("os.arch");
\r
44 JAVA_VENDOR = getSecureProperty("java.vendor");
\r
45 JAVA_VERSION = getSecureProperty("java.version");
\r
47 getSecureEnvironment("LANG");
\r
48 getSecureEnvironment("DISPLAY");
\r
50 String classpath = getSecureProperty("java.class.path");
\r
51 if(classpath != null){
\r
52 classpaths = classpath.split(File.pathSeparator);
\r
54 classpaths = new String[0];
\r
59 * 可能ならシステムプロパティを読み込む。
\r
61 * @return プロパティ値。セキュリティ上読み込み禁止の場合はnull。
\r
63 private static String getSecureProperty(String key){
\r
66 result = System.getProperty(key);
\r
67 if(result != null) propertyMap.put(key, result);
\r
68 }catch(SecurityException e){
\r
77 * @return 環境変数値。セキュリティ上読み込み禁止の場合はnull。
\r
79 private static String getSecureEnvironment(String name){
\r
82 result = System.getenv(name);
\r
83 if(result != null) environmentMap.put(name, result);
\r
84 }catch(SecurityException e){
\r
94 public static String getVMInfo(){
\r
95 StringBuilder result = new StringBuilder();
\r
96 NumberFormat nform = NumberFormat.getNumberInstance();
\r
98 result.append("最大ヒープメモリ量: "
\r
99 + nform.format(Jindolf.RUNTIME.maxMemory()) + " bytes\n");
\r
101 result.append("\n");
\r
103 result.append("起動時引数:\n");
\r
104 for(String arg : Jindolf.getOptionInfo().getInvokeArgList()){
\r
105 result.append(" ").append(arg).append("\n");
\r
108 result.append("\n");
\r
110 result.append("主要システムプロパティ:\n");
\r
111 Set<String> propKeys = propertyMap.keySet();
\r
112 for(String propKey : propKeys){
\r
113 if(propKey.equals("java.class.path")) continue;
\r
114 String value = propertyMap.get(propKey);
\r
115 result.append(" ");
\r
116 result.append(propKey).append("=").append(value).append("\n");
\r
119 result.append("\n");
\r
121 result.append("主要環境変数:\n");
\r
122 Set<String> envKeys = environmentMap.keySet();
\r
123 for(String envKey : envKeys){
\r
124 String value = environmentMap.get(envKey);
\r
125 result.append(" ");
\r
126 result.append(envKey).append("=").append(value).append("\n");
\r
129 result.append("\n");
\r
131 result.append("クラスパス:\n");
\r
132 for(String path : classpaths){
\r
133 result.append(" ");
\r
134 result.append(path).append("\n");
\r
137 result.append("\n");
\r
139 return result.toString();
\r
146 throw new AssertionError();
\r