Search in sources :

Example 21 with NSObject

use of com.dd.plist.NSObject 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 22 with NSObject

use of com.dd.plist.NSObject 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)

Example 23 with NSObject

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

the class AppleSimulatorProfileParsing method parseProfilePlistStream.

public static Optional<AppleSimulatorProfile> parseProfilePlistStream(InputStream inputStream) throws IOException {
    NSDictionary profile;
    try (BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream)) {
        try {
            profile = (NSDictionary) PropertyListParser.parse(bufferedInputStream);
        } catch (Exception e) {
            throw new IOException(e);
        }
    }
    NSObject supportedProductFamilyIDsObject = profile.objectForKey("supportedProductFamilyIDs");
    if (!(supportedProductFamilyIDsObject instanceof NSArray)) {
        LOG.warn("Invalid simulator profile.plist (supportedProductFamilyIDs missing or not an array)");
        return Optional.empty();
    }
    NSArray supportedProductFamilyIDs = (NSArray) supportedProductFamilyIDsObject;
    AppleSimulatorProfile.Builder profileBuilder = AppleSimulatorProfile.builder();
    for (NSObject supportedProductFamilyID : supportedProductFamilyIDs.getArray()) {
        if (supportedProductFamilyID instanceof NSNumber) {
            profileBuilder.addSupportedProductFamilyIDs(((NSNumber) supportedProductFamilyID).intValue());
        } else {
            LOG.warn("Invalid simulator profile.plist (supportedProductFamilyIDs contains non-number %s)", supportedProductFamilyID);
            return Optional.empty();
        }
    }
    NSObject supportedArchsObject = profile.objectForKey("supportedArchs");
    if (!(supportedArchsObject instanceof NSArray)) {
        LOG.warn("Invalid simulator profile.plist (supportedArchs missing or not an array)");
        return Optional.empty();
    }
    NSArray supportedArchs = (NSArray) supportedArchsObject;
    for (NSObject supportedArch : supportedArchs.getArray()) {
        profileBuilder.addSupportedArchitectures(supportedArch.toString());
    }
    return Optional.of(profileBuilder.build());
}
Also used : NSNumber(com.dd.plist.NSNumber) NSObject(com.dd.plist.NSObject) BufferedInputStream(java.io.BufferedInputStream) NSArray(com.dd.plist.NSArray) NSDictionary(com.dd.plist.NSDictionary) IOException(java.io.IOException) IOException(java.io.IOException)

Example 24 with NSObject

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

the class XcodeprojSerializer method serializeObject.

/**
   * Serialize a {@link PBXObject} and its recursive descendants into the object dictionary.
   *
   * @return the GID of the serialized object
   *
   * @see PBXObject#serializeInto
   */
@Nullable
private String serializeObject(PBXObject obj) {
    if (obj.getGlobalID() == null) {
        obj.setGlobalID(obj.generateGid(gidGenerator));
        LOG.verbose("Set new object GID: %s", obj);
    } else {
        // Check that the object has already been serialized.
        NSObject object = objects.get(obj.getGlobalID());
        if (object != null) {
            LOG.verbose("Object %s found, returning existing object %s", obj, object);
            return obj.getGlobalID();
        } else {
            LOG.verbose("Object already had GID set: %s", obj);
        }
    }
    // Save the existing object being deserialized.
    NSDictionary stack = currentObject;
    currentObject = new NSDictionary();
    currentObject.put("isa", obj.isa());
    obj.serializeInto(this);
    objects.put(obj.getGlobalID(), currentObject);
    // Restore the existing object being deserialized.
    currentObject = stack;
    return obj.getGlobalID();
}
Also used : NSObject(com.dd.plist.NSObject) NSDictionary(com.dd.plist.NSDictionary) Nullable(javax.annotation.Nullable)

Example 25 with NSObject

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

the class SDKSettings method parseDefaultPropertiesFromPlist.

/**
   * Parses the contents of the provided SDKSettings.plist input stream
   * and extracts the dictionary of DefaultProperties values.
   */
public static void parseDefaultPropertiesFromPlist(InputStream sdkSettingsPlist, ImmutableMap.Builder<String, String> defaultPropertiesBuilder) throws Exception {
    NSObject sdkSettings = PropertyListParser.parse(sdkSettingsPlist);
    if (!(sdkSettings instanceof NSDictionary)) {
        throw new RuntimeException("Unexpected SDKSettings.plist contents (expected NSDictionary, got " + sdkSettings + ")");
    }
    getDefaultPropertiesFromNSDictionary((NSDictionary) sdkSettings, defaultPropertiesBuilder);
}
Also used : NSObject(com.dd.plist.NSObject) NSDictionary(com.dd.plist.NSDictionary)

Aggregations

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