Search in sources :

Example 26 with NSObject

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);
                }
            }
        }
    }
}
Also used : NSObject(com.dd.plist.NSObject) NSDictionary(com.dd.plist.NSDictionary) StatusCallback(org.robovm.libimobiledevice.InstallationProxyClient.StatusCallback)

Example 27 with NSObject

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;
    }
}
Also used : NSNumber(com.dd.plist.NSNumber) FileStore(java.nio.file.FileStore) NSObject(com.dd.plist.NSObject) Executor(org.robovm.compiler.util.Executor) NSDictionary(com.dd.plist.NSDictionary) File(java.io.File)

Example 28 with NSObject

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);
}
Also used : NSObject(com.dd.plist.NSObject) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Method(java.lang.reflect.Method) Properties(java.util.Properties) Document(org.w3c.dom.Document)

Aggregations

NSObject (com.dd.plist.NSObject)28 NSDictionary (com.dd.plist.NSDictionary)21 NSString (com.dd.plist.NSString)11 IOException (java.io.IOException)8 NSArray (com.dd.plist.NSArray)7 Test (org.junit.Test)7 NSNumber (com.dd.plist.NSNumber)5 ImmutableMap (com.google.common.collect.ImmutableMap)5 BufferedInputStream (java.io.BufferedInputStream)4 File (java.io.File)4 InputStream (java.io.InputStream)4 Date (java.util.Date)4 Path (java.nio.file.Path)3 PropertyListFormatException (com.dd.plist.PropertyListFormatException)2 TestConsole (com.facebook.buck.testutil.TestConsole)2 DefaultProcessExecutor (com.facebook.buck.util.DefaultProcessExecutor)2 HumanReadableException (com.facebook.buck.util.HumanReadableException)2 HashCode (com.google.common.hash.HashCode)2 NoSuchFileException (java.nio.file.NoSuchFileException)2 ParseException (java.text.ParseException)2