Search in sources :

Example 1 with NSNumber

use of com.dd.plist.NSNumber 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)

Example 2 with NSNumber

use of com.dd.plist.NSNumber in project robovm by robovm.

the class IOSTarget method createInfoPList.

protected void createInfoPList(File dir) throws IOException {
    NSDictionary dict = new NSDictionary();
    if (config.getIosInfoPList() != null && config.getIosInfoPList().getDictionary() != null) {
        NSDictionary infoPListDict = config.getIosInfoPList().getDictionary();
        for (String key : infoPListDict.allKeys()) {
            dict.put(key, infoPListDict.objectForKey(key));
        }
    } else {
        dict.put("CFBundleVersion", "1.0");
        dict.put("CFBundleExecutable", config.getExecutableName());
        dict.put("CFBundleName", config.getExecutableName());
        dict.put("CFBundleIdentifier", getBundleId());
        dict.put("CFBundlePackageType", "APPL");
        dict.put("LSRequiresIPhoneOS", true);
        NSObject supportedDeviceFamilies = sdk.getDefaultProperty("SUPPORTED_DEVICE_FAMILIES");
        if (supportedDeviceFamilies != null) {
            // SUPPORTED_DEVICE_FAMILIES is either a NSString of comma
            // separated numbers
            // or an NSArray with NSStrings. UIDeviceFamily values should be
            // NSNumbers.
            NSArray families = null;
            if (supportedDeviceFamilies instanceof NSString) {
                NSString defFamilies = (NSString) supportedDeviceFamilies;
                String[] parts = defFamilies.toString().split(",");
                families = new NSArray(parts.length);
                for (int i = 0; i < families.count(); i++) {
                    families.setValue(i, new NSNumber(parts[i].trim()));
                }
            } else {
                NSArray defFamilies = (NSArray) supportedDeviceFamilies;
                families = new NSArray(defFamilies.count());
                for (int i = 0; i < families.count(); i++) {
                    families.setValue(i, new NSNumber(defFamilies.objectAtIndex(i).toString()));
                }
            }
            dict.put("UIDeviceFamily", families);
        }
        dict.put("UISupportedInterfaceOrientations", new NSArray(new NSString("UIInterfaceOrientationPortrait"), new NSString("UIInterfaceOrientationLandscapeLeft"), new NSString("UIInterfaceOrientationLandscapeRight"), new NSString("UIInterfaceOrientationPortraitUpsideDown")));
        dict.put("UISupportedInterfaceOrientations~ipad", new NSArray(new NSString("UIInterfaceOrientationPortrait"), new NSString("UIInterfaceOrientationLandscapeLeft"), new NSString("UIInterfaceOrientationLandscapeRight"), new NSString("UIInterfaceOrientationPortraitUpsideDown")));
        dict.put("UIRequiredDeviceCapabilities", new NSArray(new NSString("armv7")));
    }
    dict.put("DTPlatformName", sdk.getPlatformName());
    dict.put("DTSDKName", sdk.getCanonicalName());
    for (File f : FileUtils.listFiles(partialPListDir, new String[] { "plist" }, false)) {
        try {
            NSDictionary d = (NSDictionary) PropertyListParser.parse(f);
            dict.putAll(d);
        } catch (Exception e) {
            throw new CompilerException(e);
        }
    }
    if (dict.objectForKey("MinimumOSVersion") == null) {
        // This is required
        dict.put("MinimumOSVersion", "6.0");
    }
    customizeInfoPList(dict);
    /*
         * Make sure CFBundleShortVersionString and CFBundleVersion are at the
         * top of the Info.plist file to avoid the "Could not hardlink copy"
         * problem when launching on the simulator. com.dd.plist maintains the
         * insertion order of keys so we rebuild the dictionary here and make
         * sure those two keys are inserted first. See #771.
         */
    NSDictionary newDict = new NSDictionary();
    if (dict.objectForKey("CFBundleShortVersionString") != null) {
        newDict.put("CFBundleShortVersionString", dict.objectForKey("CFBundleShortVersionString"));
        dict.remove("CFBundleShortVersionString");
    }
    if (dict.objectForKey("CFBundleVersion") != null) {
        newDict.put("CFBundleVersion", dict.objectForKey("CFBundleVersion"));
        dict.remove("CFBundleVersion");
    }
    for (String key : dict.allKeys()) {
        newDict.put(key, dict.objectForKey(key));
    }
    File tmpInfoPlist = new File(config.getTmpDir(), "Info.plist");
    PropertyListParser.saveAsBinary(newDict, tmpInfoPlist);
    config.getLogger().info("Installing Info.plist to %s", dir);
    FileUtils.copyFile(tmpInfoPlist, new File(dir, tmpInfoPlist.getName()));
}
Also used : NSNumber(com.dd.plist.NSNumber) NSObject(com.dd.plist.NSObject) NSArray(com.dd.plist.NSArray) NSDictionary(com.dd.plist.NSDictionary) CompilerException(org.robovm.compiler.CompilerException) NSString(com.dd.plist.NSString) NSString(com.dd.plist.NSString) File(java.io.File) CompilerException(org.robovm.compiler.CompilerException) NoSuchElementException(java.util.NoSuchElementException) IOException(java.io.IOException)

