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

The following examples show how to use com.dd.plist.NSDictionary#get() . 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: PBXProjectTest.java    From thym with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testAddPluginFile() throws Exception{
	PBXProject project = new PBXProject(pbxFile);
	String testPath = "my/files/abc.h";
	PBXFile file = new PBXFile(testPath);
	project.addPluginFile(file);
	
	
	NSDictionary dict = (NSDictionary)ASCIIPropertyListParser.parse(project.getContent().getBytes());
	NSDictionary objects = (NSDictionary)dict.objectForKey("objects");
	NSDictionary fileRef = (NSDictionary) objects.objectForKey(file.getFileRef());
	assertNotNull(fileRef);
	NSString isa = (NSString)fileRef.get("isa");
	assertEquals("PBXFileReference",isa.getContent());
	NSString path = (NSString)fileRef.get("path");
	assertEquals(testPath, path.getContent());
	NSString lastType = (NSString)fileRef.get("lastKnownFileType");
	assertEquals(HEADER_FILE, lastType.getContent());
	NSString encoding = (NSString)fileRef.get("fileEncoding");
	assertEquals("4", encoding.getContent());
	NSString sourceTree = (NSString)fileRef.get("sourceTree");
	assertEquals(DEFAULT_GROUP, sourceTree.getContent());
	
	assertTrue("No entry found on the Plugins group",isFileEntryFoundOnPluginsGroup(file, objects));
	
}
 
Example 2
Source File: PBXProjectTest.java    From thym with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testAddFrameworkWithWeak() throws Exception{
	PBXProject project = new PBXProject(pbxFile);
	String testPath = "libsqlite3.dylib";
	PBXFile file = new PBXFile(testPath);
	file.setWeak(true);
	project.addFramework(file);

	NSDictionary dict = (NSDictionary)ASCIIPropertyListParser.parse(project.getContent().getBytes());
	NSDictionary objects = (NSDictionary)dict.objectForKey("objects");
	
	NSDictionary buildFile = (NSDictionary)objects.objectForKey(file.getUuid());
	assertNotNull(buildFile);
	NSString isa = (NSString) buildFile.get("isa");
	assertEquals("PBXBuildFile",isa.getContent());
	NSString fRef = (NSString) buildFile.get("fileRef");
	assertEquals(file.getFileRef(), fRef.getContent());
	NSDictionary settings = (NSDictionary) buildFile.get("settings");
	NSArray attributes = (NSArray) settings.get("ATTRIBUTES");
	assertTrue(attributes.containsObject(NSObject.wrap("Weak")));
}
 
Example 3
Source File: PBXProjectTest.java    From thym with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testAddToLibrarySearchPaths() throws Exception{
	PBXProject project = new PBXProject(pbxFile);
	String testPath = "my/files/abcd.h";
	PBXFile file = new PBXFile(testPath);
	project.addToLibrarySearchPaths(file);
	
	NSDictionary dict = (NSDictionary)ASCIIPropertyListParser.parse(project.getContent().getBytes());
	NSDictionary objects = (NSDictionary)dict.objectForKey("objects");
	HashMap<String, NSObject> hashmap =  objects.getHashMap();	
	Collection<NSObject> values = hashmap.values();
	for (NSObject nsObject : values) {
		NSDictionary obj = (NSDictionary) nsObject;
		NSString isa = (NSString) obj.objectForKey("isa");
		if(isa != null && isa.getContent().equals("XCBuildConfiguration")){
			NSDictionary buildSettings = (NSDictionary) obj.objectForKey("buildSettings");
			assertTrue(buildSettings.containsKey("LIBRARY_SEARCH_PATHS"));
			NSArray searchPaths = (NSArray) buildSettings.get("LIBRARY_SEARCH_PATHS"); 
			assertEquals("$(SRCROOT)/Test_Application/my/files", ((NSString)searchPaths.objectAtIndex(1)).getContent());
		}
	}

}
 
Example 4
Source File: PBXProject.java    From thym with Eclipse Public License 1.0 6 votes vote down vote up
public String getProductName() throws PBXProjectException {
	HashMap<String, NSObject> hashmap =  getObjects().getHashMap();	
	Collection<NSObject> values = hashmap.values();
	for (NSObject nsObject : values) {
		NSDictionary obj = (NSDictionary) nsObject;
		NSString isa = (NSString) obj.objectForKey("isa");
		if(isa != null && isa.getContent().equals("XCBuildConfiguration")){
			NSDictionary buildSettings = (NSDictionary) obj.objectForKey("buildSettings");
			if( buildSettings.containsKey("PRODUCT_NAME")){
				NSString name = (NSString) buildSettings.get("PRODUCT_NAME");
				return name.getContent().replace('"', ' ').trim();
			}
		}
	}
	return null;
}
 
