Search in sources :

Example 26 with NSDictionary

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

the class ProvisioningProfileTest method createProfile.

@SuppressWarnings("unchecked")
private ProvisioningProfile createProfile(String name, String appIdName, String appIdPrefix, String appId, boolean getTaskAllow, String provisionedDevice, String fingerprint) throws Exception {
    NSDictionary entitlements = new NSDictionary();
    entitlements.put("application-identifier", appId);
    entitlements.put("get-task-allow", new NSNumber(getTaskAllow));
    NSDictionary dict = new NSDictionary();
    dict.put("UUID", UUID.randomUUID().toString());
    dict.put("Name", name);
    dict.put("AppIDName", appIdName);
    dict.put("ApplicationIdentifierPrefix", new NSArray(new NSString(appIdPrefix)));
    dict.put("CreationDate", new NSDate(new Date()));
    dict.put("ExpirationDate", new NSDate(new Date()));
    dict.put("Entitlements", entitlements);
    dict.put("DeveloperCertificates", new NSArray());
    if (provisionedDevice != null) {
        NSArray devices = new NSArray(1);
        devices.setValue(0, new NSString(provisionedDevice));
        dict.put("ProvisionedDevices", devices);
    }
    ProvisioningProfile profile = new ProvisioningProfile(new File(""), dict);
    Field f = ProvisioningProfile.class.getDeclaredField("certFingerprints");
    f.setAccessible(true);
    List<String> certFingerprints = (List<String>) f.get(profile);
    certFingerprints.add(fingerprint);
    return profile;
}
Also used : NSNumber(com.dd.plist.NSNumber) Field(java.lang.reflect.Field) NSArray(com.dd.plist.NSArray) NSDictionary(com.dd.plist.NSDictionary) List(java.util.List) NSString(com.dd.plist.NSString) NSString(com.dd.plist.NSString) File(java.io.File) NSDate(com.dd.plist.NSDate) Date(java.util.Date) NSDate(com.dd.plist.NSDate)

Example 27 with NSDictionary

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

the class InfoPListTest method testParsePropertyList.

@Test
public void testParsePropertyList() throws Exception {
    File file = File.createTempFile(InfoPListTest.class.getSimpleName(), ".tmp");
    byte[] data = IOUtils.toByteArray(getClass().getResourceAsStream("InfoPListTest.Info.plist.xml"));
    FileUtils.writeByteArrayToFile(file, data);
    Properties props = new Properties();
    props.setProperty("prop1", "value1");
    props.setProperty("prop2", "value2");
    props.setProperty("prop3", "value3");
    props.setProperty("prop4", "value4");
    NSDictionary dict = (NSDictionary) InfoPList.parsePropertyList(file, props, true);
    assertEquals(new NSString("value1"), dict.objectForKey("Prop1"));
    assertEquals(new NSString("value2foobar"), dict.objectForKey("Prop2"));
    assertEquals(new NSString("foobarvalue3"), dict.objectForKey("Prop3"));
    assertEquals(new NSString("foovalue4bar"), dict.objectForKey("Prop4"));
    assertEquals(new NSString("foovalue1value2bar"), dict.objectForKey("Prop5"));
    assertEquals(new NSString("foovalue1woovalue2bar"), dict.objectForKey("Prop6"));
    assertEquals(new NSString("value1woovalue2"), dict.objectForKey("Prop7"));
    assertEquals(new NSString("${unknown}"), dict.objectForKey("Prop8"));
    assertEquals(Arrays.asList(new NSString("value1"), new NSString("value2")), Arrays.asList(((NSArray) dict.objectForKey("List")).getArray()));
}
Also used : NSArray(com.dd.plist.NSArray) NSDictionary(com.dd.plist.NSDictionary) Properties(java.util.Properties) File(java.io.File) NSString(com.dd.plist.NSString) Test(org.junit.Test)

Example 28 with NSDictionary

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

the class AppLauncher method getAppId.