Example 3 with NSNumber

use of com.dd.plist.NSNumber in project robovm by robovm.

the class ProvisioningProfileTest method createProfile.

@SuppressWarnings("unchecked")
private ProvisioningProfile createProfile(String name, String appIdName, String appIdPrefix, String appId, boolean getTaskAllow, String provisionedDevice, String fingerprint) throws Exception {
    NSDictionary entitlements = new NSDictionary();
    entitlements.put("application-identifier", appId);
    entitlements.put("get-task-allow", new NSNumber(getTaskAllow));
    NSDictionary dict = new NSDictionary();
    dict.put("UUID", UUID.randomUUID().toString());
    dict.put("Name", name);
    dict.put("AppIDName", appIdName);
    dict.put("ApplicationIdentifierPrefix", new NSArray(new NSString(appIdPrefix)));
    dict.put("CreationDate", new NSDate(new Date()));
    dict.put("ExpirationDate", new NSDate(new Date()));
    dict.put("Entitlements", entitlements);
    dict.put("DeveloperCertificates", new NSArray());
    if (provisionedDevice != null) {
        NSArray devices = new NSArray(1);
        devices.setValue(0, new NSString(provisionedDevice));
        dict.put("ProvisionedDevices", devices);
    }
    ProvisioningProfile profile = new ProvisioningProfile(new File(""), dict);
    Field f = ProvisioningProfile.class.getDeclaredField("certFingerprints");
    f.setAccessible(true);
    List<String> certFingerprints = (List<String>) f.get(profile);
    certFingerprints.add(fingerprint);
    return profile;
}
Also used : NSNumber(com.dd.plist.NSNumber) Field(java.lang.reflect.Field) NSArray(com.dd.plist.NSArray) NSDictionary(com.dd.plist.NSDictionary) List(java.util.List) NSString(com.dd.plist.NSString) NSString(com.dd.plist.NSString) File(java.io.File) NSDate(com.dd.plist.NSDate) Date(java.util.Date) NSDate(com.dd.plist.NSDate)

Example 4 with NSNumber

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

the class AppleBundle method getInfoPlistAdditionalKeys.

private ImmutableMap<String, NSObject> getInfoPlistAdditionalKeys() {
    ImmutableMap.Builder<String, NSObject> keys = ImmutableMap.builder();
    final String platformName = platform.getName();
    if (platformName.contains("osx")) {
        keys.put("NSHighResolutionCapable", new NSNumber(true));
        keys.put("NSSupportsAutomaticGraphicsSwitching", new NSNumber(true));
        keys.put("CFBundleSupportedPlatforms", new NSArray(new NSString("MacOSX")));
    } else if (platformName.contains("iphoneos")) {
        keys.put("CFBundleSupportedPlatforms", new NSArray(new NSString("iPhoneOS")));
    } else if (platformName.contains("iphonesimulator")) {
        keys.put("CFBundleSupportedPlatforms", new NSArray(new NSString("iPhoneSimulator")));
    } else if (platformName.contains("watchos") && !isLegacyWatchApp()) {
        keys.put("CFBundleSupportedPlatforms", new NSArray(new NSString("WatchOS")));
    } else if (platformName.contains("watchsimulator") && !isLegacyWatchApp()) {
        keys.put("CFBundleSupportedPlatforms", new NSArray(new NSString("WatchSimulator")));
    }
    keys.put("DTPlatformName", new NSString(platformName));
    keys.put("DTPlatformVersion", new NSString(sdkVersion));
    keys.put("DTSDKName", new NSString(sdkName + sdkVersion));
    keys.put("MinimumOSVersion", new NSString(minOSVersion));
    if (platformBuildVersion.isPresent()) {
        keys.put("DTPlatformBuild", new NSString(platformBuildVersion.get()));
        keys.put("DTSDKBuild", new NSString(platformBuildVersion.get()));
    }
    if (xcodeBuildVersion.isPresent()) {
        keys.put("DTXcodeBuild", new NSString(xcodeBuildVersion.get()));
    }
    if (xcodeVersion.isPresent()) {
        keys.put("DTXcode", new NSString(xcodeVersion.get()));
    }
    return keys.build();
}
Also used : NSNumber(com.dd.plist.NSNumber) NSObject(com.dd.plist.NSObject) NSArray(com.dd.plist.NSArray) NSString(com.dd.plist.NSString) NSString(com.dd.plist.NSString) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 5 with NSNumber

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

