Search in sources :

Example 1 with NSObject

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

the class AppleToolchainDiscovery method toolchainFromPlist.

private static Optional<AppleToolchain> toolchainFromPlist(Path toolchainDir, String plistName) throws IOException {
    Path toolchainInfoPlistPath = toolchainDir.resolve(plistName);
    InputStream toolchainInfoPlist = Files.newInputStream(toolchainInfoPlistPath);
    BufferedInputStream bufferedToolchainInfoPlist = new BufferedInputStream(toolchainInfoPlist);
    NSDictionary parsedToolchainInfoPlist;
    try {
        parsedToolchainInfoPlist = (NSDictionary) PropertyListParser.parse(bufferedToolchainInfoPlist);
    } catch (PropertyListFormatException | ParseException | ParserConfigurationException | SAXException e) {
        LOG.error(e, "Failed to parse %s: %s, ignoring", plistName, toolchainInfoPlistPath);
        return Optional.empty();
    }
    NSObject identifierObject = parsedToolchainInfoPlist.objectForKey("Identifier");
    if (identifierObject == null) {
        LOG.error("Identifier not found for toolchain path %s, ignoring", toolchainDir);
        return Optional.empty();
    }
    String identifier = identifierObject.toString();
    NSObject versionObject = parsedToolchainInfoPlist.objectForKey("DTSDKBuild");
    Optional<String> version = versionObject == null ? Optional.empty() : Optional.of(versionObject.toString());
    LOG.debug("Mapped SDK identifier %s to path %s", identifier, toolchainDir);
    AppleToolchain.Builder toolchainBuilder = AppleToolchain.builder();
    toolchainBuilder.setIdentifier(identifier);
    toolchainBuilder.setVersion(version);
    toolchainBuilder.setPath(toolchainDir);
    return Optional.of(toolchainBuilder.build());
}
Also used : Path(java.nio.file.Path) NSObject(com.dd.plist.NSObject) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) NSDictionary(com.dd.plist.NSDictionary) SAXException(org.xml.sax.SAXException) PropertyListFormatException(com.dd.plist.PropertyListFormatException) BufferedInputStream(java.io.BufferedInputStream) ParseException(java.text.ParseException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 2 with NSObject

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

the class ProvisioningProfileStore method getBestProvisioningProfile.

// If multiple valid ones, find the one which matches the most specifically.  I.e.,
// XXXXXXXXXX.com.example.* will match over XXXXXXXXXX.* for com.example.TestApp
public Optional<ProvisioningProfileMetadata> getBestProvisioningProfile(String bundleID, ApplePlatform platform, Optional<ImmutableMap<String, NSObject>> entitlements, Optional<? extends Iterable<CodeSignIdentity>> identities) {
    final Optional<String> prefix;
    if (entitlements.isPresent()) {
        prefix = ProvisioningProfileMetadata.prefixFromEntitlements(entitlements.get());
    } else {
        prefix = Optional.empty();
    }
    int bestMatchLength = -1;
    Optional<ProvisioningProfileMetadata> bestMatch = Optional.empty();
    for (ProvisioningProfileMetadata profile : getProvisioningProfiles()) {
        if (profile.getExpirationDate().after(new Date())) {
            Pair<String, String> appID = profile.getAppID();
            LOG.debug("Looking at provisioning profile " + profile.getUUID() + "," + appID.toString());
            if (!prefix.isPresent() || prefix.get().equals(appID.getFirst())) {
                String profileBundleID = appID.getSecond();
                boolean match;
                if (profileBundleID.endsWith("*")) {
                    // Chop the ending * if wildcard.
                    profileBundleID = profileBundleID.substring(0, profileBundleID.length() - 1);
                    match = bundleID.startsWith(profileBundleID);
                } else {
                    match = (bundleID.equals(profileBundleID));
                }
                if (!match) {
                    LOG.debug("Ignoring non-matching ID for profile " + profile.getUUID() + ".  Expected: " + profileBundleID + ", actual: " + bundleID);
                    continue;
                }
                Optional<String> platformName = platform.getProvisioningProfileName();
                if (platformName.isPresent() && !profile.getPlatforms().contains(platformName.get())) {
                    LOG.debug("Ignoring incompatible platform " + platformName.get() + " for profile " + profile.getUUID());
                    continue;
                }
                // For example: get-task-allow, aps-environment, etc.
                if (entitlements.isPresent()) {
                    ImmutableMap<String, NSObject> entitlementsDict = entitlements.get();
                    ImmutableMap<String, NSObject> profileEntitlements = profile.getEntitlements();
                    for (Entry<String, NSObject> entry : entitlementsDict.entrySet()) {
                        if (!(entry.getKey().equals("keychain-access-groups") || entry.getKey().equals("application-identifier") || entry.getKey().equals("com.apple.developer.associated-domains") || matchesOrArrayIsSubsetOf(entry.getValue(), profileEntitlements.get(entry.getKey())))) {
                            match = false;
                            LOG.debug("Ignoring profile " + profile.getUUID() + " with mismatched entitlement " + entry.getKey() + "; value is " + profileEntitlements.get(entry.getKey()) + " but expected " + entry.getValue());
                            break;
                        }
                    }
                }
                // Reject any certificate which we know we can't sign with the supplied identities.
                ImmutableSet<HashCode> validFingerprints = profile.getDeveloperCertificateFingerprints();
                if (match && identities.isPresent() && !validFingerprints.isEmpty()) {
                    match = false;
                    for (CodeSignIdentity identity : identities.get()) {
                        Optional<HashCode> fingerprint = identity.getFingerprint();
                        if (fingerprint.isPresent() && validFingerprints.contains(fingerprint.get())) {
                            match = true;
                            break;
                        }
                    }
                    if (!match) {
                        LOG.debug("Ignoring profile " + profile.getUUID() + " because it can't be signed with any valid identity in the current keychain.");
                        continue;
                    }
                }
                if (match && profileBundleID.length() > bestMatchLength) {
                    bestMatchLength = profileBundleID.length();
                    bestMatch = Optional.of(profile);
                }
            }
        } else {
            LOG.debug("Ignoring expired profile " + profile.getUUID());
        }
    }
    LOG.debug("Found provisioning profile " + bestMatch.toString());
    return bestMatch;
}
Also used : NSObject(com.dd.plist.NSObject) Date(java.util.Date) HashCode(com.google.common.hash.HashCode)

Example 3 with NSObject

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

the class ProvisioningProfileCopyStepTest method testNoEntitlementsDoesNotMergeInvalidProfileKeys.

@Test
public void testNoEntitlementsDoesNotMergeInvalidProfileKeys() 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.empty(), ProvisioningProfileStore.fromSearchPath(new DefaultProcessExecutor(new TestConsole()), ProvisioningProfileStore.DEFAULT_READ_COMMAND, testdataDir), outputFile, xcentFile, codeSignIdentityStore, 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"));
}
Also used : NSObject(com.dd.plist.NSObject) DefaultProcessExecutor(com.facebook.buck.util.DefaultProcessExecutor) NSDictionary(com.dd.plist.NSDictionary) NSString(com.dd.plist.NSString) TestConsole(com.facebook.buck.testutil.TestConsole) Test(org.junit.Test)

