Search in sources :

Example 16 with NSObject

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

the class ProjectGenerator method addCoreDataModelBuildPhase.

private void addCoreDataModelBuildPhase(PBXGroup targetGroup, Iterable<AppleWrapperResourceArg> dataModels) throws IOException {
    for (final AppleWrapperResourceArg dataModel : dataModels) {
        // Core data models go in the resources group also.
        PBXGroup resourcesGroup = targetGroup.getOrCreateChildGroupByName("Resources");
        if (CoreDataModelDescription.isVersionedDataModel(dataModel)) {
            // It's safe to do I/O here to figure out the current version because we're returning all
            // the versions and the file pointing to the current version from
            // getInputsToCompareToOutput(), so the rule will be correctly detected as stale if any of
            // them change.
            final String currentVersionFileName = ".xccurrentversion";
            final String currentVersionKey = "_XCCurrentVersionName";
            final XCVersionGroup versionGroup = resourcesGroup.getOrCreateChildVersionGroupsBySourceTreePath(new SourceTreePath(PBXReference.SourceTree.SOURCE_ROOT, pathRelativizer.outputDirToRootRelative(dataModel.path), Optional.empty()));
            projectFilesystem.walkRelativeFileTree(dataModel.path, new SimpleFileVisitor<Path>() {

                @Override
                public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) {
                    if (dir.equals(dataModel.path)) {
                        return FileVisitResult.CONTINUE;
                    }
                    versionGroup.getOrCreateFileReferenceBySourceTreePath(new SourceTreePath(PBXReference.SourceTree.SOURCE_ROOT, pathRelativizer.outputDirToRootRelative(dir), Optional.empty()));
                    return FileVisitResult.SKIP_SUBTREE;
                }
            });
            Path currentVersionPath = dataModel.path.resolve(currentVersionFileName);
            try (InputStream in = projectFilesystem.newFileInputStream(currentVersionPath)) {
                NSObject rootObject;
                try {
                    rootObject = PropertyListParser.parse(in);
                } catch (IOException e) {
                    throw e;
                } catch (Exception e) {
                    rootObject = null;
                }
                if (!(rootObject instanceof NSDictionary)) {
                    throw new HumanReadableException("Malformed %s file.", currentVersionFileName);
                }
                NSDictionary rootDictionary = (NSDictionary) rootObject;
                NSObject currentVersionName = rootDictionary.objectForKey(currentVersionKey);
                if (!(currentVersionName instanceof NSString)) {
                    throw new HumanReadableException("Malformed %s file.", currentVersionFileName);
                }
                PBXFileReference ref = versionGroup.getOrCreateFileReferenceBySourceTreePath(new SourceTreePath(PBXReference.SourceTree.SOURCE_ROOT, pathRelativizer.outputDirToRootRelative(dataModel.path.resolve(currentVersionName.toString())), Optional.empty()));
                versionGroup.setCurrentVersion(Optional.of(ref));
            } catch (NoSuchFileException e) {
                if (versionGroup.getChildren().size() == 1) {
                    versionGroup.setCurrentVersion(Optional.of(Iterables.get(versionGroup.getChildren(), 0)));
                }
            }
        } else {
            resourcesGroup.getOrCreateFileReferenceBySourceTreePath(new SourceTreePath(PBXReference.SourceTree.SOURCE_ROOT, pathRelativizer.outputDirToRootRelative(dataModel.path), Optional.empty()));
        }
    }
}
Also used : SourceTreePath(com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath) SourceTreePath(com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath) Path(java.nio.file.Path) SourcePath(com.facebook.buck.rules.SourcePath) BuildTargetSourcePath(com.facebook.buck.rules.BuildTargetSourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FrameworkPath(com.facebook.buck.rules.coercer.FrameworkPath) NSObject(com.dd.plist.NSObject) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) NSDictionary(com.dd.plist.NSDictionary) NoSuchFileException(java.nio.file.NoSuchFileException) FileVisitResult(java.nio.file.FileVisitResult) NSString(com.dd.plist.NSString) IOException(java.io.IOException) NSString(com.dd.plist.NSString) MacroException(com.facebook.buck.model.MacroException) NoSuchBuildTargetException(com.facebook.buck.parser.NoSuchBuildTargetException) IOException(java.io.IOException) NoSuchFileException(java.nio.file.NoSuchFileException) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) HumanReadableException(com.facebook.buck.util.HumanReadableException) XCVersionGroup(com.facebook.buck.apple.xcode.xcodeproj.XCVersionGroup) HumanReadableException(com.facebook.buck.util.HumanReadableException) PBXGroup(com.facebook.buck.apple.xcode.xcodeproj.PBXGroup) AppleWrapperResourceArg(com.facebook.buck.apple.AppleWrapperResourceArg) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) PBXFileReference(com.facebook.buck.apple.xcode.xcodeproj.PBXFileReference)

Example 17 with NSObject

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

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

the class ProvisioningProfileStoreTest method testPrefixOverride.

