use of com.dd.plist.NSObject in project robovm by robovm.
the class Callbacks method callInstproxyCallback.
static void callInstproxyCallback(String operation, byte[] statusPlistBin, int id) throws Exception {
StatusCallback callback = null;
synchronized (Callbacks.class) {
callback = instProxyStatusCallbacks.get(id);
}
if (callback != null) {
boolean done = false;
try {
NSDictionary dict = (NSDictionary) PropertyListParser.parse(statusPlistBin);
NSObject status = dict.objectForKey("Status");
NSObject percentComplete = dict.objectForKey("PercentComplete");
NSObject error = dict.objectForKey("Error");
if (error != null) {
done = true;
callback.error(error.toString());
} else {
if ("Complete".equals(status.toString())) {
done = true;
callback.success();
} else {
callback.progress(status.toString(), ((NSNumber) percentComplete).intValue());
}
}
} catch (Throwable t) {
t.printStackTrace();
} finally {
if (done) {
synchronized (Callbacks.class) {
instProxyStatusCallbacks.remove(id);
}
}
}
}
}
use of com.dd.plist.NSObject in project robovm by robovm.
the class RamDiskTools method setupRamDisk.
/**
* Checks if a RAM disk is available and prunes it if necessary.
*/
public void setupRamDisk(Config config, File cacheDir, File tmpDir) {
this.newCacheDir = cacheDir;
this.newTmpDir = tmpDir;
if (OS.getDefaultOS() != OS.macosx) {
return;
}
File volume = new File(ROBOVM_RAM_DISK_PATH);
if (!volume.exists()) {
try {
FileStore store = Files.getFileStore(new File(System.getProperty("user.home")).toPath());
String plist = new Executor(Logger.NULL_LOGGER, "diskutil").args("info", "-plist", store.name()).execCapture();
NSDictionary dict = (NSDictionary) PropertyListParser.parse(plist.getBytes("UTF-8"));
NSObject value = dict.objectForKey("SolidState");
if (value == null || (value instanceof NSNumber && !((NSNumber) value).boolValue())) {
// @formatter:off
config.getLogger().warn("RoboVM has detected that you are running on a slow HDD. Please consider mounting a RAM disk.\n" + "To create a 2GB RAM disk, run this in your terminal:\n" + "SIZE=2048 ; diskutil erasevolume HFS+ 'RoboVM RAM Disk' `hdiutil attach -nomount ram://$((SIZE * 2048))`\n" + "See http://docs.robovm.com/ for more info");
// @formatter:on
}
} catch (Throwable t) {
// nothing to do here, can't decide if we are on a SSD or HDD
t.printStackTrace();
}
return;
}
try {
FileStore store = Files.getFileStore(volume.toPath());
if (store.getUsableSpace() < MIN_FREE_SPACE) {
cleanRamDisk(store, volume, config);
if (store.getUsableSpace() < MIN_FREE_SPACE) {
config.getLogger().info("Couldn't free enough space on RAM disk, using hard drive");
return;
}
}
File newCacheDir = new File(volume, "cache");
if (!newCacheDir.exists() && !newCacheDir.mkdirs()) {
config.getLogger().info("Couldn't create cache directory on RAM disk, using hard drive");
return;
}
File newTmpDir = new File(volume, "tmp");
if (!newTmpDir.exists() && !newTmpDir.mkdirs()) {
config.getLogger().info("Couldn't create tmp directory on RAM disk, using hard drive");
return;
}
newTmpDir = new File(newTmpDir, tmpDir.getAbsolutePath());
config.getLogger().info("Using RAM disk at %s for cache and tmp directory", ROBOVM_RAM_DISK_PATH);
this.newCacheDir = newCacheDir;
this.newTmpDir = newTmpDir;
} catch (Throwable t) {
config.getLogger().error("Couldn't setup RAM disk, using hard drive, %s", t.getMessage());
this.newCacheDir = cacheDir;
this.newTmpDir = tmpDir;
}
}
use of com.dd.plist.NSObject in project robovm by robovm.
the class InfoPList method parsePropertyList.
static NSObject parsePropertyList(File file, Properties props, boolean includeSystemProperties) throws Exception {
Properties allProps = new Properties(includeSystemProperties ? System.getProperties() : new Properties());
allProps.putAll(props);
Method getDocBuilder = XMLPropertyListParser.class.getDeclaredMethod("getDocBuilder");
getDocBuilder.setAccessible(true);
Method parseDocument = XMLPropertyListParser.class.getDeclaredMethod("parseDocument", Document.class);
parseDocument.setAccessible(true);
DocumentBuilder docBuilder = (DocumentBuilder) getDocBuilder.invoke(null);
Document doc = docBuilder.parse(file);
replacePropertyRefs(doc, allProps);
return (NSObject) parseDocument.invoke(null, doc);
}
Aggregations