private static String getAppId(File f) throws IOException {
    if (f == null) {
        throw new NullPointerException("localAppPath");
    }
    if (!f.exists()) {
        throw new FileNotFoundException(f.getAbsolutePath());
    }
    NSDictionary infoPlistDict = null;
    if (f.getName().toLowerCase().endsWith(".ipa")) {
        try (ZipFile zipFile = new ZipFile(f)) {
            for (ZipEntry entry : Collections.list(zipFile.entries())) {
                if (entry.getName().matches("Payload/[^/]+\\.app/Info\\.plist")) {
                    try (InputStream is = zipFile.getInputStream(entry)) {
                        try {
                            infoPlistDict = (NSDictionary) PropertyListParser.parse(is);
                        } catch (IOException e) {
                            throw e;
                        } catch (Exception e) {
                            throw new IOException(e);
                        }
                        break;
                    }
                }
            }
        }
    } else if (f.isDirectory()) {
        File infoPlistFile = new File(f, "Info.plist");
        if (infoPlistFile.exists()) {
            try {
                infoPlistDict = (NSDictionary) PropertyListParser.parse(infoPlistFile);
            } catch (IOException e) {
                throw e;
            } catch (Exception e) {
                throw new IOException(e);
            }
        }
    }
    if (infoPlistDict == null) {
        throw new IllegalArgumentException("Path " + f + " is neither a " + ".ipa file nor an iOS app bundle directory.");
    }
    NSString appId = (NSString) infoPlistDict.objectForKey("CFBundleIdentifier");
    if (appId == null) {
        throw new IllegalArgumentException("No CFBundleIdentifier found in " + "the Info.plist file in " + f);
    }
    return appId.toString();
}
Also used : ZipFile(java.util.zip.ZipFile) NSDictionary(com.dd.plist.NSDictionary) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) FileNotFoundException(java.io.FileNotFoundException) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) ZipFile(java.util.zip.ZipFile) File(java.io.File) NSString(com.dd.plist.NSString) TimeoutException(java.util.concurrent.TimeoutException) InterruptedIOException(java.io.InterruptedIOException) LibIMobileDeviceException(org.robovm.libimobiledevice.LibIMobileDeviceException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 29 with NSDictionary

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

the class InstallationProxyClientTest method testBrowse.

@Test
public void testBrowse() throws Exception {
    NSArray array = client.browse();
    NSDictionary safari = null;
    for (int i = 0; i < array.count(); i++) {
        NSDictionary dict = (NSDictionary) array.objectAtIndex(i);
        NSObject v = dict.objectForKey("CFBundleIdentifier");
        if (v != null && "com.apple.mobilesafari".equals(v.toString())) {
            safari = dict;
        }
    }
    assertNotNull(safari);
}
Also used : NSObject(com.dd.plist.NSObject) NSArray(com.dd.plist.NSArray) NSDictionary(com.dd.plist.NSDictionary) Test(org.junit.Test)

Example 30 with NSDictionary

use of com.dd.plist.NSDictionary 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)

Aggregations

NSDictionary (com.dd.plist.NSDictionary)70 NSString (com.dd.plist.NSString)33 NSObject (com.dd.plist.NSObject)22 IOException (java.io.IOException)16 Test (org.junit.Test)15 File (java.io.File)13 NSArray (com.dd.plist.NSArray)12 Path (java.nio.file.Path)11 InputStream (java.io.InputStream)8 NSNumber (com.dd.plist.NSNumber)7 PBXBuildFile (com.facebook.buck.apple.xcode.xcodeproj.PBXBuildFile)6 PBXFileReference (com.facebook.buck.apple.xcode.xcodeproj.PBXFileReference)6 ImmutableMap (com.google.common.collect.ImmutableMap)6 BufferedInputStream (java.io.BufferedInputStream)6 SourceTreePath (com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath)4 NoSuchFileException (java.nio.file.NoSuchFileException)4 PropertyListFormatException (com.dd.plist.PropertyListFormatException)3 ExecutionContext (com.facebook.buck.step.ExecutionContext)3 TestExecutionContext (com.facebook.buck.step.TestExecutionContext)3 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)3