Search in sources :

Example 11 with NSObject

use of com.dd.plist.NSObject in project robovm by robovm.

the class MobileImageMounterClient method main.

public static void main(String[] args) throws Exception {
    String deviceId = null;
    String action = null;
    int index = 0;
    try {
        action = args[index++];
        if (action.matches("[0-9a-f]{40}")) {
            deviceId = action;
            action = args[index++];
        }
        if (!action.matches("lookup|mount")) {
            System.err.println("Unknown action: " + action);
            printUsageAndExit();
        }
        if (deviceId == null) {
            if (deviceId == null) {
                String[] udids = IDevice.listUdids();
                if (udids.length == 0) {
                    System.err.println("No device connected");
                    return;
                }
                if (udids.length > 1) {
                    System.err.println("More than 1 device connected (" + Arrays.asList(udids) + "). Using " + udids[0]);
                }
                deviceId = udids[0];
            }
        }
        try (IDevice device = new IDevice(deviceId)) {
            try (LockdowndClient lockdowndClient = new LockdowndClient(device, MobileImageMounterClient.class.getSimpleName(), true)) {
                LockdowndServiceDescriptor afcService = lockdowndClient.startService(AfcClient.SERVICE_NAME);
                try (AfcClient afcClient = new AfcClient(device, afcService)) {
                    LockdowndServiceDescriptor mimService = lockdowndClient.startService(SERVICE_NAME);
                    try (MobileImageMounterClient mimClient = new MobileImageMounterClient(device, mimService)) {
                        NSObject result = null;
                        String imageType = null;
                        switch(action) {
                            case "lookup":
                                if (args.length < index) {
                                    imageType = args[index];
                                }
                                result = mimClient.lookupImage(imageType);
                                break;
                            case "mount":
                                String imagePath = args[index++];
                                String sigPath = args[index++];
                                byte[] sig = Files.readAllBytes(new File(sigPath).toPath());
                                if (args.length < index) {
                                    imageType = args[index];
                                }
                                afcClient.makeDirectory("/PublicStaging");
                                afcClient.fileCopy(new File(imagePath), "/PublicStaging/staging.dimage");
                                result = mimClient.mountImage("/PublicStaging/staging.dimage", sig, imageType);
                                break;
                        }
                        System.out.println(result.toXMLPropertyList());
                    }
                }
            }
        }
    } catch (ArrayIndexOutOfBoundsException e) {
        printUsageAndExit();
    }
}
Also used : NSObject(com.dd.plist.NSObject) File(java.io.File)

Example 12 with NSObject

use of com.dd.plist.NSObject in project robovm by robovm.

the class LockdowndClientTest method testGetValue.

@Test
public void testGetValue() throws Exception {
    String udid = IDevice.listUdids()[0];
    try (IDevice device = new IDevice(udid);
        LockdowndClient client = new LockdowndClient(device, null, true)) {
        NSObject node = client.getValue(null, null);
        assertTrue(node instanceof NSDictionary);
        NSDictionary dict = (NSDictionary) node;
        assertNotNull(dict.objectForKey("DeviceName"));
    }
}
Also used : NSObject(com.dd.plist.NSObject) NSDictionary(com.dd.plist.NSDictionary) Test(org.junit.Test)

Example 13 with NSObject

use of com.dd.plist.NSObject in project bazel by bazelbuild.

the class PlistMerging method from.

/**
   * Generates a Plistmerging combining values from sourceFiles and immutableSourceFiles, and
   * modifying them based on subsitutions and keysToRemoveIfEmptyString.
   */
public static PlistMerging from(List<Path> sourceFiles, List<Path> immutableSourceFiles, Map<String, String> substitutions, KeysToRemoveIfEmptyString keysToRemoveIfEmptyString, String executableName) throws IOException {
    NSDictionary merged = PlistMerging.merge(sourceFiles);
    NSDictionary immutableEntries = PlistMerging.merge(immutableSourceFiles);
    Set<String> conflictingEntries = Sets.intersection(immutableEntries.keySet(), merged.keySet());
    Preconditions.checkArgument(conflictingEntries.isEmpty(), "The following plist entries may not be overridden, but are present in more than one " + "of the input lists: %s", conflictingEntries);
    merged.putAll(immutableEntries);
    for (Map.Entry<String, NSObject> entry : merged.entrySet()) {
        if (entry.getValue().toJavaObject() instanceof String) {
            String newValue = substituteEnvironmentVariable(substitutions, (String) entry.getValue().toJavaObject());
            merged.put(entry.getKey(), newValue);
        }
    }
    for (String key : keysToRemoveIfEmptyString) {
        if (Equaling.of(Mapping.of(merged, key), Optional.<NSObject>of(new NSString("")))) {
            merged.remove(key);
        }
    }
    // TODO(bazel-team): warn user if we replace their values.
    if (!immutableEntries.isEmpty()) {
        Pattern versionPattern = Pattern.compile("[^0-9.]");
        if (!merged.containsKey(BUNDLE_VERSION_PLIST_KEY)) {
            merged.put(BUNDLE_VERSION_PLIST_KEY, BUNDLE_VERSION_DEFAULT);
        } else {
            NSObject nsVersion = merged.get(BUNDLE_VERSION_PLIST_KEY);
            String version = (String) nsVersion.toJavaObject();
            if (version.length() > 18 || versionPattern.matcher(version).find()) {
                merged.put(BUNDLE_VERSION_PLIST_KEY, BUNDLE_VERSION_DEFAULT);
            }
        }
        if (!merged.containsKey(BUNDLE_SHORT_VERSION_STRING_PLIST_KEY)) {
            merged.put(BUNDLE_SHORT_VERSION_STRING_PLIST_KEY, BUNDLE_SHORT_VERSION_STRING_DEFAULT);
        } else {
            NSObject nsVersion = merged.get(BUNDLE_SHORT_VERSION_STRING_PLIST_KEY);
            String version = (String) nsVersion.toJavaObject();
            if (version.length() > 18 || versionPattern.matcher(version).find()) {
                merged.put(BUNDLE_SHORT_VERSION_STRING_PLIST_KEY, BUNDLE_SHORT_VERSION_STRING_DEFAULT);
            }
        }
    }
    PlistMerging result = new PlistMerging(merged);
    if (executableName != null) {
        result.setExecutableName(executableName);
    }
    return result;
}
Also used : Pattern(java.util.regex.Pattern) NSObject(com.dd.plist.NSObject) NSDictionary(com.dd.plist.NSDictionary) NSString(com.dd.plist.NSString) Map(java.util.Map) NSString(com.dd.plist.NSString)

