Search in sources :

Example 46 with NSDictionary

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.*"))));
}
Also used : Path(java.nio.file.Path) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) NSDictionary(com.dd.plist.NSDictionary) Test(org.junit.Test)

Example 47 with NSDictionary

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"));
}
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 48 with NSDictionary

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);
    }
}
Also used : NSObject(com.dd.plist.NSObject) NSData(com.dd.plist.NSData) NSArray(com.dd.plist.NSArray) NSDictionary(com.dd.plist.NSDictionary) NSString(com.dd.plist.NSString) NSString(com.dd.plist.NSString) HashCode(com.google.common.hash.HashCode) ImmutableSet(com.google.common.collect.ImmutableSet) NSDate(com.dd.plist.NSDate) ProcessExecutorParams(com.facebook.buck.util.ProcessExecutorParams) IOException(java.io.IOException) ProcessExecutor(com.facebook.buck.util.ProcessExecutor) Date(java.util.Date) NSDate(com.dd.plist.NSDate) ImmutableMap(com.google.common.collect.ImmutableMap) IOException(java.io.IOException) HashFunction(com.google.common.hash.HashFunction) NSObject(com.dd.plist.NSObject)

Example 49 with NSDictionary

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;
}
Also used : ProcessExecutorParams(com.facebook.buck.util.ProcessExecutorParams) NSDictionary(com.dd.plist.NSDictionary) ImmutableList(com.google.common.collect.ImmutableList) IOException(java.io.IOException) ProcessExecutor(com.facebook.buck.util.ProcessExecutor)

Example 50 with NSDictionary

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;
}
Also used : NSObject(com.dd.plist.NSObject) BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) NSDictionary(com.dd.plist.NSDictionary) IOException(java.io.IOException) IOException(java.io.IOException) ImmutableMap(com.google.common.collect.ImmutableMap)

Aggregations

NSDictionary (com.dd.plist.NSDictionary)69 NSString (com.dd.plist.NSString)31 NSObject (com.dd.plist.NSObject)22 IOException (java.io.IOException)16 Test (org.junit.Test)15 File (java.io.File)14 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 PBXBuildFile (org.gradle.ide.xcode.internal.xcodeproj.PBXBuildFile)4 PBXFileReference (org.gradle.ide.xcode.internal.xcodeproj.PBXFileReference)4 XcodeProjectFile (org.gradle.ide.xcode.tasks.internal.XcodeProjectFile)4 PropertyListFormatException (com.dd.plist.PropertyListFormatException)3