Java Code Examples for com.dd.plist.PropertyListParser#parse()

The following examples show how to use com.dd.plist.PropertyListParser#parse() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProvisioningProfileCopyStepTest.java    From buck with Apache License 2.0 6 votes vote down vote up
@Test
public void testApplicationIdentifierNotInInfoPlistForWatchOSApps() throws Exception {
  assumeTrue(Platform.detect() == Platform.MACOS);
  Path infoPlistPath = testdataDir.resolve("Info_WatchOS.plist");
  ProvisioningProfileCopyStep step =
      new ProvisioningProfileCopyStep(
          projectFilesystem,
          infoPlistPath,
          ApplePlatform.IPHONEOS,
          Optional.empty(),
          Optional.empty(),
          ProvisioningProfileStoreFactory.fromSearchPath(
              new DefaultProcessExecutor(new TestConsole()), FAKE_READ_COMMAND, testdataDir),
          outputFile,
          xcentFile,
          codeSignIdentitiesSupplier,
          Optional.empty());
  step.execute(executionContext);

  byte[] infoPlistContents = projectFilesystem.getFileBytes(infoPlistPath);
  NSDictionary infoPlist = (NSDictionary) PropertyListParser.parse(infoPlistContents);
  assertNull(infoPlist.get("ApplicationIdentifier"));
}
 
Example 2
Source File: ProvisioningProfileCopyStepTest.java    From buck with Apache License 2.0 6 votes vote down vote up
@Test
public void testApplicationIdentifierNotInInfoPlistForFrameworks() throws Exception {
  assumeTrue(Platform.detect() == Platform.MACOS);
  Path infoPlistPath = testdataDir.resolve("Info_Framework.plist");
  ProvisioningProfileCopyStep step =
      new ProvisioningProfileCopyStep(
          projectFilesystem,
          infoPlistPath,
          ApplePlatform.IPHONEOS,
          Optional.empty(),
          Optional.empty(),
          ProvisioningProfileStoreFactory.fromSearchPath(
              new DefaultProcessExecutor(new TestConsole()), FAKE_READ_COMMAND, testdataDir),
          outputFile,
          xcentFile,
          codeSignIdentitiesSupplier,
          Optional.empty());
  step.execute(executionContext);

  byte[] infoPlistContents = projectFilesystem.getFileBytes(infoPlistPath);
  NSDictionary infoPlist = (NSDictionary) PropertyListParser.parse(infoPlistContents);
  assertNull(infoPlist.get("ApplicationIdentifier"));
}
 
Example 3
Source File: WorkspaceGeneratorTest.java    From buck with Apache License 2.0 6 votes vote down vote up
@Test
public void workspaceEnabledForLegacyBuildSystem() throws Exception {
  AppleConfig appleConfig =
      FakeBuckConfig.builder()
          .setSections("[apple]", "use_modern_build_system = false")
          .build()
          .getView(AppleConfig.class);

  WorkspaceGenerator generator =
      new WorkspaceGenerator(projectFilesystem, "ws", Paths.get("."), appleConfig);

  Path workspacePath = generator.writeWorkspace();
  Optional<String> settings =
      projectFilesystem.readFileIfItExists(
          workspacePath.resolve("xcshareddata/WorkspaceSettings.xcsettings"));
  assertThat(settings.isPresent(), equalTo(true));
  NSObject object = PropertyListParser.parse(settings.get().getBytes(Charsets.UTF_8));
  assertThat(object, instanceOf(NSDictionary.class));
  NSObject buildSystemType = ((NSDictionary) object).get("BuildSystemType");
  assertThat(buildSystemType, instanceOf(NSString.class));
  assertThat(buildSystemType, equalTo(new NSString("Original")));
}
 
Example 4
Source File: InflatableData.java    From InflatableDonkey with MIT License 6 votes vote down vote up
public static Optional<InflatableData> from(byte[] bs) {
    InflatableData data;
    try {
        NSDictionary parse = (NSDictionary) PropertyListParser.parse(bs);
        byte[] escrowedKeys = ((NSData) parse.get("escrowedKeys")).bytes();
        UUID deviceUuid = UUID.fromString(((NSString) parse.get("deviceUuid")).getContent());
        String deviceHardWareId = ((NSString) parse.get("deviceHardWareId")).getContent();
        data = new InflatableData(escrowedKeys, deviceUuid, deviceHardWareId);

    } catch (ClassCastException | IllegalArgumentException | IOException | NullPointerException
            | PropertyListFormatException | ParseException | ParserConfigurationException | SAXException ex) {
        logger.warn("-- from() - exception: ", ex);
        data = null;
    }
    return Optional.ofNullable(data);
}
 