Example 14 with NSObject

use of com.dd.plist.NSObject in project bazel by bazelbuild.

the class XcodeprojSerializer method serializeObject.

/**
   * Serialize a {@link PBXObject} and its recursive descendants into the object dictionary.
   *
   * @return the GID of the serialized object
   *
   * @see PBXObject#serializeInto
   */
private String serializeObject(PBXObject obj) {
    if (obj.getGlobalID() == null) {
        obj.setGlobalID(obj.generateGid(gidGenerator));
        LOG.verbose("Set new object GID: %s", obj);
    } else {
        // Check that the object has already been serialized.
        NSObject object = objects.get(obj.getGlobalID());
        if (object != null) {
            LOG.verbose("Object %s found, returning existing object %s", obj, object);
            return obj.getGlobalID();
        } else {
            LOG.verbose("Object already had GID set: %s", obj);
        }
    }
    // Save the existing object being deserialized.
    NSDictionary stack = currentObject;
    currentObject = new NSDictionary();
    currentObject.put("isa", obj.isa());
    obj.serializeInto(this);
    objects.put(obj.getGlobalID(), currentObject);
    // Restore the existing object being deserialized.
    currentObject = stack;
    return obj.getGlobalID();
}
Also used : NSObject(com.dd.plist.NSObject) NSDictionary(com.dd.plist.NSDictionary)

Example 15 with NSObject

use of com.dd.plist.NSObject in project buck by facebook.

the class ProjectWorkspace method assertFilesEqual.

public void assertFilesEqual(Path expected, Path actual) throws IOException {
    if (!expected.isAbsolute()) {
        expected = templatePath.resolve(expected);
    }
    if (!actual.isAbsolute()) {
        actual = destPath.resolve(actual);
    }
    if (!Files.isRegularFile(actual)) {
        fail("Expected file " + actual + " could not be found.");
    }
    String extension = MorePaths.getFileExtension(actual);
    String cleanPathToObservedFile = MoreStrings.withoutSuffix(templatePath.relativize(expected).toString(), EXPECTED_SUFFIX);
    switch(extension) {
        //    Otherwise, fall back to exact string match.
        case "plist":
        case "stringsdict":
            NSObject expectedObject;
            try {
                expectedObject = BinaryPropertyListParser.parse(expected.toFile());
            } catch (Exception e) {
                // Not binary format.
                expectedObject = null;
            }
            NSObject observedObject;
            try {
                observedObject = BinaryPropertyListParser.parse(actual.toFile());
            } catch (Exception e) {
                // Not binary format.
                observedObject = null;
            }
            assertTrue(String.format("In %s, expected plist to be of %s type.", cleanPathToObservedFile, (expectedObject != null) ? "binary" : "XML"), (expectedObject != null) == (observedObject != null));
            if (expectedObject != null) {
                // These keys depend on the locally installed version of Xcode, so ignore them
                // in comparisons.
                String[] ignoredKeys = { "DTSDKName", "DTPlatformName", "DTPlatformVersion", "MinimumOSVersion", "DTSDKBuild", "DTPlatformBuild", "DTXcode", "DTXcodeBuild" };
                if (observedObject instanceof NSDictionary && expectedObject instanceof NSDictionary) {
                    for (String key : ignoredKeys) {
                        ((NSDictionary) observedObject).remove(key);
                        ((NSDictionary) expectedObject).remove(key);
                    }
                }
                assertEquals(String.format("In %s, expected binary plist contents to match.", cleanPathToObservedFile), expectedObject, observedObject);
                break;
            } else {
                assertFileContentsEqual(expected, actual);
            }
            break;
        default:
            assertFileContentsEqual(expected, actual);
    }
}
Also used : NSObject(com.dd.plist.NSObject) NSDictionary(com.dd.plist.NSDictionary) NoSuchFileException(java.nio.file.NoSuchFileException) InvalidPathException(java.nio.file.InvalidPathException) IOException(java.io.IOException) FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException)

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