the class AppleSimulatorProfileParsing method parseProfilePlistStream.

public static Optional<AppleSimulatorProfile> parseProfilePlistStream(InputStream inputStream) throws IOException {
    NSDictionary profile;
    try (BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream)) {
        try {
            profile = (NSDictionary) PropertyListParser.parse(bufferedInputStream);
        } catch (Exception e) {
            throw new IOException(e);
        }
    }
    NSObject supportedProductFamilyIDsObject = profile.objectForKey("supportedProductFamilyIDs");
    if (!(supportedProductFamilyIDsObject instanceof NSArray)) {
        LOG.warn("Invalid simulator profile.plist (supportedProductFamilyIDs missing or not an array)");
        return Optional.empty();
    }
    NSArray supportedProductFamilyIDs = (NSArray) supportedProductFamilyIDsObject;
    AppleSimulatorProfile.Builder profileBuilder = AppleSimulatorProfile.builder();
    for (NSObject supportedProductFamilyID : supportedProductFamilyIDs.getArray()) {
        if (supportedProductFamilyID instanceof NSNumber) {
            profileBuilder.addSupportedProductFamilyIDs(((NSNumber) supportedProductFamilyID).intValue());
        } else {
            LOG.warn("Invalid simulator profile.plist (supportedProductFamilyIDs contains non-number %s)", supportedProductFamilyID);
            return Optional.empty();
        }
    }
    NSObject supportedArchsObject = profile.objectForKey("supportedArchs");
    if (!(supportedArchsObject instanceof NSArray)) {
        LOG.warn("Invalid simulator profile.plist (supportedArchs missing or not an array)");
        return Optional.empty();
    }
    NSArray supportedArchs = (NSArray) supportedArchsObject;
    for (NSObject supportedArch : supportedArchs.getArray()) {
        profileBuilder.addSupportedArchitectures(supportedArch.toString());
    }
    return Optional.of(profileBuilder.build());
}
Also used : NSNumber(com.dd.plist.NSNumber) NSObject(com.dd.plist.NSObject) BufferedInputStream(java.io.BufferedInputStream) NSArray(com.dd.plist.NSArray) NSDictionary(com.dd.plist.NSDictionary) IOException(java.io.IOException) IOException(java.io.IOException)

Aggregations

NSNumber (com.dd.plist.NSNumber)8 NSDictionary (com.dd.plist.NSDictionary)7 NSArray (com.dd.plist.NSArray)5 NSObject (com.dd.plist.NSObject)5 NSString (com.dd.plist.NSString)5 File (java.io.File)3 IOException (java.io.IOException)2 Path (java.nio.file.Path)2 Test (org.junit.Test)2 NSDate (com.dd.plist.NSDate)1 BuildTarget (com.facebook.buck.model.BuildTarget)1 ProjectWorkspace (com.facebook.buck.testutil.integration.ProjectWorkspace)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 BufferedInputStream (java.io.BufferedInputStream)1 Field (java.lang.reflect.Field)1 FileStore (java.nio.file.FileStore)1 Date (java.util.Date)1 List (java.util.List)1 NoSuchElementException (java.util.NoSuchElementException)1 Matchers.hasXPath (org.hamcrest.Matchers.hasXPath)1