Example 5
Source File: XcodeprojSerializerTest.java    From buck with Apache License 2.0 6 votes vote down vote up
@Test
public void testEmptyProject() {
  PBXProject project = new PBXProject("TestProject", AbstractPBXObjectFactory.DefaultFactory());
  XcodeprojSerializer xcodeprojSerializer = new XcodeprojSerializer(new GidGenerator(), project);
  NSDictionary rootObject = xcodeprojSerializer.toPlist();

  assertEquals(project.getGlobalID(), ((NSString) rootObject.get("rootObject")).getContent());

  NSDictionary objects = ((NSDictionary) rootObject.get("objects"));
  NSDictionary projectObject = (NSDictionary) objects.get(project.getGlobalID());

  String[] requiredKeys = {
    "mainGroup", "targets", "buildConfigurationList", "compatibilityVersion", "attributes",
  };

  for (String key : requiredKeys) {
    assertTrue(projectObject.containsKey(key));
  }
}
 
Example 6
Source File: IpaLoader.java    From unidbg with Apache License 2.0 5 votes vote down vote up
private static String parseExecutable(File ipa, String appDir) throws IOException {
    try {
        byte[] data = loadZip(ipa, appDir + "Info.plist");
        if (data == null) {
            throw new IllegalStateException("Find Info.plist failed");
        }
        NSDictionary info = (NSDictionary) PropertyListParser.parse(data);
        NSString bundleExecutable = (NSString) info.get("CFBundleExecutable");
        return bundleExecutable.getContent();
    } catch (PropertyListFormatException | ParseException | ParserConfigurationException | SAXException e) {
        throw new IllegalStateException("load ipa failed", e);
    }
}
 
Example 7
Source File: IpaLoader.java    From unidbg with Apache License 2.0 5 votes vote down vote up
private static String parseVersion(File ipa, String appDir) throws IOException {
    try {
        byte[] data = loadZip(ipa, appDir + "Info.plist");
        if (data == null) {
            throw new IllegalStateException("Find Info.plist failed");
        }
        NSDictionary info = (NSDictionary) PropertyListParser.parse(data);
        NSString bundleVersion = (NSString) info.get("CFBundleVersion");
        return bundleVersion.getContent();
    } catch (PropertyListFormatException | ParseException | ParserConfigurationException | SAXException e) {
        throw new IllegalStateException("load ipa failed", e);
    }
}
 
Example 8
Source File: IpaLoader.java    From unidbg with Apache License 2.0 5 votes vote down vote up
private static String parseCFBundleIdentifier(File ipa, String appDir) throws IOException {
    try {
        byte[] data = loadZip(ipa, appDir + "Info.plist");
        if (data == null) {
            throw new IllegalStateException("Find Info.plist failed");
        }
        NSDictionary info = (NSDictionary) PropertyListParser.parse(data);
        NSString bundleIdentifier = (NSString) info.get("CFBundleIdentifier");
        return bundleIdentifier.getContent();
    } catch (PropertyListFormatException | ParseException | ParserConfigurationException | SAXException e) {
        throw new IllegalStateException("load ipa failed", e);
    }
}
 
Example 9
Source File: PListsLegacy.java    From InflatableDonkey with MIT License 5 votes vote down vote up
static <T extends NSObject> T cast(String key, NSDictionary dictionary) throws BadDataException {
    try {
        return (T) dictionary.get(key);

    } catch (ClassCastException ex) {
        throw new BadDataException("Bad type for key:" + key, ex);
    }
}
 
Example 10
Source File: PropertyLists.java    From LiquidDonkey with MIT License 5 votes vote down vote up
static <T> T get(NSDictionary dictionary, String key) throws BadDataException {
    NSObject object = dictionary.get(key);
    if (object == null) {
        throw new BadDataException("Missing key: " + key);
    }

    try {
        return (T) object;
    } catch (ClassCastException ex) {
        throw new BadDataException("Bad data type", ex);
    }
}
 
Example 11
Source File: PropertyLists.java    From LiquidDonkey with MIT License 5 votes vote down vote up
static String string(NSDictionary dictionary, String key) throws BadDataException {
    NSObject object = dictionary.get(key);
    if (object == null) {
        throw new BadDataException("Missing key: " + key);
    }
    return object.toString();
}
 