@Test
public void testPrefixOverride() throws Exception {
    ProvisioningProfileMetadata expected = makeTestMetadata("AAAAAAAAAA.*", new Date(Long.MAX_VALUE), "00000000-0000-0000-0000-000000000000");
    ProvisioningProfileStore profiles = ProvisioningProfileStore.fromProvisioningProfiles(ImmutableList.of(expected, makeTestMetadata("BBBBBBBBBB.com.facebook.test", new Date(Long.MAX_VALUE), "00000000-0000-0000-0000-000000000000")));
    NSString[] fakeKeychainAccessGroups = { new NSString("AAAAAAAAAA.*") };
    ImmutableMap<String, NSObject> fakeEntitlements = ImmutableMap.of("keychain-access-groups", new NSArray(fakeKeychainAccessGroups));
    Optional<ProvisioningProfileMetadata> actual = profiles.getBestProvisioningProfile("com.facebook.test", ApplePlatform.IPHONEOS, Optional.of(fakeEntitlements), ProvisioningProfileStore.MATCH_ANY_IDENTITY);
    assertThat(actual.get(), is(equalTo(expected)));
}
Also used : NSObject(com.dd.plist.NSObject) NSArray(com.dd.plist.NSArray) NSString(com.dd.plist.NSString) NSString(com.dd.plist.NSString) Date(java.util.Date) Test(org.junit.Test)

Example 19 with NSObject

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

the class AppleBundle method getInfoPlistAdditionalKeys.

private ImmutableMap<String, NSObject> getInfoPlistAdditionalKeys() {
    ImmutableMap.Builder<String, NSObject> keys = ImmutableMap.builder();
    final String platformName = platform.getName();
    if (platformName.contains("osx")) {
        keys.put("NSHighResolutionCapable", new NSNumber(true));
        keys.put("NSSupportsAutomaticGraphicsSwitching", new NSNumber(true));
        keys.put("CFBundleSupportedPlatforms", new NSArray(new NSString("MacOSX")));
    } else if (platformName.contains("iphoneos")) {
        keys.put("CFBundleSupportedPlatforms", new NSArray(new NSString("iPhoneOS")));
    } else if (platformName.contains("iphonesimulator")) {
        keys.put("CFBundleSupportedPlatforms", new NSArray(new NSString("iPhoneSimulator")));
    } else if (platformName.contains("watchos") && !isLegacyWatchApp()) {
        keys.put("CFBundleSupportedPlatforms", new NSArray(new NSString("WatchOS")));
    } else if (platformName.contains("watchsimulator") && !isLegacyWatchApp()) {
        keys.put("CFBundleSupportedPlatforms", new NSArray(new NSString("WatchSimulator")));
    }
    keys.put("DTPlatformName", new NSString(platformName));
    keys.put("DTPlatformVersion", new NSString(sdkVersion));
    keys.put("DTSDKName", new NSString(sdkName + sdkVersion));
    keys.put("MinimumOSVersion", new NSString(minOSVersion));
    if (platformBuildVersion.isPresent()) {
        keys.put("DTPlatformBuild", new NSString(platformBuildVersion.get()));
        keys.put("DTSDKBuild", new NSString(platformBuildVersion.get()));
    }
    if (xcodeBuildVersion.isPresent()) {
        keys.put("DTXcodeBuild", new NSString(xcodeBuildVersion.get()));
    }
    if (xcodeVersion.isPresent()) {
        keys.put("DTXcode", new NSString(xcodeVersion.get()));
    }
    return keys.build();
}
Also used : NSNumber(com.dd.plist.NSNumber) NSObject(com.dd.plist.NSObject) NSArray(com.dd.plist.NSArray) NSString(com.dd.plist.NSString) NSString(com.dd.plist.NSString) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 20 with NSObject

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

the class AbstractProvisioningProfileMetadata method getMergeableEntitlements.

public ImmutableMap<String, NSObject> getMergeableEntitlements() {
    final ImmutableSet<String> excludedKeys = ImmutableSet.of("com.apple.developer.icloud-container-development-container-identifiers", "com.apple.developer.icloud-container-environment", "com.apple.developer.icloud-container-identifiers", "com.apple.developer.icloud-services", "com.apple.developer.restricted-resource-mode", "com.apple.developer.ubiquity-container-identifiers", "com.apple.developer.ubiquity-kvstore-identifier", "inter-app-audio", "com.apple.developer.homekit", "com.apple.developer.healthkit", "com.apple.developer.in-app-payments", "com.apple.developer.maps", "com.apple.external-accessory.wireless-configuration");
    ImmutableMap<String, NSObject> allEntitlements = getEntitlements();
    ImmutableMap.Builder<String, NSObject> filteredEntitlementsBuilder = ImmutableMap.builder();
    for (String key : allEntitlements.keySet()) {
        if (!excludedKeys.contains(key)) {
            filteredEntitlementsBuilder.put(key, allEntitlements.get(key));
        }
    }
    return filteredEntitlementsBuilder.build();
}
Also used : NSObject(com.dd.plist.NSObject) NSString(com.dd.plist.NSString) ImmutableMap(com.google.common.collect.ImmutableMap)

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