Search in sources :

Example 11 with NSDictionary

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

the class PlistProcessStepTest method testAdditionDoesNotReplaceExistingKey.

@Test
public void testAdditionDoesNotReplaceExistingKey() throws Exception {
    FakeProjectFilesystem projectFilesystem = new FakeProjectFilesystem();
    PlistProcessStep plistProcessStep = new PlistProcessStep(projectFilesystem, INPUT_PATH, Optional.empty(), OUTPUT_PATH, ImmutableMap.of("Key1", new NSString("OverrideValue")), ImmutableMap.of(), PlistProcessStep.OutputFormat.XML);
    NSDictionary dict = new NSDictionary();
    dict.put("Key1", "Value1");
    dict.put("Key2", "Value2");
    projectFilesystem.writeContentsToPath(dict.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(dict.toXMLPropertyList())));
}
Also used : ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) NSDictionary(com.dd.plist.NSDictionary) NSString(com.dd.plist.NSString) Test(org.junit.Test)

Example 12 with NSDictionary

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

the class ProvisioningProfileCopyStepTest method testDoesNotFailInDryRunMode.

@Test
public void testDoesNotFailInDryRunMode() throws Exception {
    assumeTrue(Platform.detect() == Platform.MACOS);
    Path emptyDir = TestDataHelper.getTestDataDirectory(this).resolve("provisioning_profiles_empty");
    ProvisioningProfileCopyStep step = new ProvisioningProfileCopyStep(projectFilesystem, testdataDir.resolve("Info.plist"), ApplePlatform.IPHONEOS, Optional.empty(), Optional.empty(), ProvisioningProfileStore.fromSearchPath(new DefaultProcessExecutor(new TestConsole()), ProvisioningProfileStore.DEFAULT_READ_COMMAND, emptyDir), outputFile, xcentFile, codeSignIdentityStore, Optional.of(dryRunResultFile));
    Future<Optional<ProvisioningProfileMetadata>> profileFuture = step.getSelectedProvisioningProfileFuture();
    step.execute(executionContext);
    assertTrue(profileFuture.isDone());
    assertNotNull(profileFuture.get());
    assertFalse(profileFuture.get().isPresent());
    Optional<String> resultContents = projectFilesystem.readFileIfItExists(dryRunResultFile);
    assertTrue(resultContents.isPresent());
    NSDictionary resultPlist = (NSDictionary) PropertyListParser.parse(resultContents.get().getBytes(Charsets.UTF_8));
    assertEquals(new NSString("com.example.TestApp"), resultPlist.get("bundle-id"));
}
Also used : Path(java.nio.file.Path) DefaultProcessExecutor(com.facebook.buck.util.DefaultProcessExecutor) Optional(java.util.Optional) NSDictionary(com.dd.plist.NSDictionary) NSString(com.dd.plist.NSString) TestConsole(com.facebook.buck.testutil.TestConsole) NSString(com.dd.plist.NSString) Test(org.junit.Test)

Example 13 with NSDictionary

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

the class ProvisioningProfileCopyStepTest method testNoEntitlementsDoesNotMergeInvalidProfileKeys.

@Test
public void testNoEntitlementsDoesNotMergeInvalidProfileKeys() 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.empty(), 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 14 with NSDictionary

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

the class ProjectGeneratorTest method assertHasSingletonSourcesPhaseWithSourcesAndFlags.

private void assertHasSingletonSourcesPhaseWithSourcesAndFlags(PBXTarget target, ImmutableMap<String, Optional<String>> sourcesAndFlags) {
    PBXSourcesBuildPhase sourcesBuildPhase = ProjectGeneratorTestUtils.getSingletonPhaseByType(target, PBXSourcesBuildPhase.class);
    assertEquals("Sources build phase should have correct number of sources", sourcesAndFlags.size(), sourcesBuildPhase.getFiles().size());
    // map keys to absolute paths
    ImmutableMap.Builder<String, Optional<String>> absolutePathFlagMapBuilder = ImmutableMap.builder();
    for (Map.Entry<String, Optional<String>> name : sourcesAndFlags.entrySet()) {
        absolutePathFlagMapBuilder.put(projectFilesystem.getRootPath().resolve(name.getKey()).toAbsolutePath().normalize().toString(), name.getValue());
    }
    ImmutableMap<String, Optional<String>> absolutePathFlagMap = absolutePathFlagMapBuilder.build();
    for (PBXBuildFile file : sourcesBuildPhase.getFiles()) {
        String filePath = assertFileRefIsRelativeAndResolvePath(file.getFileRef());
        Optional<String> flags = absolutePathFlagMap.get(filePath);
        assertNotNull(String.format("Unexpected file ref '%s' found", filePath), flags);
        if (flags.isPresent()) {
            assertTrue("Build file should have settings dictionary", file.getSettings().isPresent());
            NSDictionary buildFileSettings = file.getSettings().get();
            NSString compilerFlags = (NSString) buildFileSettings.get("COMPILER_FLAGS");
            assertNotNull("Build file settings should have COMPILER_FLAGS entry", compilerFlags);
            assertEquals("Build file settings should be expected value", flags.get(), compilerFlags.getContent());
        } else {
            assertFalse("Build file should not have settings dictionary", file.getSettings().isPresent());
        }
    }
}
Also used : Optional(java.util.Optional) NSDictionary(com.dd.plist.NSDictionary) PBXBuildFile(com.facebook.buck.apple.xcode.xcodeproj.PBXBuildFile) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) NSString(com.dd.plist.NSString) Map(java.util.Map) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) ImmutableMap(com.google.common.collect.ImmutableMap) HeaderMap(com.facebook.buck.apple.clang.HeaderMap) NSString(com.dd.plist.NSString) ImmutableMap(com.google.common.collect.ImmutableMap) PBXSourcesBuildPhase(com.facebook.buck.apple.xcode.xcodeproj.PBXSourcesBuildPhase)

Example 15 with NSDictionary

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

the class WorkspaceGeneratorTest method workspaceDisablesSchemeAutoCreation.

@Test
public void workspaceDisablesSchemeAutoCreation() throws Exception {
    Path workspacePath = generator.writeWorkspace();
    Optional<String> settings = projectFilesystem.readFileIfItExists(workspacePath.resolve("xcshareddata/WorkspaceSettings.xcsettings"));
    assertThat(settings.isPresent(), equalTo(true));
    NSObject object = PropertyListParser.parse(settings.get().getBytes(Charsets.UTF_8));
    assertThat(object, instanceOf(NSDictionary.class));
    NSObject autocreate = ((NSDictionary) object).get("IDEWorkspaceSharedSettings_AutocreateContextsIfNeeded");
    assertThat(autocreate, instanceOf(NSNumber.class));
    assertThat((NSNumber) autocreate, equalTo(new NSNumber(false)));
}
Also used : Path(java.nio.file.Path) Matchers.hasXPath(org.hamcrest.Matchers.hasXPath) NSNumber(com.dd.plist.NSNumber) NSObject(com.dd.plist.NSObject) NSDictionary(com.dd.plist.NSDictionary) Test(org.junit.Test)

Aggregations

NSDictionary (com.dd.plist.NSDictionary)70 NSString (com.dd.plist.NSString)33 NSObject (com.dd.plist.NSObject)22 IOException (java.io.IOException)16 Test (org.junit.Test)15 File (java.io.File)13 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 PropertyListFormatException (com.dd.plist.PropertyListFormatException)3 ExecutionContext (com.facebook.buck.step.ExecutionContext)3 TestExecutionContext (com.facebook.buck.step.TestExecutionContext)3 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)3