Example 12
Source File: PBXProjectTest.java    From thym with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testAddResourceWithPlugin() throws Exception{
	PBXProject project = new PBXProject(pbxFile);
	String testPath = "assets.bundle";
	PBXFile file = new PBXFile(testPath);
	file.setPlugin(true);
	project.addResourceFile(file);
	
	NSDictionary dict = (NSDictionary)ASCIIPropertyListParser.parse(project.getContent().getBytes());
	NSDictionary objects = (NSDictionary)dict.objectForKey("objects");
	
	//Added the PBXFileReference object correctly?
	NSDictionary fileRef = (NSDictionary) objects.objectForKey(file.getFileRef());
	assertNotNull(fileRef);
	NSString isa = (NSString)fileRef.get("isa");
	assertEquals("PBXFileReference",isa.getContent());
	NSString path = (NSString)fileRef.get("path");
	assertEquals("assets.bundle", path.getContent());
	NSString lastType = (NSString)fileRef.get("lastKnownFileType");
	assertEquals("\"wrapper.plug-in\"", lastType.getContent());
	NSString sourceTree = (NSString)fileRef.get("sourceTree");
	assertEquals(DEFAULT_GROUP, sourceTree.getContent());
	NSString name = (NSString) fileRef.get("name");
	assertEquals("assets.bundle", name.getContent());
	assertFalse(fileRef.containsKey("fileEncoding"));


	//Added to the Plugins PBXGroup group?
	NSDictionary group = getGroupByName(objects, "Plugins");
	NSArray children = (NSArray) group.objectForKey("children");
	assertTrue(children.containsObject(new NSString(file.getFileRef())));
	
	//Added to the PBXSourcesBuildPhase
	NSDictionary phase = getPhase(objects, "PBXResourcesBuildPhase");
	NSArray files = (NSArray) phase.get("files");
	assertTrue(files.containsObject(new NSString(file.getUuid())));


}
 
Example 13
Source File: PBXProjectTest.java    From thym with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testAddHeader() throws Exception{
	PBXProject project = new PBXProject(pbxFile);
	String testPath = "file.h";
	PBXFile file = new PBXFile(testPath);
	project.addHeaderFile(file);
	
	NSDictionary dict = (NSDictionary)ASCIIPropertyListParser.parse(project.getContent().getBytes());
	NSDictionary objects = (NSDictionary)dict.objectForKey("objects");
	
	//Added the PBXFileReference object correctly?
	NSDictionary fileRef = (NSDictionary) objects.objectForKey(file.getFileRef());
	assertNotNull(fileRef);
	NSString isa = (NSString)fileRef.get("isa");
	assertEquals("PBXFileReference",isa.getContent());
	NSString path = (NSString)fileRef.get("path");
	assertEquals(testPath, path.getContent());
	NSString lastType = (NSString)fileRef.get("lastKnownFileType");
	assertEquals("sourcecode.c.h", lastType.getContent());
	NSString sourceTree = (NSString)fileRef.get("sourceTree");
	assertEquals(DEFAULT_GROUP, sourceTree.getContent());
	NSString name = (NSString) fileRef.get("name");
	assertEquals("file.h", name.getContent());
	NSString encoding = (NSString) fileRef.get("fileEncoding");
	assertEquals("4", encoding.getContent());

	//Added to the Plugins PBXGroup group?
	NSDictionary group = getGroupByName(objects, "Plugins");
	NSArray children = (NSArray) group.objectForKey("children");
	assertTrue(children.containsObject(new NSString(file.getFileRef())));
	
}
 
Example 14
Source File: PBXBuildPhasesTest.java    From buck with Apache License 2.0 5 votes vote down vote up
private NSDictionary getObjectForGID(String gid, NSDictionary projPlist) {
  assertNotNull(projPlist);

  NSDictionary objects = (NSDictionary) projPlist.get("objects");
  assertNotNull(objects);

  NSDictionary object = (NSDictionary) objects.get(gid);
  assertNotNull(object);

  return object;
}
 
Example 15
Source File: PropertyLists.java    From LiquidDonkey with MIT License 4 votes vote down vote up
static String string(NSDictionary dictionary, String key, String defaultValue) {
    NSObject object = dictionary.get(key);
    return object == null
            ? defaultValue
            : object.toString();
}
 
Example 16
Source File: PBXTestUtils.java    From buck with Apache License 2.0 4 votes vote down vote up
public static void assertHasSingleSourcesPhaseWithSourcesAndFlags(
    PBXTarget target,
    ImmutableMap<String, Optional<String>> sourcesAndFlags,
    ProjectFilesystem projectFilesystem,
    Path outputDirectory) {

  PBXSourcesBuildPhase sourcesBuildPhase =
      ProjectGeneratorTestUtils.getSingleBuildPhaseOfType(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()).normalize().toString(),
        name.getValue());
  }
  ImmutableMap<String, Optional<String>> absolutePathFlagMap = absolutePathFlagMapBuilder.build();

  for (PBXBuildFile file : sourcesBuildPhase.getFiles()) {
    String filePath =
        assertFileRefIsRelativeAndResolvePath(
            file.getFileRef(), projectFilesystem, outputDirectory);
    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());
    }
  }
}