Search in sources :

Example 6 with NSDictionary

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

the class ProjectGenerator method writeProjectFile.

/**
   * Create the project bundle structure and write {@code project.pbxproj}.
   */
private Path writeProjectFile(PBXProject project) throws IOException {
    XcodeprojSerializer serializer = new XcodeprojSerializer(new GidGenerator(ImmutableSet.copyOf(gidsToTargetNames.keySet())), project);
    NSDictionary rootObject = serializer.toPlist();
    Path xcodeprojDir = outputDirectory.resolve(projectName + ".xcodeproj");
    projectFilesystem.mkdirs(xcodeprojDir);
    Path serializedProject = xcodeprojDir.resolve("project.pbxproj");
    String contentsToWrite = rootObject.toXMLPropertyList();
    // Before we write any files, check if the file contents have changed.
    if (MoreProjectFilesystems.fileContentsDiffer(new ByteArrayInputStream(contentsToWrite.getBytes(Charsets.UTF_8)), serializedProject, projectFilesystem)) {
        LOG.debug("Regenerating project at %s", serializedProject);
        if (shouldGenerateReadOnlyFiles()) {
            projectFilesystem.writeContentsToPath(contentsToWrite, serializedProject, READ_ONLY_FILE_ATTRIBUTE);
        } else {
            projectFilesystem.writeContentsToPath(contentsToWrite, serializedProject);
        }
    } else {
        LOG.debug("Not regenerating project at %s (contents have not changed)", serializedProject);
    }
    return xcodeprojDir;
}
Also used : 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) XcodeprojSerializer(com.facebook.buck.apple.xcode.XcodeprojSerializer) ByteArrayInputStream(java.io.ByteArrayInputStream) NSDictionary(com.dd.plist.NSDictionary) NSString(com.dd.plist.NSString) GidGenerator(com.facebook.buck.apple.xcode.GidGenerator)

Example 7 with NSDictionary

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

the class ProjectGenerator method createXcodeProjects.

public void createXcodeProjects() throws IOException {
    LOG.debug("Creating projects for targets %s", initialTargets);
    boolean hasAtLeastOneTarget = false;
    try (SimplePerfEvent.Scope scope = SimplePerfEvent.scope(buckEventBus, PerfEventId.of("xcode_project_generation"), ImmutableMap.of("Path", getProjectPath()))) {
        for (TargetNode<?, ?> targetNode : targetGraph.getNodes()) {
            if (isBuiltByCurrentProject(targetNode.getBuildTarget())) {
                LOG.debug("Including rule %s in project", targetNode);
                // Trigger the loading cache to call the generateProjectTarget function.
                Optional<PBXTarget> target = targetNodeToProjectTarget.getUnchecked(targetNode);
                if (target.isPresent()) {
                    targetNodeToGeneratedProjectTargetBuilder.put(targetNode, target.get());
                }
                if (targetNode.getBuildTarget().matchesUnflavoredTargets(focusModules)) {
                    // If the target is not included, we still need to do other operations to generate
                    // the required header maps.
                    hasAtLeastOneTarget = true;
                }
            } else {
                LOG.verbose("Excluding rule %s (not built by current project)", targetNode);
            }
        }
        if (!hasAtLeastOneTarget && focusModules.isPresent()) {
            return;
        }
        if (targetToBuildWithBuck.isPresent()) {
            generateBuildWithBuckTarget(targetGraph.get(targetToBuildWithBuck.get()));
        }
        for (String configName : targetConfigNamesBuilder.build()) {
            XCBuildConfiguration outputConfig = project.getBuildConfigurationList().getBuildConfigurationsByName().getUnchecked(configName);
            outputConfig.setBuildSettings(new NSDictionary());
        }
        if (!shouldGenerateHeaderSymlinkTreesOnly()) {
            writeProjectFile(project);
        }
        projectGenerated = true;
    } catch (UncheckedExecutionException e) {
        // if any code throws an exception, they tend to get wrapped in LoadingCache's
        // UncheckedExecutionException. Unwrap it if its cause is HumanReadable.
        UncheckedExecutionException originalException = e;
        while (e.getCause() instanceof UncheckedExecutionException) {
            e = (UncheckedExecutionException) e.getCause();
        }
        if (e.getCause() instanceof HumanReadableException) {
            throw (HumanReadableException) e.getCause();
        } else {
            throw originalException;
        }
    }
}
Also used : PBXTarget(com.facebook.buck.apple.xcode.xcodeproj.PBXTarget) XCBuildConfiguration(com.facebook.buck.apple.xcode.xcodeproj.XCBuildConfiguration) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) NSDictionary(com.dd.plist.NSDictionary) HumanReadableException(com.facebook.buck.util.HumanReadableException) NSString(com.dd.plist.NSString) SimplePerfEvent(com.facebook.buck.event.SimplePerfEvent)

Example 8 with NSDictionary

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

the class XcodeprojSerializer method toPlist.

/**
   * Generate a plist serialization of project bound to this serializer.
   */
public NSDictionary toPlist() {
    serializeObject(rootObject);
    NSDictionary root = new NSDictionary();
    root.put("archiveVersion", "1");
    root.put("classes", new NSDictionary());
    root.put("objectVersion", "46");
    root.put("objects", objects);
    root.put("rootObject", rootObject.getGlobalID());
    return root;
}
Also used : NSDictionary(com.dd.plist.NSDictionary)

Example 9 with NSDictionary

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

the class PlistProcessStepTest method testOverrideReplacesExistingKey.

@Test
public void testOverrideReplacesExistingKey() 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);
    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));
    dict.put("Key1", "OverrideValue");
    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 10 with NSDictionary

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

the class PlistProcessStepTest method testMergeFromFileReplacesExistingKey.

@Test
public void testMergeFromFileReplacesExistingKey() throws Exception {
    FakeProjectFilesystem projectFilesystem = new FakeProjectFilesystem();
    PlistProcessStep plistProcessStep = new PlistProcessStep(projectFilesystem, INPUT_PATH, Optional.of(MERGE_PATH), OUTPUT_PATH, ImmutableMap.of(), ImmutableMap.of(), PlistProcessStep.OutputFormat.XML);
    NSDictionary dict = new NSDictionary();
    dict.put("Key1", "Value1");
    dict.put("Key2", "Value2");
    projectFilesystem.writeContentsToPath(dict.toXMLPropertyList(), INPUT_PATH);
    NSDictionary overrideDict = new NSDictionary();
    overrideDict.put("Key1", "OverrideValue");
    projectFilesystem.writeContentsToPath(overrideDict.toXMLPropertyList(), MERGE_PATH);
    ExecutionContext executionContext = TestExecutionContext.newInstance();
    int errorCode = plistProcessStep.execute(executionContext).getExitCode();
    assertThat(errorCode, equalTo(0));
    dict.put("Key1", "OverrideValue");
    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) 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