Example 5
Source File: PropertyListResponseHandler.java    From InflatableDonkey with MIT License 6 votes vote down vote up
@Override
public T handleEntity(HttpEntity entity) throws IOException {
    NSObject nsObject;

    try {
        // Avoiding PropertyListParser#parse(InputStream) as the current Maven build (1.16) can bug out.
        nsObject = PropertyListParser.parse(EntityUtils.toByteArray(entity));

    } catch (PropertyListFormatException | ParseException | ParserConfigurationException | SAXException ex) {
        throw new BadDataException("failed to parse property list", ex);
    }

    if (to.isAssignableFrom(nsObject.getClass())) {
        return to.cast(nsObject);
    }

    throw new BadDataException("failed to cast property list: " + nsObject.getClass());
}
 
Example 6
Source File: ProvisioningProfileCopyStepTest.java    From buck with Apache License 2.0 6 votes vote down vote up
@Test
public void testApplicationIdentifierIsInInfoPlist() throws Exception {
  assumeTrue(Platform.detect() == Platform.MACOS);
  Path infoPlistPath = testdataDir.resolve("Info.plist");
  ProvisioningProfileCopyStep step =
      new ProvisioningProfileCopyStep(
          projectFilesystem,
          infoPlistPath,
          ApplePlatform.IPHONEOS,
          Optional.empty(),
          Optional.empty(),
          ProvisioningProfileStoreFactory.fromSearchPath(
              new DefaultProcessExecutor(new TestConsole()), FAKE_READ_COMMAND, testdataDir),
          outputFile,
          xcentFile,
          codeSignIdentitiesSupplier,
          Optional.empty());
  step.execute(executionContext);

  byte[] infoPlistContents = projectFilesystem.getFileBytes(infoPlistPath);
  NSDictionary infoPlist = (NSDictionary) PropertyListParser.parse(infoPlistContents);
  assertEquals(
      infoPlist.get("ApplicationIdentifier"), new NSString("ABCDE12345.com.example.TestApp"));
}
 
Example 7
Source File: DdPlistTest.java    From buck with Apache License 2.0 5 votes vote down vote up
@Test
public void testXMLWriting() throws Exception {
  InputStream in = getClass().getResourceAsStream("test-files/test1.plist");
  NSDictionary x = (NSDictionary) PropertyListParser.parse(in);
  PropertyListParser.saveAsXML(x, outputFile);
  NSDictionary y = (NSDictionary) PropertyListParser.parse(outputFile);
  assertEquals(x, y);
}
 
Example 8
Source File: IpaLoader.java    From unidbg with Apache License 2.0 5 votes vote down vote up
private static String parseExecutable(File ipa, String appDir) throws IOException {
    try {
        byte[] data = loadZip(ipa, appDir + "Info.plist");
        if (data == null) {
            throw new IllegalStateException("Find Info.plist failed");
        }
        NSDictionary info = (NSDictionary) PropertyListParser.parse(data);
        NSString bundleExecutable = (NSString) info.get("CFBundleExecutable");
        return bundleExecutable.getContent();
    } catch (PropertyListFormatException | ParseException | ParserConfigurationException | SAXException e) {
        throw new IllegalStateException("load ipa failed", e);
    }
}
 
Example 9
Source File: WorkspaceGeneratorTest.java    From buck with Apache License 2.0 5 votes vote down vote up
@Test
public void workspaceDisablesSchemeAutoCreation() throws Exception {
  Path workspacePath = generator.writeWorkspace();
  Optional<String> settings =
      projectFilesystem.readFileIfItExists(
          workspacePath.resolve("xcshareddata/WorkspaceSettings.xcsettings"));
  assertThat(settings.isPresent(), equalTo(true));
  NSObject object = PropertyListParser.parse(settings.get().getBytes(Charsets.UTF_8));
  assertThat(object, instanceOf(NSDictionary.class));
  NSObject autocreate =
      ((NSDictionary) object).get("IDEWorkspaceSharedSettings_AutocreateContextsIfNeeded");
  assertThat(autocreate, instanceOf(NSNumber.class));
  assertThat(autocreate, equalTo(new NSNumber(false)));
}
 
