Search in sources :

Example 6 with NSString

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

the class InfoPListTest method testParsePropertyList.

@Test
public void testParsePropertyList() throws Exception {
    File file = File.createTempFile(InfoPListTest.class.getSimpleName(), ".tmp");
    byte[] data = IOUtils.toByteArray(getClass().getResourceAsStream("InfoPListTest.Info.plist.xml"));
    FileUtils.writeByteArrayToFile(file, data);
    Properties props = new Properties();
    props.setProperty("prop1", "value1");
    props.setProperty("prop2", "value2");
    props.setProperty("prop3", "value3");
    props.setProperty("prop4", "value4");
    NSDictionary dict = (NSDictionary) InfoPList.parsePropertyList(file, props, true);
    assertEquals(new NSString("value1"), dict.objectForKey("Prop1"));
    assertEquals(new NSString("value2foobar"), dict.objectForKey("Prop2"));
    assertEquals(new NSString("foobarvalue3"), dict.objectForKey("Prop3"));
    assertEquals(new NSString("foovalue4bar"), dict.objectForKey("Prop4"));
    assertEquals(new NSString("foovalue1value2bar"), dict.objectForKey("Prop5"));
    assertEquals(new NSString("foovalue1woovalue2bar"), dict.objectForKey("Prop6"));
    assertEquals(new NSString("value1woovalue2"), dict.objectForKey("Prop7"));
    assertEquals(new NSString("${unknown}"), dict.objectForKey("Prop8"));
    assertEquals(Arrays.asList(new NSString("value1"), new NSString("value2")), Arrays.asList(((NSArray) dict.objectForKey("List")).getArray()));
}
Also used : NSArray(com.dd.plist.NSArray) NSDictionary(com.dd.plist.NSDictionary) Properties(java.util.Properties) File(java.io.File) NSString(com.dd.plist.NSString) Test(org.junit.Test)

Example 7 with NSString

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

the class AppLauncher method getAppId.

