Search in sources :

Example 1 with ParseException

use of java.text.ParseException 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 2 with ParseException

use of java.text.ParseException in project buck by facebook.

the class AppleToolchainDiscovery method toolchainFromPlist.

private static Optional<AppleToolchain> toolchainFromPlist(Path toolchainDir, String plistName) throws IOException {
    Path toolchainInfoPlistPath = toolchainDir.resolve(plistName);
    InputStream toolchainInfoPlist = Files.newInputStream(toolchainInfoPlistPath);
    BufferedInputStream bufferedToolchainInfoPlist = new BufferedInputStream(toolchainInfoPlist);
    NSDictionary parsedToolchainInfoPlist;
    try {
        parsedToolchainInfoPlist = (NSDictionary) PropertyListParser.parse(bufferedToolchainInfoPlist);
    } catch (PropertyListFormatException | ParseException | ParserConfigurationException | SAXException e) {
        LOG.error(e, "Failed to parse %s: %s, ignoring", plistName, toolchainInfoPlistPath);
        return Optional.empty();
    }
    NSObject identifierObject = parsedToolchainInfoPlist.objectForKey("Identifier");
    if (identifierObject == null) {
        LOG.error("Identifier not found for toolchain path %s, ignoring", toolchainDir);
        return Optional.empty();
    }
    String identifier = identifierObject.toString();
    NSObject versionObject = parsedToolchainInfoPlist.objectForKey("DTSDKBuild");
    Optional<String> version = versionObject == null ? Optional.empty() : Optional.of(versionObject.toString());
    LOG.debug("Mapped SDK identifier %s to path %s", identifier, toolchainDir);
    AppleToolchain.Builder toolchainBuilder = AppleToolchain.builder();
    toolchainBuilder.setIdentifier(identifier);
    toolchainBuilder.setVersion(version);
    toolchainBuilder.setPath(toolchainDir);
    return Optional.of(toolchainBuilder.build());
}
Also used : Path(java.nio.file.Path) NSObject(com.dd.plist.NSObject) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) NSDictionary(com.dd.plist.NSDictionary) SAXException(org.xml.sax.SAXException) PropertyListFormatException(com.dd.plist.PropertyListFormatException) BufferedInputStream(java.io.BufferedInputStream) ParseException(java.text.ParseException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 3 with ParseException

use of java.text.ParseException in project elasticsearch by elastic.

the class ShardUpgradeResult method readFrom.

@Override
public void readFrom(StreamInput in) throws IOException {
    shardId = ShardId.readShardId(in);
    primary = in.readBoolean();
    upgradeVersion = Version.readVersion(in);
    try {
        oldestLuceneSegment = org.apache.lucene.util.Version.parse(in.readString());
    } catch (ParseException ex) {
        throw new IOException("failed to parse lucene version [" + oldestLuceneSegment + "]", ex);
    }
}
Also used : ParseException(java.text.ParseException) IOException(java.io.IOException)

Example 4 with ParseException

use of java.text.ParseException in project elasticsearch by elastic.

the class ExpressionTests method testLinkError.

public void testLinkError() {
    ScriptException e = expectThrows(ScriptException.class, () -> {
        compile("doc['e'].value * 5");
    });
    assertTrue(e.getCause() instanceof ParseException);
}
Also used : ScriptException(org.elasticsearch.script.ScriptException) ParseException(java.text.ParseException)

Example 5 with ParseException

use of java.text.ParseException in project elasticsearch by elastic.

the class ExpressionTests method testCompileError.

public void testCompileError() {
    ScriptException e = expectThrows(ScriptException.class, () -> {
        compile("doc['d'].value * *@#)(@$*@#$ + 4");
    });
    assertTrue(e.getCause() instanceof ParseException);
}
Also used : ScriptException(org.elasticsearch.script.ScriptException) ParseException(java.text.ParseException)

Aggregations

ParseException (java.text.ParseException)3499 Date (java.util.Date)1367 SimpleDateFormat (java.text.SimpleDateFormat)1276 IOException (java.io.IOException)363 ArrayList (java.util.ArrayList)330 DateFormat (java.text.DateFormat)299 Calendar (java.util.Calendar)284 Test (org.junit.Test)272 HashMap (java.util.HashMap)137 Matcher (java.util.regex.Matcher)98 File (java.io.File)97 GregorianCalendar (java.util.GregorianCalendar)94 Map (java.util.Map)93 List (java.util.List)90 BigDecimal (java.math.BigDecimal)68 Locale (java.util.Locale)67 ParsePosition (java.text.ParsePosition)56 Timestamp (java.sql.Timestamp)55 InputStream (java.io.InputStream)53 DecimalFormat (java.text.DecimalFormat)49