Example 10
Source File: AppleBundleIntegrationTest.java    From buck with Apache License 2.0 5 votes vote down vote up
@Test
public void infoPlistSubstitutionsAreApplied() throws Exception {
  ProjectWorkspace workspace =
      TestDataHelper.createProjectWorkspaceForScenario(
          this, "application_bundle_with_substitutions", tmp);
  workspace.setUp();

  BuildTarget target = workspace.newBuildTarget("//:DemoApp#iphonesimulator-x86_64,no-debug");
  workspace.runBuckCommand("build", target.getFullyQualifiedName()).assertSuccess();

  workspace.verify(
      Paths.get("DemoApp_output.expected"),
      BuildTargetPaths.getGenPath(
          filesystem,
          target.withAppendedFlavors(AppleDescriptions.NO_INCLUDE_FRAMEWORKS_FLAVOR),
          "%s"));

  Path appPath =
      BuildTargetPaths.getGenPath(
              filesystem,
              target.withAppendedFlavors(AppleDescriptions.NO_INCLUDE_FRAMEWORKS_FLAVOR),
              "%s")
          .resolve(target.getShortName() + ".app");
  assertTrue(Files.exists(workspace.getPath(appPath.resolve(target.getShortName()))));

  NSDictionary plist =
      (NSDictionary)
          PropertyListParser.parse(
              Files.readAllBytes(workspace.getPath(appPath.resolve("Info.plist"))));
  assertThat(
      "Should contain xcode build version",
      (String) plist.get("DTXcodeBuild").toJavaObject(),
      not(emptyString()));
}
 
