Search in sources :

Example 1 with SAXException

use of org.xml.sax.SAXException 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 SAXException

use of org.xml.sax.SAXException 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 SAXException

use of org.xml.sax.SAXException in project che by eclipse.

the class CheCodeFormatterOptions method getCheDefaultSettings.

private Map<String, String> getCheDefaultSettings() {
    SAXParserFactory factory = SAXParserFactory.newInstance();
    XMLParser parserXML = new XMLParser();
    try {
        SAXParser parser = factory.newSAXParser();
        parser.parse(getClass().getResourceAsStream(DEFAULT_CODESTYLE), parserXML);
    } catch (ParserConfigurationException | SAXException | IOException e) {
        LOG.error("It is not possible to parse file " + DEFAULT_CODESTYLE, e);
    }
    return parserXML.getSettings();
}
Also used : SAXParser(javax.xml.parsers.SAXParser) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) SAXParserFactory(javax.xml.parsers.SAXParserFactory) SAXException(org.xml.sax.SAXException)

Example 4 with SAXException

use of org.xml.sax.SAXException in project che by eclipse.

the class TemplateReaderWriter method read.

/**
	 * Reads templates from an <code>InputSource</code> and adds them to the templates.
	 *
	 * @param source the input source
	 * @param bundle a resource bundle to use for translating the read templates, or <code>null</code> if no translation should occur
	 * @param singleId the template id to extract, or <code>null</code> to read in all templates
	 * @return the read templates, encapsulated in instances of <code>TemplatePersistenceData</code>
	 * @throws IOException if reading from the stream fails
	 */
private TemplatePersistenceData[] read(InputSource source, ResourceBundle bundle, String singleId) throws IOException {
    try {
        Collection templates = new ArrayList();
        Set ids = new HashSet();
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder parser = factory.newDocumentBuilder();
        parser.setErrorHandler(new DefaultHandler());
        Document document = parser.parse(source);
        NodeList elements = document.getElementsByTagName(TEMPLATE_ELEMENT);
        int count = elements.getLength();
        for (int i = 0; i != count; i++) {
            Node node = elements.item(i);
            NamedNodeMap attributes = node.getAttributes();
            if (attributes == null)
                continue;
            String id = getStringValue(attributes, ID_ATTRIBUTE, null);
            if (id != null && ids.contains(id))
                //$NON-NLS-1$
                throw new IOException(TemplatePersistenceMessages.getString("TemplateReaderWriter.duplicate.id"));
            if (singleId != null && !singleId.equals(id))
                continue;
            boolean deleted = getBooleanValue(attributes, DELETED_ATTRIBUTE, false);
            String name = getStringValue(attributes, NAME_ATTRIBUTE);
            name = translateString(name, bundle);
            //$NON-NLS-1$
            String description = getStringValue(attributes, DESCRIPTION_ATTRIBUTE, "");
            description = translateString(description, bundle);
            String context = getStringValue(attributes, CONTEXT_ATTRIBUTE);
            if (name == null || context == null)
                //$NON-NLS-1$
                throw new IOException(TemplatePersistenceMessages.getString("TemplateReaderWriter.error.missing_attribute"));
            boolean enabled = getBooleanValue(attributes, ENABLED_ATTRIBUTE, true);
            boolean autoInsertable = getBooleanValue(attributes, AUTO_INSERTABLE_ATTRIBUTE, true);
            StringBuffer buffer = new StringBuffer();
            NodeList children = node.getChildNodes();
            for (int j = 0; j != children.getLength(); j++) {
                String value = children.item(j).getNodeValue();
                if (value != null)
                    buffer.append(value);
            }
            String pattern = buffer.toString();
            pattern = translateString(pattern, bundle);
            Template template = new Template(name, description, context, pattern, autoInsertable);
            TemplatePersistenceData data = new TemplatePersistenceData(template, enabled, id);
            data.setDeleted(deleted);
            templates.add(data);
            if (singleId != null && singleId.equals(id))
                break;
        }
        return (TemplatePersistenceData[]) templates.toArray(new TemplatePersistenceData[templates.size()]);
    } catch (ParserConfigurationException e) {
        Assert.isTrue(false);
    } catch (SAXException e) {
        //$NON-NLS-1$
        throw (IOException) new IOException("Could not read template file").initCause(e);
    }
    // dummy
    return null;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) NamedNodeMap(org.w3c.dom.NamedNodeMap) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Document(org.w3c.dom.Document) DefaultHandler(org.xml.sax.helpers.DefaultHandler) Template(org.eclipse.jface.text.templates.Template) SAXException(org.xml.sax.SAXException) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Collection(java.util.Collection) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) HashSet(java.util.HashSet)

Example 5 with SAXException

use of org.xml.sax.SAXException in project che by eclipse.

the class DialogSettings method load.

/* (non-Javadoc)
     * Method declared on IDialogSettings.
     */
@Override
public void load(Reader r) {
    Document document = null;
    try {
        DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        //		parser.setProcessNamespace(true);
        document = parser.parse(new InputSource(r));
        //Strip out any comments first
        Node root = document.getFirstChild();
        while (root.getNodeType() == Node.COMMENT_NODE) {
            document.removeChild(root);
            root = document.getFirstChild();
        }
        load(document, (Element) root);
    } catch (ParserConfigurationException e) {
    // ignore
    } catch (IOException e) {
    // ignore
    } catch (SAXException e) {
    // ignore
    }
}
Also used : InputSource(org.xml.sax.InputSource) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Node(org.w3c.dom.Node) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException)

Aggregations

SAXException (org.xml.sax.SAXException)2465 IOException (java.io.IOException)1622 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1049 Document (org.w3c.dom.Document)682 DocumentBuilder (javax.xml.parsers.DocumentBuilder)537 InputSource (org.xml.sax.InputSource)518 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)415 InputStream (java.io.InputStream)317 Element (org.w3c.dom.Element)311 NodeList (org.w3c.dom.NodeList)292 File (java.io.File)274 Node (org.w3c.dom.Node)247 ByteArrayInputStream (java.io.ByteArrayInputStream)235 StringReader (java.io.StringReader)224 SAXParser (javax.xml.parsers.SAXParser)209 SAXParseException (org.xml.sax.SAXParseException)196 TransformerException (javax.xml.transform.TransformerException)180 ArrayList (java.util.ArrayList)169 SAXParserFactory (javax.xml.parsers.SAXParserFactory)159 XMLReader (org.xml.sax.XMLReader)151