use of com.dd.plist.NSDictionary in project buck by facebook.
the class AppleCxxPlatformsTest method platformVersionPlistWithMissingFieldIsLogged.
@Test
public void platformVersionPlistWithMissingFieldIsLogged() throws Exception {
Path tempRoot = temp.getRoot();
Path platformRoot = tempRoot.resolve("Platforms/iPhoneOS.platform");
Files.createDirectories(platformRoot);
Files.write(platformRoot.resolve("version.plist"), new NSDictionary().toXMLPropertyList().getBytes(Charsets.UTF_8));
AppleCxxPlatform platform = buildAppleCxxPlatform(tempRoot);
assertThat(platform.getBuildVersion(), equalTo(Optional.empty()));
assertThat(logSink.getRecords(), hasItem(TestLogSink.logRecordWithMessage(matchesPattern(".*missing ProductBuildVersion. Build version will be unset.*"))));
}
use of com.dd.plist.NSDictionary in project buck by facebook.
the class ProvisioningProfileCopyStepTest method testEntitlementsDoesNotMergeInvalidProfileKeys.
@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), 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.NSDictionary in project buck by facebook.
the class AbstractProvisioningProfileMetadata method fromProvisioningProfilePath.
public static ProvisioningProfileMetadata fromProvisioningProfilePath(ProcessExecutor executor, ImmutableList<String> readCommand, Path profilePath) throws IOException, InterruptedException {
Set<ProcessExecutor.Option> options = EnumSet.of(ProcessExecutor.Option.EXPECTING_STD_OUT);
// Extract the XML from its signed message wrapper.
ProcessExecutorParams processExecutorParams = ProcessExecutorParams.builder().addAllCommand(readCommand).addCommand(profilePath.toString()).build();
ProcessExecutor.Result result;
result = executor.launchAndExecute(processExecutorParams, options, /* stdin */
Optional.empty(), /* timeOutMs */
Optional.empty(), /* timeOutHandler */
Optional.empty());
if (result.getExitCode() != 0) {
throw new IOException(result.getMessageForResult("Invalid provisioning profile: " + profilePath));
}
try {
NSDictionary plist = (NSDictionary) PropertyListParser.parse(result.getStdout().get().getBytes());
Date expirationDate = ((NSDate) plist.get("ExpirationDate")).getDate();
String uuid = ((NSString) plist.get("UUID")).getContent();
ImmutableSet.Builder<HashCode> certificateFingerprints = ImmutableSet.builder();
NSArray certificates = (NSArray) plist.get("DeveloperCertificates");
HashFunction hasher = Hashing.sha1();
if (certificates != null) {
for (NSObject item : certificates.getArray()) {
certificateFingerprints.add(hasher.hashBytes(((NSData) item).bytes()));
}
}
ImmutableMap.Builder<String, NSObject> builder = ImmutableMap.builder();
NSDictionary entitlements = ((NSDictionary) plist.get("Entitlements"));
for (String key : entitlements.keySet()) {
builder = builder.put(key, entitlements.objectForKey(key));
}
String appID = entitlements.get("application-identifier").toString();
ProvisioningProfileMetadata.Builder provisioningProfileMetadata = ProvisioningProfileMetadata.builder();
if (plist.get("Platform") != null) {
for (Object platform : (Object[]) plist.get("Platform").toJavaObject()) {
provisioningProfileMetadata.addPlatforms((String) platform);
}
}
return provisioningProfileMetadata.setAppID(ProvisioningProfileMetadata.splitAppID(appID)).setExpirationDate(expirationDate).setUUID(uuid).setProfilePath(profilePath).setEntitlements(builder.build()).setDeveloperCertificateFingerprints(certificateFingerprints.build()).build();
} catch (Exception e) {
throw new IllegalArgumentException("Malformed embedded plist: " + e);
}
}
use of com.dd.plist.NSDictionary in project buck by facebook.
the class CodeSignStep method execute.
@Override
public StepExecutionResult execute(ExecutionContext context) throws InterruptedException {
if (dryRunResultsPath.isPresent()) {
try {
NSDictionary dryRunResult = new NSDictionary();
dryRunResult.put("relative-path-to-sign", dryRunResultsPath.get().getParent().relativize(pathToSign).toString());
dryRunResult.put("use-entitlements", pathToSigningEntitlements.isPresent());
dryRunResult.put("identity", getIdentityArg(codeSignIdentitySupplier.get()));
filesystem.writeContentsToPath(dryRunResult.toXMLPropertyList(), dryRunResultsPath.get());
return StepExecutionResult.SUCCESS;
} catch (IOException e) {
context.logError(e, "Failed when trying to write dry run results: %s", getDescription(context));
return StepExecutionResult.ERROR;
}
}
ProcessExecutorParams.Builder paramsBuilder = ProcessExecutorParams.builder();
if (codesignAllocatePath.isPresent()) {
ImmutableList<String> commandPrefix = codesignAllocatePath.get().getCommandPrefix(resolver);
paramsBuilder.setEnvironment(ImmutableMap.of("CODESIGN_ALLOCATE", Joiner.on(" ").join(commandPrefix)));
}
ImmutableList.Builder<String> commandBuilder = ImmutableList.builder();
commandBuilder.addAll(codesign.getCommandPrefix(resolver));
commandBuilder.add("--force", "--sign", getIdentityArg(codeSignIdentitySupplier.get()));
if (pathToSigningEntitlements.isPresent()) {
commandBuilder.add("--entitlements", pathToSigningEntitlements.get().toString());
}
commandBuilder.add(pathToSign.toString());
ProcessExecutorParams processExecutorParams = paramsBuilder.setCommand(commandBuilder.build()).setDirectory(filesystem.getRootPath()).build();
// Must specify that stdout is expected or else output may be wrapped in Ansi escape chars.
Set<ProcessExecutor.Option> options = EnumSet.of(ProcessExecutor.Option.EXPECTING_STD_OUT);
ProcessExecutor.Result result;
try {
ProcessExecutor processExecutor = context.getProcessExecutor();
result = processExecutor.launchAndExecute(processExecutorParams, options, /* stdin */
Optional.empty(), /* timeOutMs */
Optional.empty(), /* timeOutHandler */
Optional.empty());
} catch (InterruptedException | IOException e) {
context.logError(e, "Could not execute codesign.");
return StepExecutionResult.ERROR;
}
if (result.getExitCode() != 0) {
return StepExecutionResult.of(result);
}
return StepExecutionResult.SUCCESS;
}
use of com.dd.plist.NSDictionary in project buck by facebook.
the class PlistProcessStep method execute.
@Override
public StepExecutionResult execute(ExecutionContext context) throws InterruptedException {
try (InputStream stream = filesystem.newFileInputStream(input);
BufferedInputStream bufferedStream = new BufferedInputStream(stream)) {
NSObject infoPlist;
try {
infoPlist = PropertyListParser.parse(bufferedStream);
} catch (Exception e) {
throw new IOException(input.toString() + ": " + e);
}
if (infoPlist instanceof NSDictionary) {
NSDictionary dictionary = (NSDictionary) infoPlist;
if (additionalInputToMerge.isPresent()) {
try (InputStream mergeStream = filesystem.newFileInputStream(additionalInputToMerge.get());
BufferedInputStream mergeBufferedStream = new BufferedInputStream(mergeStream)) {
NSObject mergeInfoPlist;
try {
mergeInfoPlist = PropertyListParser.parse(mergeBufferedStream);
} catch (Exception e) {
throw new IOException(additionalInputToMerge.toString() + ": " + e);
}
dictionary.putAll(((NSDictionary) mergeInfoPlist).getHashMap());
}
}
for (ImmutableMap.Entry<String, NSObject> entry : additionalKeys.entrySet()) {
if (!dictionary.containsKey(entry.getKey())) {
dictionary.put(entry.getKey(), entry.getValue());
}
}
dictionary.putAll(overrideKeys);
}
switch(this.outputFormat) {
case XML:
String serializedInfoPlist = infoPlist.toXMLPropertyList();
filesystem.writeContentsToPath(serializedInfoPlist, output);
break;
case BINARY:
byte[] binaryInfoPlist = BinaryPropertyListWriter.writeToArray(infoPlist);
filesystem.writeBytesToPath(binaryInfoPlist, output);
break;
}
} catch (IOException e) {
context.logError(e, "error parsing plist %s", input);
return StepExecutionResult.ERROR;
}
return StepExecutionResult.SUCCESS;
}
Aggregations