Example 11
Source File: IPAModifyPlist.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
private void readPlist() {
	try {
		File file = new File(this.plistFile);
		this.rootDict = ((NSDictionary) PropertyListParser.parse(file));
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
Example 12
Source File: PropertyLists.java    From LiquidDonkey with MIT License 5 votes vote down vote up
static <T> T parse(byte[] data) throws BadDataException {
    try {
        return (T) PropertyListParser.parse(data);

    } catch (ClassCastException |
            IOException |
            PropertyListFormatException |
            ParseException |
            ParserConfigurationException |
            SAXException ex) {

        throw new BadDataException("Failed to parse property list", ex);
    }
}
 
Example 13
Source File: NSDictionaries.java    From InflatableDonkey with MIT License 5 votes vote down vote up
static Optional<NSObject> parseNSObject(byte[] data) {
    try {
        NSObject nsObject = PropertyListParser.parse(data);
        return Optional.of(nsObject);

    } catch (IOException | PropertyListFormatException | ParseException | ParserConfigurationException |
            SAXException ex) {
        logger.warn("-- parseNSObject() - failed to parse data: {} 0x{}", ex.getMessage(), Hex.toHexString(data));
        return Optional.empty();
    }
}
 
Example 14
Source File: PListsLegacy.java    From InflatableDonkey with MIT License 5 votes vote down vote up
public static Optional<NSObject> parse(byte[] data) {
    try {
        NSObject nsObject = PropertyListParser.parse(data);
        return Optional.of(nsObject);

    } catch (IOException | PropertyListFormatException | ParseException | ParserConfigurationException | SAXException ex) {
        logger.warn("-- parse() - failed to parse NSObject data: 0x{}", Hex.toHexString(data));
        return Optional.empty();
    }
}
 
Example 15
Source File: Accounts.java    From InflatableDonkey with MIT License 5 votes vote down vote up
public static Account account(byte[] bs) {
    try {
        NSDictionary dict = (NSDictionary) PropertyListParser.parse(bs);
        return account(dict);
    } catch (IOException | PropertyListFormatException | ParseException | ParserConfigurationException | SAXException ex) {
        throw new IllegalArgumentException(ex);
    }
}
 
Example 16
Source File: EntryHelper.java    From narrate-android with Apache License 2.0 5 votes vote down vote up
public static Entry parse(File file) {
    LogUtil.log("EntryUtil", "parse(File)");

    try {

        NSDictionary rootDict = (NSDictionary) PropertyListParser.parse(file);
        LogUtil.log("EntryUtil", "NSDictionary: " + rootDict.toXMLPropertyList());
        return fromDictionary(rootDict);

    } catch (Exception e) {
        LogUtil.e("EntryUtil", "Exception in parse: ", e);
        return null;
    }
}
 
Example 17
Source File: ProvisioningProfileCopyStepTest.java    From buck with Apache License 2.0 5 votes vote down vote up
@Test
public void testEntitlementsDoesNotMergeInvalidProfileKeys() throws Exception {
  assumeTrue(Platform.detect() == Platform.MACOS);
  ProvisioningProfileCopyStep step =
      new ProvisioningProfileCopyStep(
          projectFilesystem,
          testdataDir.resolve("Info.plist"),
          ApplePlatform.IPHONEOS,
          Optional.of("00000000-0000-0000-0000-000000000000"),
          Optional.of(entitlementsFile),
          ProvisioningProfileStoreFactory.fromSearchPath(
              new DefaultProcessExecutor(new TestConsole()), FAKE_READ_COMMAND, testdataDir),
          outputFile,
          xcentFile,
          codeSignIdentitiesSupplier,
          Optional.empty());
  step.execute(executionContext);

  ProvisioningProfileMetadata selectedProfile =
      step.getSelectedProvisioningProfileFuture().get().get();
  ImmutableMap<String, NSObject> profileEntitlements = selectedProfile.getEntitlements();
  assertTrue(
      profileEntitlements.containsKey(
          "com.apple.developer.icloud-container-development-container-identifiers"));

  Optional<String> xcentContents = projectFilesystem.readFileIfItExists(xcentFile);
  assertTrue(xcentContents.isPresent());
  NSDictionary xcentPlist =
      (NSDictionary) PropertyListParser.parse(xcentContents.get().getBytes());
  assertFalse(
      xcentPlist.containsKey(
          "com.apple.developer.icloud-container-development-container-identifiers"));
  assertEquals(
      xcentPlist.get("com.apple.developer.team-identifier"),
      profileEntitlements.get("com.apple.developer.team-identifier"));
}
 
Example 18
Source File: AirPlayAuth.java    From AirPlayAuth with MIT License 5 votes vote down vote up
private PairSetupPin2Response doPairSetupPin2(Socket socket, final byte[] publicClientValueA, final byte[] clientEvidenceMessageM1) throws Exception {
    byte[] pairSetupPinRequestData = AuthUtils.createPList(new HashMap<String, byte[]>() {{
        put("pk", publicClientValueA);
        put("proof", clientEvidenceMessageM1);
    }});

    byte[] pairSetupPin2ResponseBytes = AuthUtils.postData(socket, "/pair-setup-pin", "application/x-apple-binary-plist", pairSetupPinRequestData);

    NSDictionary pairSetupPin2Response = (NSDictionary) PropertyListParser.parse(pairSetupPin2ResponseBytes);
    if (pairSetupPin2Response.containsKey("proof")) {
        byte[] proof = ((NSData) pairSetupPin2Response.get("proof")).bytes();
        return new PairSetupPin2Response(proof);
    }
    throw new Exception();
}
 
Example 19
Source File: IpaLoader.java    From unidbg with Apache License 2.0 5 votes vote down vote up
private static String parseCFBundleIdentifier(File ipa, String appDir) throws IOException {
    try {
        byte[] data = loadZip(ipa, appDir + "Info.plist");
        if (data == null) {
            throw new IllegalStateException("Find Info.plist failed");
        }
        NSDictionary info = (NSDictionary) PropertyListParser.parse(data);
        NSString bundleIdentifier = (NSString) info.get("CFBundleIdentifier");
        return bundleIdentifier.getContent();
    } catch (PropertyListFormatException | ParseException | ParserConfigurationException | SAXException e) {
        throw new IllegalStateException("load ipa failed", e);
    }
}
 
Example 20
Source File: ProvisioningProfileCopyStepTest.java    From buck with Apache License 2.0 5 votes vote down vote up
@Test
public void testEntitlementsMergesValidProfileKeys() throws Exception {
  assumeTrue(Platform.detect() == Platform.MACOS);
  ProvisioningProfileCopyStep step =
      new ProvisioningProfileCopyStep(
          projectFilesystem,
          testdataDir.resolve("Info.plist"),
          ApplePlatform.IPHONEOS,
          Optional.of("00000000-0000-0000-0000-000000000000"),
          Optional.of(entitlementsFile),
          ProvisioningProfileStoreFactory.fromSearchPath(
              new DefaultProcessExecutor(new TestConsole()), FAKE_READ_COMMAND, testdataDir),
          outputFile,
          xcentFile,
          codeSignIdentitiesSupplier,
          Optional.empty());
  step.execute(executionContext);

  ProvisioningProfileMetadata selectedProfile =
      step.getSelectedProvisioningProfileFuture().get().get();
  ImmutableMap<String, NSObject> profileEntitlements = selectedProfile.getEntitlements();
  assertTrue(profileEntitlements.containsKey("get-task-allow"));

  Optional<String> entitlementsContents = projectFilesystem.readFileIfItExists(entitlementsFile);
  assertTrue(entitlementsContents.isPresent());
  NSDictionary entitlementsPlist =
      (NSDictionary) PropertyListParser.parse(entitlementsContents.get().getBytes());
  assertFalse(entitlementsPlist.containsKey("get-task-allow"));

  Optional<String> xcentContents = projectFilesystem.readFileIfItExists(xcentFile);
  assertTrue(xcentContents.isPresent());
  NSDictionary xcentPlist =
      (NSDictionary) PropertyListParser.parse(xcentContents.get().getBytes());
  assertTrue(xcentPlist.containsKey("get-task-allow"));
}