Java Code Examples for com.dd.plist.NSDictionary#put()

The following examples show how to use com.dd.plist.NSDictionary#put() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PBXProject.java    From thym with Eclipse Public License 1.0 6 votes vote down vote up
private void addToPbxBuildFileSection(PBXFile pbxfile) throws PBXProjectException {
	NSDictionary obj = new NSDictionary();
	obj.put("isa" , "PBXBuildFile");
	obj.put("fileRef", pbxfile.getFileRef());
	if (pbxfile.hasSettings()){
		NSDictionary settings = new NSDictionary();
		if(pbxfile.isWeak()){
			NSArray attribs = new NSArray(NSObject.wrap("Weak"));
			settings.put("ATTRIBUTES", attribs);
		}
		if(pbxfile.getCompilerFlags() != null ){
			settings.put("COMPILER_FLAGS", NSObject.wrap(pbxfile.getCompilerFlags()));
		}
		obj.put("settings", settings);
	}
	getObjects().put(pbxfile.getUuid(), obj);
}
 
Example 2
Source File: PBXProject.java    From buck with Apache License 2.0 6 votes vote down vote up
@Override
public void serializeInto(XcodeprojSerializer s) {
  super.serializeInto(s);

  s.addField("mainGroup", mainGroup);

  targets.sort(Ordering.natural().onResultOf(PBXTarget::getName));
  s.addField("targets", targets);
  s.addField("buildConfigurationList", buildConfigurationList);
  s.addField("compatibilityVersion", compatibilityVersion);

  NSDictionary d = new NSDictionary();
  d.put("LastUpgradeCheck", "9999");

  s.addField("attributes", d);
}
 
Example 3
Source File: XcodeNativeTargetProjectWriter.java    From buck with Apache License 2.0 6 votes vote down vote up
private void addFileReferenceToHeadersBuildPhase(
    PBXFileReference fileReference,
    PBXHeadersBuildPhase headersBuildPhase,
    HeaderVisibility visibility,
    boolean frameworkHeadersEnabled,
    Optional<ProductType> productType) {
  PBXBuildFile buildFile = objectFactory.createBuildFile(fileReference);
  if (visibility != HeaderVisibility.PRIVATE) {
    productType.ifPresent(
        type -> {
          if (frameworkHeadersEnabled
              && (type == ProductTypes.FRAMEWORK || type == ProductTypes.STATIC_FRAMEWORK)) {
            headersBuildPhase.getFiles().add(buildFile);
          }
        });

    NSDictionary settings = new NSDictionary();
    settings.put(
        "ATTRIBUTES",
        new NSArray(new NSString(AppleHeaderVisibilities.toXcodeAttribute(visibility))));
    buildFile.setSettings(Optional.of(settings));
  } else {
    buildFile.setSettings(Optional.empty());
  }
}
 
Example 4
Source File: NewNativeTargetProjectMutator.java    From buck with Apache License 2.0 5 votes vote down vote up
private void addSourcePathToHeadersBuildPhase(
    SourcePath headerPath,
    PBXGroup headersGroup,
    PBXHeadersBuildPhase headersBuildPhase,
    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) {

    if (this.frameworkHeadersEnabled
        && (this.productType == ProductTypes.FRAMEWORK
            || this.productType == ProductTypes.STATIC_FRAMEWORK)) {
      headersBuildPhase.getFiles().add(buildFile);
    }

    NSDictionary settings = new NSDictionary();
    settings.put(
        "ATTRIBUTES",
        new NSArray(new NSString(AppleHeaderVisibilities.toXcodeAttribute(visibility))));
    buildFile.setSettings(Optional.of(settings));
  } else {
    buildFile.setSettings(Optional.empty());
  }
}
 
Example 5
Source File: PlistProcessStepTest.java    From buck with Apache License 2.0 5 votes vote down vote up
@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())));
}
 
Example 6
Source File: PlistProcessStepTest.java    From buck with Apache License 2.0 5 votes vote down vote up
@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())));
}
 
Example 7
Source File: PlistProcessStepTest.java    From buck with Apache License 2.0 5 votes vote down vote up
@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())));
}
 