Example 4 with NSObject

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

the class ProvisioningProfileStoreTest method testEntitlementKeysAreMatched.

@Test
public void testEntitlementKeysAreMatched() throws Exception {
    final NSString[] fakeKeychainAccessGroups = { new NSString("AAAAAAAAAA.*") };
    final NSArray fakeKeychainAccessGroupsArray = new NSArray(fakeKeychainAccessGroups);
    ImmutableMap<String, NSObject> fakeDevelopmentEntitlements = ImmutableMap.of("keychain-access-groups", fakeKeychainAccessGroupsArray, "aps-environment", new NSString("development"), "com.apple.security.application-groups", new NSArray(new NSString("foo"), new NSString("bar")));
    ImmutableMap<String, NSObject> fakeProductionEntitlements = ImmutableMap.of("keychain-access-groups", fakeKeychainAccessGroupsArray, "aps-environment", new NSString("production"), "com.apple.security.application-groups", new NSArray(new NSString("foo"), new NSString("bar"), new NSString("baz")));
    ProvisioningProfileMetadata expected = makeTestMetadata("AAAAAAAAAA.com.facebook.test", new Date(Long.MAX_VALUE), "11111111-1111-1111-1111-111111111111", fakeProductionEntitlements);
    ProvisioningProfileStore profiles = ProvisioningProfileStore.fromProvisioningProfiles(ImmutableList.of(makeTestMetadata("AAAAAAAAAA.com.facebook.test", new Date(Long.MAX_VALUE), "00000000-0000-0000-0000-000000000000", fakeDevelopmentEntitlements), expected));
    Optional<ProvisioningProfileMetadata> actual = profiles.getBestProvisioningProfile("com.facebook.test", ApplePlatform.IPHONEOS, Optional.of(ImmutableMap.of("keychain-access-groups", fakeKeychainAccessGroupsArray, "aps-environment", new NSString("production"), "com.apple.security.application-groups", new NSArray(new NSString("foo"), new NSString("bar")))), ProvisioningProfileStore.MATCH_ANY_IDENTITY);
    assertThat(actual.get(), is(equalTo(expected)));
    actual = profiles.getBestProvisioningProfile("com.facebook.test", ApplePlatform.IPHONEOS, Optional.of(ImmutableMap.of("keychain-access-groups", fakeKeychainAccessGroupsArray, "aps-environment", new NSString("production"), "com.apple.security.application-groups", new NSArray(new NSString("foo"), new NSString("xxx")))), ProvisioningProfileStore.MATCH_ANY_IDENTITY);
    assertFalse(actual.isPresent());
    // Test without keychain access groups.
    actual = profiles.getBestProvisioningProfile("com.facebook.test", ApplePlatform.IPHONEOS, Optional.of(ImmutableMap.of("aps-environment", new NSString("production"), "com.apple.security.application-groups", new NSArray(new NSString("foo"), new NSString("bar")))), ProvisioningProfileStore.MATCH_ANY_IDENTITY);
    assertThat(actual.get(), is(equalTo(expected)));
    actual = profiles.getBestProvisioningProfile("com.facebook.test", ApplePlatform.IPHONEOS, Optional.of(ImmutableMap.of("aps-environment", new NSString("production"), "com.apple.security.application-groups", new NSArray(new NSString("foo"), new NSString("xxx")))), ProvisioningProfileStore.MATCH_ANY_IDENTITY);
    assertFalse(actual.isPresent());
}
Also used : NSObject(com.dd.plist.NSObject) NSArray(com.dd.plist.NSArray) NSString(com.dd.plist.NSString) NSString(com.dd.plist.NSString) Date(java.util.Date) Test(org.junit.Test)

Example 5 with NSObject

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

the class WorkspaceGeneratorTest method workspaceDisablesSchemeAutoCreation.

@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((NSNumber) autocreate, equalTo(new NSNumber(false)));
}
Also used : Path(java.nio.file.Path) Matchers.hasXPath(org.hamcrest.Matchers.hasXPath) NSNumber(com.dd.plist.NSNumber) NSObject(com.dd.plist.NSObject) NSDictionary(com.dd.plist.NSDictionary) Test(org.junit.Test)

Aggregations

NSObject (com.dd.plist.NSObject)29 NSDictionary (com.dd.plist.NSDictionary)22 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