use of libcore.io.StructPasswd in project robovm by robovm.
the class System method initSystemProperties.
private static void initSystemProperties() {
VMRuntime runtime = VMRuntime.getRuntime();
Properties p = new Properties();
String projectUrl = "http://www.robovm.org/";
String projectName = "RoboVM";
p.put("java.boot.class.path", runtime.bootClassPath());
p.put("java.class.path", runtime.classPath());
// None of these four are meaningful on Android, but these keys are guaranteed
// to be present for System.getProperty. For java.class.version, we use the maximum
// class file version that dx currently supports.
p.put("java.class.version", "50.0");
p.put("java.compiler", "");
p.put("java.ext.dirs", "");
p.put("java.version", "0");
// RoboVM note: Android uses getenv("JAVA_HOME") here with "/system" as fallback.
p.put("java.home", VM.resourcesPath());
// RoboVM note: Use value of $TMPDIR if set. Otherwise use /tmp as Android does.
String tmpdir = getenv("TMPDIR");
p.put("java.io.tmpdir", tmpdir != null ? tmpdir : "/tmp");
String ldLibraryPath = getenv("LD_LIBRARY_PATH");
if (ldLibraryPath != null) {
p.put("java.library.path", ldLibraryPath);
}
p.put("java.specification.name", "RoboVM Core Library");
p.put("java.specification.vendor", projectName);
p.put("java.specification.version", "0.9");
p.put("java.vendor", projectName);
p.put("java.vendor.url", projectUrl);
p.put("java.vm.name", "RoboVM");
p.put("java.vm.specification.name", "RoboVM Virtual Machine Specification");
p.put("java.vm.specification.vendor", projectName);
p.put("java.vm.specification.version", "0.9");
p.put("java.vm.vendor", projectName);
p.put("java.vm.version", runtime.vmVersion());
p.put("file.separator", "/");
p.put("line.separator", "\n");
p.put("path.separator", ":");
p.put("java.runtime.name", "RoboVM Runtime");
p.put("java.runtime.version", "0.9");
p.put("java.vm.vendor.url", projectUrl);
p.put("file.encoding", "UTF-8");
p.put("user.language", "en");
p.put("user.region", "US");
try {
StructPasswd passwd = Libcore.os.getpwuid(Libcore.os.getuid());
p.put("user.home", passwd.pw_dir);
p.put("user.name", passwd.pw_name);
} catch (ErrnoException exception) {
// RoboVM note: Start change. Fall back to environment variables. getpwuid() fails on the iOS simulator.
String home = getenv("HOME");
String user = getenv("USER");
p.put("user.home", home != null ? home : "");
p.put("user.name", user != null ? user : "");
// RoboVM note: End change.
}
StructUtsname info = Libcore.os.uname();
p.put("os.arch", info.machine);
p.put("os.name", info.sysname);
p.put("os.version", info.release);
// Undocumented Android-only properties.
p.put("android.icu.library.version", ICU.getIcuVersion());
p.put("android.icu.unicode.version", ICU.getUnicodeVersion());
p.put("android.icu.cldr.version", ICU.getCldrVersion());
parsePropertyAssignments(p, specialProperties());
parsePropertyAssignments(p, robovmSpecialProperties());
// user.home, user.dir and user.name values on iOS.
if (p.getProperty("os.name").contains("iOS")) {
// On iOS we want user.home and user.dir to point to the app's data
// container root dir. This is the dir $HOME points to. We also set
// user.name to $USER or hardcode 'mobile' if $USER isn't set (iOS
// simulator).
String home = getenv("HOME");
String user = getenv("USER");
p.put("user.home", home != null ? home : "");
p.put("user.dir", home != null ? home : "/");
p.put("user.name", user != null ? user : "mobile");
}
// RoboVM note: End change.
// Override built-in properties with settings from the command line.
parsePropertyAssignments(p, runtime.properties());
systemProperties = p;
}
Aggregations