private static String getAppId(File f) throws IOException {
    if (f == null) {
        throw new NullPointerException("localAppPath");
    }
    if (!f.exists()) {
        throw new FileNotFoundException(f.getAbsolutePath());
    }
    NSDictionary infoPlistDict = null;
    if (f.getName().toLowerCase().endsWith(".ipa")) {
        try (ZipFile zipFile = new ZipFile(f)) {
            for (ZipEntry entry : Collections.list(zipFile.entries())) {
                if (entry.getName().matches("Payload/[^/]+\\.app/Info\\.plist")) {
                    try (InputStream is = zipFile.getInputStream(entry)) {
                        try {
                            infoPlistDict = (NSDictionary) PropertyListParser.parse(is);
                        } catch (IOException e) {
                            throw e;
                        } catch (Exception e) {
                            throw new IOException(e);
                        }
                        break;
                    }
                }
            }
        }
    } else if (f.isDirectory()) {
        File infoPlistFile = new File(f, "Info.plist");
        if (infoPlistFile.exists()) {
            try {
                infoPlistDict = (NSDictionary) PropertyListParser.parse(infoPlistFile);
            } catch (IOException e) {
                throw e;
            } catch (Exception e) {
                throw new IOException(e);
            }
        }
    }
    if (infoPlistDict == null) {
        throw new IllegalArgumentException("Path " + f + " is neither a " + ".ipa file nor an iOS app bundle directory.");
    }
    NSString appId = (NSString) infoPlistDict.objectForKey("CFBundleIdentifier");
    if (appId == null) {
        throw new IllegalArgumentException("No CFBundleIdentifier found in " + "the Info.plist file in " + f);
    }
    return appId.toString();
}
Also used : ZipFile(java.util.zip.ZipFile) NSDictionary(com.dd.plist.NSDictionary) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) FileNotFoundException(java.io.FileNotFoundException) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) ZipFile(java.util.zip.ZipFile) File(java.io.File) NSString(com.dd.plist.NSString) TimeoutException(java.util.concurrent.TimeoutException) InterruptedIOException(java.io.InterruptedIOException) LibIMobileDeviceException(org.robovm.libimobiledevice.LibIMobileDeviceException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 8 with NSString

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

the class AppleSdkDiscovery method buildSdkFromPath.

private static boolean buildSdkFromPath(Path sdkDir, AppleSdk.Builder sdkBuilder, ImmutableMap<String, AppleToolchain> xcodeToolchains, Optional<AppleToolchain> defaultToolchain, AppleConfig appleConfig) throws IOException {
    try (InputStream sdkSettingsPlist = Files.newInputStream(sdkDir.resolve("SDKSettings.plist"));
        BufferedInputStream bufferedSdkSettingsPlist = new BufferedInputStream(sdkSettingsPlist)) {
        NSDictionary sdkSettings;
        try {
            sdkSettings = (NSDictionary) PropertyListParser.parse(bufferedSdkSettingsPlist);
        } catch (PropertyListFormatException | ParseException | SAXException e) {
            LOG.error(e, "Malformatted SDKSettings.plist. Skipping SDK path %s.", sdkDir);
            return false;
        } catch (ParserConfigurationException e) {
            throw new IOException(e);
        }
        String name = sdkSettings.objectForKey("CanonicalName").toString();
        String version = sdkSettings.objectForKey("Version").toString();
        NSDictionary defaultProperties = (NSDictionary) sdkSettings.objectForKey("DefaultProperties");
        Optional<ImmutableList<String>> toolchains = appleConfig.getToolchainsOverrideForSDKName(name);
        boolean foundToolchain = false;
        if (!toolchains.isPresent()) {
            NSArray settingsToolchains = (NSArray) sdkSettings.objectForKey("Toolchains");
            if (settingsToolchains != null) {
                toolchains = Optional.of(Arrays.stream(settingsToolchains.getArray()).map(Object::toString).collect(MoreCollectors.toImmutableList()));
            }
        }
        if (toolchains.isPresent()) {
            for (String toolchainId : toolchains.get()) {
                AppleToolchain toolchain = xcodeToolchains.get(toolchainId);
                if (toolchain != null) {
                    foundToolchain = true;
                    sdkBuilder.addToolchains(toolchain);
                } else {
                    LOG.debug("Specified toolchain %s not found for SDK path %s", toolchainId, sdkDir);
                }
            }
        }
        if (!foundToolchain && defaultToolchain.isPresent()) {
            foundToolchain = true;
            sdkBuilder.addToolchains(defaultToolchain.get());
        }
        if (!foundToolchain) {
            LOG.warn("No toolchains found and no default toolchain. Skipping SDK path %s.", sdkDir);
            return false;
        } else {
            NSString platformName = (NSString) defaultProperties.objectForKey("PLATFORM_NAME");
            ApplePlatform applePlatform = ApplePlatform.of(platformName.toString());
            sdkBuilder.setName(name).setVersion(version).setApplePlatform(applePlatform);
            ImmutableList<String> architectures = validArchitecturesForPlatform(applePlatform, sdkDir);
            sdkBuilder.addAllArchitectures(architectures);
            return true;
        }
    } catch (NoSuchFileException e) {
        LOG.warn(e, "Skipping SDK at path %s, no SDKSettings.plist found", sdkDir);
        return false;
    }
}
Also used : NSArray(com.dd.plist.NSArray) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) NSDictionary(com.dd.plist.NSDictionary) ImmutableList(com.google.common.collect.ImmutableList) NoSuchFileException(java.nio.file.NoSuchFileException) IOException(java.io.IOException) NSString(com.dd.plist.NSString) NSString(com.dd.plist.NSString) SAXException(org.xml.sax.SAXException) PropertyListFormatException(com.dd.plist.PropertyListFormatException) BufferedInputStream(java.io.BufferedInputStream) ParseException(java.text.ParseException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 9 with NSString

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

the class NewNativeTargetProjectMutator method addSourcePathToHeadersBuildPhase.

private void addSourcePathToHeadersBuildPhase(SourcePath headerPath, PBXGroup headersGroup, 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) {
        NSDictionary settings = new NSDictionary();
        settings.put("ATTRIBUTES", new NSArray(new NSString(AppleHeaderVisibilities.toXcodeAttribute(visibility))));
        buildFile.setSettings(Optional.of(settings));
    } else {
        buildFile.setSettings(Optional.empty());
    }
}
Also used : SourceTreePath(com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath) NSArray(com.dd.plist.NSArray) NSDictionary(com.dd.plist.NSDictionary) PBXBuildFile(com.facebook.buck.apple.xcode.xcodeproj.PBXBuildFile) NSString(com.dd.plist.NSString) PBXFileReference(com.facebook.buck.apple.xcode.xcodeproj.PBXFileReference)

Example 10 with NSString

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

Aggregations

NSString (com.dd.plist.NSString)34 NSDictionary (com.dd.plist.NSDictionary)23 NSArray (com.dd.plist.NSArray)20 Test (org.junit.Test)10 NSObject (com.dd.plist.NSObject)8 IOException (java.io.IOException)8 File (java.io.File)7 NSNumber (com.dd.plist.NSNumber)5 Path (java.nio.file.Path)5 PBXBuildFile (com.facebook.buck.apple.xcode.xcodeproj.PBXBuildFile)4 PBXFileReference (com.facebook.buck.apple.xcode.xcodeproj.PBXFileReference)4 Date (java.util.Date)4 PBXSourcesBuildPhase (com.facebook.buck.apple.xcode.xcodeproj.PBXSourcesBuildPhase)3 ExecutionContext (com.facebook.buck.step.ExecutionContext)3 TestExecutionContext (com.facebook.buck.step.TestExecutionContext)3 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 NSDate (com.dd.plist.NSDate)2 PBXProject (com.facebook.buck.apple.xcode.xcodeproj.PBXProject)2 SourceTreePath (com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath)2