Search in sources :

Example 1 with NSArray

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

the class AppleSdkDiscovery method buildSdkFromPath.

private static boolean buildSdkFromPath(Path sdkDir, AppleSdk.Builder sdkBuilder, ImmutableMap<String, AppleToolchain> xcodeToolchains, Optional<AppleToolchain> defaultToolchain, AppleConfig appleConfig) throws IOException {
    try (InputStream sdkSettingsPlist = Files.newInputStream(sdkDir.resolve("SDKSettings.plist"));
        BufferedInputStream bufferedSdkSettingsPlist = new BufferedInputStream(sdkSettingsPlist)) {
        NSDictionary sdkSettings;
        try {
            sdkSettings = (NSDictionary) PropertyListParser.parse(bufferedSdkSettingsPlist);
        } catch (PropertyListFormatException | ParseException | SAXException e) {
            LOG.error(e, "Malformatted SDKSettings.plist. Skipping SDK path %s.", sdkDir);
            return false;
        } catch (ParserConfigurationException e) {
            throw new IOException(e);
        }
        String name = sdkSettings.objectForKey("CanonicalName").toString();
        String version = sdkSettings.objectForKey("Version").toString();
        NSDictionary defaultProperties = (NSDictionary) sdkSettings.objectForKey("DefaultProperties");
        Optional<ImmutableList<String>> toolchains = appleConfig.getToolchainsOverrideForSDKName(name);
        boolean foundToolchain = false;
        if (!toolchains.isPresent()) {
            NSArray settingsToolchains = (NSArray) sdkSettings.objectForKey("Toolchains");
            if (settingsToolchains != null) {
                toolchains = Optional.of(Arrays.stream(settingsToolchains.getArray()).map(Object::toString).collect(MoreCollectors.toImmutableList()));
            }
        }
        if (toolchains.isPresent()) {
            for (String toolchainId : toolchains.get()) {
                AppleToolchain toolchain = xcodeToolchains.get(toolchainId);
                if (toolchain != null) {
                    foundToolchain = true;
                    sdkBuilder.addToolchains(toolchain);
                } else {
                    LOG.debug("Specified toolchain %s not found for SDK path %s", toolchainId, sdkDir);
                }
            }
        }
        if (!foundToolchain && defaultToolchain.isPresent()) {
            foundToolchain = true;
            sdkBuilder.addToolchains(defaultToolchain.get());
        }
        if (!foundToolchain) {
            LOG.warn("No toolchains found and no default toolchain. Skipping SDK path %s.", sdkDir);
            return false;
        } else {
            NSString platformName = (NSString) defaultProperties.objectForKey("PLATFORM_NAME");
            ApplePlatform applePlatform = ApplePlatform.of(platformName.toString());
            sdkBuilder.setName(name).setVersion(version).setApplePlatform(applePlatform);
            ImmutableList<String> architectures = validArchitecturesForPlatform(applePlatform, sdkDir);
            sdkBuilder.addAllArchitectures(architectures);
            return true;
        }
    } catch (NoSuchFileException e) {
        LOG.warn(e, "Skipping SDK at path %s, no SDKSettings.plist found", sdkDir);
        return false;
    }
}
Also used : NSArray(com.dd.plist.NSArray) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) NSDictionary(com.dd.plist.NSDictionary) ImmutableList(com.google.common.collect.ImmutableList) NoSuchFileException(java.nio.file.NoSuchFileException) IOException(java.io.IOException) NSString(com.dd.plist.NSString) NSString(com.dd.plist.NSString) 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 NSArray

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

the class NewNativeTargetProjectMutator method addSourcePathToHeadersBuildPhase.

private void addSourcePathToHeadersBuildPhase(SourcePath headerPath, PBXGroup headersGroup, HeaderVisibility visibility) {
    PBXFileReference fileReference = headersGroup.getOrCreateFileReferenceBySourceTreePath(new SourceTreePath(PBXReference.SourceTree.SOURCE_ROOT, pathRelativizer.outputPathToSourcePath(headerPath), Optional.empty()));
    PBXBuildFile buildFile = new PBXBuildFile(fileReference);
    if (visibility != HeaderVisibility.PRIVATE) {
        NSDictionary settings = new NSDictionary();
        settings.put("ATTRIBUTES", new NSArray(new NSString(AppleHeaderVisibilities.toXcodeAttribute(visibility))));
        buildFile.setSettings(Optional.of(settings));
    } else {
        buildFile.setSettings(Optional.empty());
    }
}
Also used : SourceTreePath(com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath) NSArray(com.dd.plist.NSArray) NSDictionary(com.dd.plist.NSDictionary) PBXBuildFile(com.facebook.buck.apple.xcode.xcodeproj.PBXBuildFile) NSString(com.dd.plist.NSString) PBXFileReference(com.facebook.buck.apple.xcode.xcodeproj.PBXFileReference)

