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;
}
}
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());
}
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();
}
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;
}
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
}
}
Aggregations