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;
}
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;
}
}
}
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;
}
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())));
}
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())));
}
Aggregations