Example 3 with NSArray

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

the class AbstractProvisioningProfileMetadata method prefixFromEntitlements.

/**
   * Takes an ImmutableMap representing an entitlements file, returns the application prefix
   * if it can be inferred from keys in the entitlement.  Otherwise, it returns empty.
   */
public static Optional<String> prefixFromEntitlements(ImmutableMap<String, NSObject> entitlements) {
    try {
        NSArray keychainAccessGroups = ((NSArray) entitlements.get("keychain-access-groups"));
        Preconditions.checkNotNull(keychainAccessGroups);
        String appID = keychainAccessGroups.objectAtIndex(0).toString();
        return Optional.of(splitAppID(appID).getFirst());
    } catch (RuntimeException e) {
        return Optional.empty();
    }
}
Also used : NSArray(com.dd.plist.NSArray) NSString(com.dd.plist.NSString)

Example 4 with NSArray

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

the class XcodeprojSerializer method addField.

public void addField(String name, List<? extends PBXObject> objectList) {
    NSArray array = new NSArray(objectList.size());
    for (int i = 0; i < objectList.size(); i++) {
        String gid = serializeObject(objectList.get(i));
        array.setValue(i, new NSString(gid));
    }
    Preconditions.checkNotNull(currentObject).put(name, array);
}
Also used : NSArray(com.dd.plist.NSArray) NSString(com.dd.plist.NSString) NSString(com.dd.plist.NSString)

Example 5 with NSArray

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

the class PlistProcessStepTest method testHandlesNonDictionaryPlists.

@Test
public void testHandlesNonDictionaryPlists() throws Exception {
    FakeProjectFilesystem projectFilesystem = new FakeProjectFilesystem();
    PlistProcessStep plistProcessStep = new PlistProcessStep(projectFilesystem, INPUT_PATH, Optional.empty(), OUTPUT_PATH, ImmutableMap.of(), ImmutableMap.of("Key1", new NSString("OverrideValue")), PlistProcessStep.OutputFormat.XML);
    NSArray array = new NSArray(new NSString("Value1"), new NSString("Value2"));
    projectFilesystem.writeContentsToPath(array.toXMLPropertyList(), INPUT_PATH);
    ExecutionContext executionContext = TestExecutionContext.newInstance();
    int errorCode = plistProcessStep.execute(executionContext).getExitCode();
    assertThat(errorCode, equalTo(0));
    assertThat(projectFilesystem.readFileIfItExists(OUTPUT_PATH), equalTo(Optional.of(array.toXMLPropertyList())));
}
Also used : ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) NSArray(com.dd.plist.NSArray) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) NSString(com.dd.plist.NSString) Test(org.junit.Test)

Aggregations

NSArray (com.dd.plist.NSArray)23 NSString (com.dd.plist.NSString)19 NSDictionary (com.dd.plist.NSDictionary)12 NSObject (com.dd.plist.NSObject)7 NSNumber (com.dd.plist.NSNumber)5 IOException (java.io.IOException)5 Test (org.junit.Test)5 File (java.io.File)4 Date (java.util.Date)4 NSDate (com.dd.plist.NSDate)2 PBXBuildFile (com.facebook.buck.apple.xcode.xcodeproj.PBXBuildFile)2 PBXFileReference (com.facebook.buck.apple.xcode.xcodeproj.PBXFileReference)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 BufferedInputStream (java.io.BufferedInputStream)2 NSData (com.dd.plist.NSData)1 PropertyListFormatException (com.dd.plist.PropertyListFormatException)1 PBXFrameworksBuildPhase (com.facebook.buck.apple.xcode.xcodeproj.PBXFrameworksBuildPhase)1 PBXNativeTarget (com.facebook.buck.apple.xcode.xcodeproj.PBXNativeTarget)1 PBXProject (com.facebook.buck.apple.xcode.xcodeproj.PBXProject)1