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());
}
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;
}
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"));
}
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());
}
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)));
}
Aggregations