2
Copyright (C) 2004-2011 Jeroen Frijters
4
This software is provided 'as-is', without any express or implied
5
warranty. In no event will the authors be held liable for any damages
6
arising from the use of this software.
8
Permission is granted to anyone to use this software for any purpose,
9
including commercial applications, and to alter it and redistribute it
10
freely, subject to the following restrictions:
12
1. The origin of this software must not be misrepresented; you must not
13
claim that you wrote the original software. If you use this software
14
in a product, an acknowledgment in the product documentation would be
15
appreciated but is not required.
16
2. Altered source versions must be plainly marked as such, and must not be
17
misrepresented as being the original software.
18
3. This notice may not be removed or altered from any source distribution.
26
import java.util.Properties;
27
import static ikvm.internal.Util.SafeGetEnvironmentVariable;
29
final class VMSystemProperties
31
private VMSystemProperties() { }
33
public static final String SPEC_TITLE = "Java Platform API Specification";
34
public static final String SPEC_VERSION = "1.7";
35
public static final String SPEC_VENDOR = "Oracle Corporation";
37
private static String getLibraryPath()
40
if(ikvm.internal.Util.WINDOWS)
42
// see /hotspot/src/os/windows/vm/os_windows.cpp for the comment that describes how we build the path
43
String windir = SafeGetEnvironmentVariable("SystemRoot");
46
libraryPath = cli.System.IO.Path.PathSeparator + windir + "\\Sun\\Java\\bin";
54
if(false) throw new cli.System.Security.SecurityException();
55
if (libraryPath == null)
57
libraryPath = cli.System.Environment.get_SystemDirectory();
61
libraryPath += cli.System.IO.Path.PathSeparator + cli.System.Environment.get_SystemDirectory();
64
catch(cli.System.Security.SecurityException _)
69
libraryPath += cli.System.IO.Path.PathSeparator + windir;
71
String path = SafeGetEnvironmentVariable("PATH");
74
libraryPath += cli.System.IO.Path.PathSeparator + path;
77
else if(ikvm.internal.Util.MACOSX)
81
else /* assume Linux, since that's the only other platform we support */
83
// on Linux we have some hardcoded paths (from /hotspot/src/os/linux/vm/os_linux.cpp)
84
// and we can only guess the cpu arch based on bitness (that means only x86 and x64)
85
String cpu_arch = cli.System.IntPtr.get_Size() == 4 ? "i386" : "amd64";
86
libraryPath = "/usr/java/packages/lib/" + cpu_arch + ":/lib:/usr/lib";
87
String ld_library_path = SafeGetEnvironmentVariable("LD_LIBRARY_PATH");
88
if(ld_library_path != null)
90
libraryPath = ld_library_path + ":" + libraryPath;
95
cli.System.Reflection.Assembly entryAsm = cli.System.Reflection.Assembly.GetEntryAssembly();
96
// If the CLR was started by a native app (e.g. via COM interop) there is no entry assembly
99
// the application (or launcher) directory is prepended to the library path
100
// (similar to how the JDK prepends its directory to the path)
101
libraryPath = new cli.System.IO.FileInfo(entryAsm.get_Location()).get_DirectoryName() + cli.System.IO.Path.PathSeparator + libraryPath;
108
if(ikvm.internal.Util.WINDOWS)
110
libraryPath += cli.System.IO.Path.PathSeparator + ".";
115
private static void initCommonProperties(Properties p)
117
p.setProperty("java.version", "1.7.0");
118
p.setProperty("java.vendor", "Jeroen Frijters");
119
p.setProperty("java.vendor.url", "http://ikvm.net/");
120
p.setProperty("java.vendor.url.bug", "http://www.ikvm.net/bugs");
121
p.setProperty("java.vm.specification.version", "1.7");
122
p.setProperty("java.vm.specification.vendor", "Oracle Corporation");
123
p.setProperty("java.vm.specification.name", "Java Virtual Machine Specification");
124
p.setProperty("java.vm.version", PropertyConstants.java_vm_version);
125
p.setProperty("java.vm.vendor", "Jeroen Frijters");
126
p.setProperty("java.vm.name", "IKVM.NET");
127
p.setProperty("java.runtime.name", "IKVM.NET");
128
p.setProperty("java.runtime.version", PropertyConstants.java_runtime_version);
129
p.setProperty("java.specification.version", SPEC_VERSION);
130
p.setProperty("java.specification.vendor", SPEC_VENDOR);
131
p.setProperty("java.specification.name", SPEC_TITLE);
132
p.setProperty("java.class.version", "51.0");
133
p.setProperty("java.class.path", "");
134
p.setProperty("java.library.path", getLibraryPath());
137
if(false) throw new cli.System.Security.SecurityException();
138
p.setProperty("java.io.tmpdir", cli.System.IO.Path.GetTempPath());
140
catch(cli.System.Security.SecurityException _)
142
// TODO should we set another value?
143
p.setProperty("java.io.tmpdir", ".");
145
p.setProperty("java.ext.dirs", "");
146
// NOTE os.name *must* contain "Windows" when running on Windows, because Classpath tests on that
147
String osname = null;
149
cli.System.OperatingSystem os = cli.System.Environment.get_OSVersion();
150
int major = os.get_Version().get_Major();
151
int minor = os.get_Version().get_Minor();
152
switch(os.get_Platform().Value)
154
case cli.System.PlatformID.Win32NT:
155
osname = "Windows NT (unknown)";
160
osver = major + "." + minor;
161
osname = "Windows NT";
168
osname = "Windows 2000";
172
osname = "Windows XP";
176
osname = "Windows 2003";
181
// since there appears to be no managed way to differentiate between Client/Server, we report client names
186
osname = "Windows Vista";
190
osname = "Windows 7";
196
case cli.System.PlatformID.Win32Windows:
203
osname = "Windows 95";
207
osname = "Windows 98";
211
osname = "Windows Me";
216
case cli.System.PlatformID.Unix:
217
if(ikvm.internal.Util.MACOSX)
219
// for back compat Mono will return PlatformID.Unix when running on the Mac,
220
// so we handle that explicitly here
222
// HACK this tries to map the Darwin version to the OS X version
223
// (based on http://en.wikipedia.org/wiki/Darwin_(operating_system)#Releases)
224
cli.System.Version ver = cli.System.Environment.get_OSVersion().get_Version();
225
osver = "10." + (ver.get_Major() - 4) + "." + ver.get_Minor();
231
osname = cli.System.Environment.get_OSVersion().ToString();
235
osver = major + "." + minor;
237
p.setProperty("os.name", osname);
238
p.setProperty("os.version", osver);
239
String arch = SafeGetEnvironmentVariable("PROCESSOR_ARCHITECTURE");
242
// we don't know, so we make a guess
243
if(cli.System.IntPtr.get_Size() == 4)
245
arch = ikvm.internal.Util.WINDOWS ? "x86" : "i386";
252
if(arch.equals("AMD64"))
256
p.setProperty("os.arch", arch);
257
p.setProperty("sun.arch.data.model", "" + (cli.System.IntPtr.get_Size() * 8));
258
p.setProperty("file.separator", "" + cli.System.IO.Path.DirectorySeparatorChar);
259
p.setProperty("file.encoding", cli.System.Text.Encoding.get_Default().get_WebName());
260
p.setProperty("path.separator", "" + cli.System.IO.Path.PathSeparator);
261
p.setProperty("line.separator", cli.System.Environment.get_NewLine());
264
if(false) throw new cli.System.Security.SecurityException();
265
p.setProperty("user.name", cli.System.Environment.get_UserName());
267
catch(cli.System.Security.SecurityException _)
269
p.setProperty("user.name", "(unknown)");
271
String home = SafeGetEnvironmentVariable("USERPROFILE");
274
// maybe we're on *nix
275
home = SafeGetEnvironmentVariable("HOME");
278
// TODO maybe there is a better way
279
// NOTE on MS .NET this doesn't return the correct path
280
// (it returns "C:\\Documents and Settings\\username\\My Documents", but we really need
281
// "C:\\Documents and Settings\\username" to be compatible with Sun, that's why we use %USERPROFILE% if it exists)
284
if(false) throw new cli.System.Security.SecurityException();
285
home = cli.System.Environment.GetFolderPath(cli.System.Environment.SpecialFolder.wrap(cli.System.Environment.SpecialFolder.Personal));
287
catch(cli.System.Security.SecurityException _)
293
p.setProperty("user.home", home);
296
if(false) throw new cli.System.Security.SecurityException();
297
p.setProperty("user.dir", cli.System.Environment.get_CurrentDirectory());
299
catch(cli.System.Security.SecurityException _)
301
p.setProperty("user.dir", ".");
303
p.setProperty("awt.toolkit", PropertyConstants.awt_toolkit);
306
public static void initProperties(Properties p)
308
p.setProperty("openjdk.version", PropertyConstants.openjdk_version);
309
String vfsroot = getVirtualFileSystemRoot();
310
p.setProperty("java.home", vfsroot.substring(0, vfsroot.length() - 1));
311
// the %home%\lib\endorsed directory does not exist, but neither does it on JDK 1.7
312
p.setProperty("java.endorsed.dirs", vfsroot + "lib" + cli.System.IO.Path.DirectorySeparatorChar + "endorsed");
313
p.setProperty("sun.boot.library.path", vfsroot + "bin");
314
p.setProperty("sun.boot.class.path", getBootClassPath());
315
initCommonProperties(p);
317
p.setProperty("sun.cpu.endian", cli.System.BitConverter.IsLittleEndian ? "little" : "big");
318
p.setProperty("file.encoding.pkg", "sun.io");
319
p.setProperty("user.timezone", "");
320
p.setProperty("sun.os.patch.level", cli.System.Environment.get_OSVersion().get_ServicePack());
321
p.setProperty("java.vm.info", "compiled mode");
322
p.setProperty("sun.nio.MaxDirectMemorySize", "-1");
323
p.setProperty("java.awt.graphicsenv", PropertyConstants.java_awt_graphicsenv);
324
p.setProperty("java.awt.printerjob", "sun.awt.windows.WPrinterJob");
327
// sun.cpu.isalist:=pentium_pro+mmx pentium_pro pentium+mmx pentium i486 i386 i86
328
// sun.desktop:=windows
329
// sun.io.unicode.encoding:=UnicodeLittle
330
// sun.jnu.encoding:=Cp1252
331
// sun.management.compiler:=HotSpot Client Compiler
334
// read properties from app.config
335
if(false) throw new cli.System.Configuration.ConfigurationException();
336
cli.System.Collections.Specialized.NameValueCollection appSettings = cli.System.Configuration.ConfigurationSettings.get_AppSettings();
337
cli.System.Collections.IEnumerator keys = appSettings.GetEnumerator();
338
while(keys.MoveNext())
340
String key = (String)keys.get_Current();
341
if(key.startsWith("ikvm:"))
343
p.setProperty(key.substring(5), appSettings.get_Item(key));
347
catch(cli.System.Configuration.ConfigurationException _)
349
// app.config is invalid, ignore
351
// set the properties that were specified with ikvm.runtime.Startup.setProperties()
352
cli.System.Collections.IDictionary props = ikvm.runtime.Startup.props;
355
cli.System.Collections.IDictionaryEnumerator entries = props.GetEnumerator();
356
while(entries.MoveNext())
358
p.setProperty((String)entries.get_Key(), (String)entries.get_Value());
363
private static void setupI18N(Properties p)
365
String[] culture = ((cli.System.String)(Object)cli.System.Globalization.CultureInfo.get_CurrentCulture().get_Name()).Split(new char[] { '-' });
370
if (culture.length == 2)
372
language = culture[0];
373
if (culture[1].length() == 4)
384
else if (culture.length == 3)
386
language = culture[0];
397
if (language.equals("nb"))
403
else if (language.equals("nn"))
413
p.setProperty("user.language", language);
414
p.setProperty("user.country", region);
415
p.setProperty("user.variant", variant);
416
p.setProperty("user.script", script);
419
private static native String getVirtualFileSystemRoot();
420
private static native String getBootClassPath();