Example 8
Source File: XcodeprojSerializer.java    From buck with Apache License 2.0 5 votes vote down vote up
/** 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;
}
 
Example 9
Source File: XcodeNativeTargetProjectWriter.java    From buck with Apache License 2.0 5 votes vote down vote up
private void addFileReferenceToSourcesBuildPhase(
    ProjectFileWriter.Result result,
    SourceWithFlags sourceWithFlags,
    PBXSourcesBuildPhase sourcesBuildPhase,
    ImmutableMap<CxxSource.Type, ImmutableList<String>> langPreprocessorFlags) {
  PBXFileReference fileReference = result.getFileReference();
  SourceTreePath sourceTreePath = result.getSourceTreePath();
  PBXBuildFile buildFile = objectFactory.createBuildFile(fileReference);
  sourcesBuildPhase.getFiles().add(buildFile);

  ImmutableList<String> customLangPreprocessorFlags = ImmutableList.of();
  Optional<CxxSource.Type> sourceType =
      CxxSource.Type.fromExtension(Files.getFileExtension(sourceTreePath.toString()));
  if (sourceType.isPresent() && langPreprocessorFlags.containsKey(sourceType.get())) {
    customLangPreprocessorFlags = langPreprocessorFlags.get(sourceType.get());
  }

  ImmutableList<String> customFlags =
      ImmutableList.copyOf(
          Iterables.concat(customLangPreprocessorFlags, sourceWithFlags.getFlags()));
  if (!customFlags.isEmpty()) {
    NSDictionary settings = new NSDictionary();
    settings.put("COMPILER_FLAGS", Joiner.on(' ').join(customFlags));
    buildFile.setSettings(Optional.of(settings));
  }
  LOG.verbose(
      "Added source path %s to sources build phase, flags %s, PBXFileReference %s",
      sourceWithFlags, customFlags, fileReference);
}
 
Example 10
Source File: AuthUtils.java    From AirPlayAuth with MIT License 5 votes vote down vote up
static byte[] createPList(Map<String, ? extends Object> properties) throws IOException {
    ByteArrayOutputStream plistOutputStream = new ByteArrayOutputStream();
    NSDictionary root = new NSDictionary();
    for (Map.Entry<String, ? extends Object> property : properties.entrySet()) {
        root.put(property.getKey(), property.getValue());
    }
    PropertyListParser.saveAsBinary(root, plistOutputStream);
    return plistOutputStream.toByteArray();
}
 
Example 11
Source File: PBXProject.java    From thym with Eclipse Public License 1.0 5 votes vote down vote up
private void addToPbxFileReferenceSection(PBXFile pbxfile) throws PBXProjectException {
	NSDictionary obj = new NSDictionary();
	obj.put("isa", "PBXFileReference");
	obj.put("lastKnownFileType", pbxfile.getLastType());
	obj.put("path", pbxfile.getPath());
	obj.put("name", FilenameUtils.getName(pbxfile.getPath()));
	obj.put("sourceTree", pbxfile.getSourceTree());
	if(pbxfile.getEncoding() != null){
		obj.put("fileEncoding", pbxfile.getEncoding());
	}
	getObjects().put(pbxfile.getFileRef(), obj);
}
 
Example 12
Source File: PBXProject.java    From thym with Eclipse Public License 1.0 5 votes vote down vote up
private void addToPbxGroup(String groupName, PBXFile pbxfile) throws PBXProjectException {
	NSDictionary group = getGroupByName(groupName);
	NSArray children = (NSArray) group.objectForKey("children");
	NSObject[] childs = children.getArray();
	NSObject[] newChilds = new NSObject[childs.length +1];
	System.arraycopy(childs, 0, newChilds, 0, childs.length);
	newChilds[newChilds.length-1] = new NSString(pbxfile.getFileRef());
	NSArray newArray = new NSArray(newChilds);
	group.remove("children");
	group.put("children", newArray);
	
}
 
Example 13
Source File: PBXProject.java    From thym with Eclipse Public License 1.0 5 votes vote down vote up
private void addToBuildPhase(String phaseName, PBXFile pbxfile) throws PBXProjectException {
	NSDictionary phase = getPhaseByName(phaseName);
	NSArray files = (NSArray) phase.objectForKey("files");
	NSObject[] current = files.getArray();
	NSObject[] newArray = new NSObject[ current.length +1 ];
	System.arraycopy(current, 0, newArray, 0, current.length);
	newArray[newArray.length-1] = new NSString(pbxfile.getUuid());
	NSArray newNSArray = new NSArray(newArray);
	phase.remove("files");
	phase.put("files", newNSArray);
}
 
Example 14
Source File: InflatableData.java    From InflatableDonkey with MIT License 5 votes vote down vote up
public byte[] encoded() {
    try {
        NSDictionary dict = new NSDictionary();
        dict.put("escrowedKeys", new NSData(escrowedKeys));
        dict.put("deviceUuid", new NSString(deviceUuid.toString()));
        dict.put("deviceHardWareId", new NSString(deviceHardWareId));
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PropertyListParser.saveAsBinary(dict, baos);
        return baos.toByteArray();
    } catch (IOException ex) {
        throw new IllegalStateException(ex);
    }
}
 
Example 15
Source File: EntryHelper.java    From narrate-android with Apache License 2.0 5 votes vote down vote up
public static NSDictionary toDictionary(Entry entry) {
    NSDictionary dictionary = new NSDictionary();

    dictionary.put("UUID", entry.uuid);
    dictionary.put("Creation Date", entry.creationDate.getTime());
    dictionary.put("Modified Date", entry.modifiedDate);

    NSDictionary creatorDictionary = new NSDictionary();
    creatorDictionary.put("Device Agent", "Narrate");
    creatorDictionary.put("Generation Date", entry.creationDate.getTime());
    creatorDictionary.put("Host Name", "Narrate");
    creatorDictionary.put("OS Agent", "Android");
    creatorDictionary.put("Software Agent", "Narrate");
    dictionary.put("Creator", creatorDictionary);

    if (entry.title != null && entry.title.length() > 0)
        dictionary.put("Entry Text", entry.title + "\n" + entry.text);
    else
        dictionary.put("Entry Text", entry.text);

    if (entry.hasLocation) {
        NSDictionary locationDict = new NSDictionary();
        locationDict.put("Administrative Area", "");
        locationDict.put("Country", "");
        locationDict.put("Latitude", entry.latitude);
        locationDict.put("Locality", "");
        locationDict.put("Longitude", entry.longitude);

        if (entry.placeName != null)
            locationDict.put("Place Name", entry.placeName);

        dictionary.put("Location", locationDict);
    }

    dictionary.put("Starred", entry.starred);
    dictionary.put("Time Zone", entry.creationDate.getTimeZone().getDisplayName());
    dictionary.put("Tags", entry.tags);

    return dictionary;
}
 
Example 16
Source File: PlistSerializer.java    From cyberduck with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void setMapForKey(final Map<String, String> value, final String key) {
    final NSDictionary list = new NSDictionary();
    for(Map.Entry<String, String> entry : value.entrySet()) {
        list.put(entry.getKey(), entry.getValue());
    }
    dict.put(key, list);
}
 
Example 17
Source File: NewNativeTargetProjectMutator.java    From buck with Apache License 2.0 4 votes vote down vote up
private void addSourcePathToSourcesBuildPhase(
    SourceWithFlags sourceWithFlags,
    PBXGroup sourcesGroup,
    PBXSourcesBuildPhase sourcesBuildPhase) {
  SourceTreePath sourceTreePath =
      new SourceTreePath(
          PBXReference.SourceTree.SOURCE_ROOT,
          pathRelativizer.outputDirToRootRelative(
              sourcePathResolver.apply(sourceWithFlags.getSourcePath())),
          Optional.empty());
  PBXFileReference fileReference =
      sourcesGroup.getOrCreateFileReferenceBySourceTreePath(sourceTreePath);
  PBXBuildFile buildFile = new PBXBuildFile(fileReference);
  sourcesBuildPhase.getFiles().add(buildFile);

  ImmutableList<String> customLangPreprocessorFlags = ImmutableList.of();
  Optional<CxxSource.Type> sourceType =
      CxxSource.Type.fromExtension(Files.getFileExtension(sourceTreePath.toString()));
  if (sourceType.isPresent() && langPreprocessorFlags.containsKey(sourceType.get())) {
    customLangPreprocessorFlags = langPreprocessorFlags.get(sourceType.get());
  }

  ImmutableList<String> customLangCompilerFlags = ImmutableList.of();
  if (sourceType.isPresent()) {
    Optional<CxxSource.Type> sourceProcessedLanguage =
        CxxSource.Type.fromLanguage(sourceType.get().getPreprocessedLanguage());

    if (sourceProcessedLanguage.isPresent()
        && langCompilerFlags.containsKey(sourceProcessedLanguage.get())) {
      customLangCompilerFlags = langCompilerFlags.get(sourceProcessedLanguage.get());
    }
  }

  ImmutableList<String> customFlags =
      ImmutableList.copyOf(
          Iterables.concat(
              customLangPreprocessorFlags, customLangCompilerFlags, sourceWithFlags.getFlags()));
  if (!customFlags.isEmpty()) {
    NSDictionary settings = new NSDictionary();
    settings.put("COMPILER_FLAGS", Joiner.on(' ').join(customFlags));
    buildFile.setSettings(Optional.of(settings));
  }
  LOG.verbose(
      "Added source path %s to group %s, flags %s, PBXFileReference %s",
      sourceWithFlags, sourcesGroup.getName(), customFlags, fileReference);
}
 
Example 18
Source File: CodeSignStep.java    From buck with Apache License 2.0 4 votes vote down vote up
@Override
public StepExecutionResult execute(ExecutionContext context)
    throws IOException, InterruptedException {
  if (dryRunResultsPath.isPresent()) {
    NSDictionary dryRunResult = new NSDictionary();
    dryRunResult.put(
        "relative-path-to-sign",
        dryRunResultsPath.get().getParent().relativize(pathToSign).toString());
    dryRunResult.put("use-entitlements", pathToSigningEntitlements.isPresent());
    dryRunResult.put("identity", getIdentityArg(codeSignIdentitySupplier.get()));
    filesystem.writeContentsToPath(dryRunResult.toXMLPropertyList(), dryRunResultsPath.get());
    return StepExecutionResults.SUCCESS;
  }

  ProcessExecutorParams.Builder paramsBuilder = ProcessExecutorParams.builder();
  if (codesignAllocatePath.isPresent()) {
    ImmutableList<String> commandPrefix = codesignAllocatePath.get().getCommandPrefix(resolver);
    paramsBuilder.setEnvironment(
        ImmutableMap.of("CODESIGN_ALLOCATE", Joiner.on(" ").join(commandPrefix)));
  }
  ImmutableList.Builder<String> commandBuilder = ImmutableList.builder();
  commandBuilder.addAll(codesign.getCommandPrefix(resolver));
  commandBuilder.add("--force", "--sign", getIdentityArg(codeSignIdentitySupplier.get()));
  commandBuilder.addAll(codesignFlags);
  if (pathToSigningEntitlements.isPresent()) {
    commandBuilder.add("--entitlements", pathToSigningEntitlements.get().toString());
  }
  commandBuilder.add(pathToSign.toString());
  ProcessExecutorParams processExecutorParams =
      paramsBuilder
          .setCommand(commandBuilder.build())
          .setDirectory(filesystem.getRootPath().getPath())
          .build();
  // Must specify that stdout is expected or else output may be wrapped in Ansi escape chars.
  Set<ProcessExecutor.Option> options = EnumSet.of(ProcessExecutor.Option.EXPECTING_STD_OUT);
  ProcessExecutor processExecutor = context.getProcessExecutor();
  if (LOG.isDebugEnabled()) {
    LOG.debug("codesign command: %s", Joiner.on(" ").join(processExecutorParams.getCommand()));
  }
  ProcessExecutor.Result result =
      processExecutor.launchAndExecute(
          processExecutorParams,
          options,
          /* stdin */ Optional.empty(),
          /* timeOutMs */ Optional.of(codesignTimeout.toMillis()),
          /* timeOutHandler */ Optional.empty());

  if (result.isTimedOut()) {
    throw new RuntimeException(
        "codesign timed out.  This may be due to the keychain being locked.");
  }

  if (result.getExitCode() != 0) {
    return StepExecutionResult.of(result);
  }
  return StepExecutionResults.SUCCESS;
}