use of javax.xml.parsers.ParserConfigurationException 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 javax.xml.parsers.ParserConfigurationException 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
}
}
use of javax.xml.parsers.ParserConfigurationException in project cogtool by cogtool.
the class ProjectController method createPasteAction.
// Action for Paste
protected IListenerAction createPasteAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return ProjectSelectionState.class;
}
public boolean performAction(Object prms) {
ProjectSelectionState seln = (ProjectSelectionState) prms;
try {
// Check for CogTool objects to paste
Collection<Object> objects = CogToolClipboard.fetchCogToolObjects(project);
// designs and tasks only
int numObjectsPasted = 0;
if ((objects != null) && (objects.size() > 0)) {
// Paste tasks as children of the selected TaskGroup
AUndertaking[] selectedTasks = seln.getSelectedTasks(TaskSelectionState.ORDER_SELECTION);
TaskGroup taskParent = seln.getSelectedTaskParent();
int index;
// index at which new pasted Tasks will be placed.
if (taskParent != null) {
AUndertaking last = selectedTasks[selectedTasks.length - 1];
index = taskParent.getUndertakings().indexOf(last) + 1;
} else {
index = findLastSelectedRoot(selectedTasks);
}
// Create undo support
String presentationName = PASTE;
CompoundUndoableEdit editSeq = new CompoundUndoableEdit(presentationName, ProjectLID.Paste);
// If task applications are pasted, they will have
// null Design fields; they should "arrive" after
// the Design being pasted at the same time!
Design newDesign = null;
// Existing tasks are to be re-used if the paste
// is within the same project as the copy/cut.
Map<AUndertaking, AUndertaking> reuseTasks = null;
Iterator<Object> objIt = objects.iterator();
while (objIt.hasNext()) {
Object o = objIt.next();
// unique name and create and place the design.
if (o instanceof Design) {
newDesign = (Design) o;
makeDesignNameUnique(newDesign);
// Add an undo step after creating/placing
ProjectCmd.addNewDesign(project, newDesign, seln.getSelectedDesign(), presentationName, editSeq);
numObjectsPasted++;
} else // or to the Project. Create and place.
if (o instanceof AUndertaking) {
AUndertaking task = (AUndertaking) o;
// project or pasting copied tasks
if (reuseTasks == null) {
pasteTask(task, taskParent, index++, editSeq, presentationName);
numObjectsPasted++;
} else {
// In this case, a copied design is
// being pasted into the same project.
// Map each undertaking to the
// corresponding one in the current project
mapProjectTasks(task, project, reuseTasks, editSeq, presentationName);
}
} else // along when copying an Design.
if (o instanceof TaskApplication) {
TaskApplication taskApp = (TaskApplication) o;
if (reuseTasks != null) {
AUndertaking reuseTask = reuseTasks.get(taskApp.getTask());
if (reuseTask != null) {
taskApp.setTask(reuseTask);
}
}
// The undo edit for adding the Design will
// remove and restore the task-applications;
// simply add to the project.
project.setTaskApplication(taskApp);
} else if (o instanceof CogToolClipboard.ProjectScope) {
CogToolClipboard.ProjectScope projectScope = (CogToolClipboard.ProjectScope) o;
// a copied design into the same project
if (projectScope.getProject() != null) {
reuseTasks = new HashMap<AUndertaking, AUndertaking>();
}
}
}
// Done with undo/redo steps; add the compound change
// to the undo manager.
editSeq.end();
undoMgr.addEdit(editSeq);
interaction.setStatusMessage(numObjectsPasted + " " + pasteComplete);
} else {
interaction.setStatusMessage(nothingPasted);
}
return true;
} catch (IOException e) {
throw new RcvrClipboardException(e);
} catch (SAXException e) {
throw new RcvrClipboardException(e);
} catch (ParserConfigurationException e) {
throw new RcvrClipboardException(e);
} catch (ClipboardUtil.ClipboardException e) {
throw new RcvrClipboardException(e);
}
}
};
}
use of javax.xml.parsers.ParserConfigurationException in project buck by facebook.
the class AppleCxxPlatforms method buildWithExecutableChecker.
@VisibleForTesting
static AppleCxxPlatform buildWithExecutableChecker(ProjectFilesystem filesystem, AppleSdk targetSdk, String minVersion, String targetArchitecture, final AppleSdkPaths sdkPaths, BuckConfig buckConfig, AppleConfig appleConfig, ExecutableFinder executableFinder, Optional<ProcessExecutor> processExecutor, Optional<AppleToolchain> swiftToolChain) {
AppleCxxPlatform.Builder platformBuilder = AppleCxxPlatform.builder();
ImmutableList.Builder<Path> toolSearchPathsBuilder = ImmutableList.builder();
// Search for tools from most specific to least specific.
toolSearchPathsBuilder.add(sdkPaths.getSdkPath().resolve(USR_BIN)).add(sdkPaths.getSdkPath().resolve("Developer").resolve(USR_BIN)).add(sdkPaths.getPlatformPath().resolve("Developer").resolve(USR_BIN));
for (Path toolchainPath : sdkPaths.getToolchainPaths()) {
toolSearchPathsBuilder.add(toolchainPath.resolve(USR_BIN));
}
if (sdkPaths.getDeveloperPath().isPresent()) {
toolSearchPathsBuilder.add(sdkPaths.getDeveloperPath().get().resolve(USR_BIN));
toolSearchPathsBuilder.add(sdkPaths.getDeveloperPath().get().resolve("Tools"));
}
// TODO(bhamiltoncx): Add more and better cflags.
ImmutableList.Builder<String> cflagsBuilder = ImmutableList.builder();
cflagsBuilder.add("-isysroot", sdkPaths.getSdkPath().toString());
cflagsBuilder.add("-iquote", filesystem.getRootPath().toString());
cflagsBuilder.add("-arch", targetArchitecture);
cflagsBuilder.add(targetSdk.getApplePlatform().getMinVersionFlagPrefix() + minVersion);
if (targetSdk.getApplePlatform().equals(ApplePlatform.WATCHOS)) {
cflagsBuilder.add("-fembed-bitcode");
}
ImmutableList.Builder<String> ldflagsBuilder = ImmutableList.builder();
ldflagsBuilder.addAll(Linkers.iXlinker("-sdk_version", targetSdk.getVersion(), "-ObjC"));
if (targetSdk.getApplePlatform().equals(ApplePlatform.WATCHOS)) {
ldflagsBuilder.addAll(Linkers.iXlinker("-bitcode_verify", "-bitcode_hide_symbols", "-bitcode_symbol_map"));
}
// Populate Xcode version keys from Xcode's own Info.plist if available.
Optional<String> xcodeBuildVersion = Optional.empty();
Optional<Path> developerPath = sdkPaths.getDeveloperPath();
if (developerPath.isPresent()) {
Path xcodeBundlePath = developerPath.get().getParent();
if (xcodeBundlePath != null) {
File xcodeInfoPlistPath = xcodeBundlePath.resolve("Info.plist").toFile();
try {
NSDictionary parsedXcodeInfoPlist = (NSDictionary) PropertyListParser.parse(xcodeInfoPlistPath);
NSObject xcodeVersionObject = parsedXcodeInfoPlist.objectForKey("DTXcode");
if (xcodeVersionObject != null) {
Optional<String> xcodeVersion = Optional.of(xcodeVersionObject.toString());
platformBuilder.setXcodeVersion(xcodeVersion);
}
} catch (IOException e) {
LOG.warn("Error reading Xcode's info plist %s; ignoring Xcode versions", xcodeInfoPlistPath);
} catch (PropertyListFormatException | ParseException | ParserConfigurationException | SAXException e) {
LOG.warn("Error in parsing %s; ignoring Xcode versions", xcodeInfoPlistPath);
}
}
// different than the build number in the Info.plist, sigh.
if (processExecutor.isPresent()) {
xcodeBuildVersion = appleConfig.getXcodeBuildVersionSupplier(developerPath.get(), processExecutor.get()).get();
platformBuilder.setXcodeBuildVersion(xcodeBuildVersion);
LOG.debug("Xcode build version is: " + xcodeBuildVersion.orElse("<absent>"));
}
}
ImmutableList.Builder<String> versions = ImmutableList.builder();
versions.add(targetSdk.getVersion());
ImmutableList<String> toolchainVersions = targetSdk.getToolchains().stream().map(AppleToolchain::getVersion).flatMap(Optionals::toStream).collect(MoreCollectors.toImmutableList());
if (toolchainVersions.isEmpty()) {
if (!xcodeBuildVersion.isPresent()) {
throw new HumanReadableException("Failed to read toolchain versions and Xcode version.");
}
versions.add(xcodeBuildVersion.get());
} else {
versions.addAll(toolchainVersions);
}
String version = Joiner.on(':').join(versions.build());
ImmutableList<Path> toolSearchPaths = toolSearchPathsBuilder.build();
Tool clangPath = VersionedTool.of(getToolPath("clang", toolSearchPaths, executableFinder), "apple-clang", version);
Tool clangXxPath = VersionedTool.of(getToolPath("clang++", toolSearchPaths, executableFinder), "apple-clang++", version);
Tool ar = VersionedTool.of(getToolPath("ar", toolSearchPaths, executableFinder), "apple-ar", version);
Tool ranlib = VersionedTool.builder().setPath(getToolPath("ranlib", toolSearchPaths, executableFinder)).setName("apple-ranlib").setVersion(version).build();
Tool strip = VersionedTool.of(getToolPath("strip", toolSearchPaths, executableFinder), "apple-strip", version);
Tool nm = VersionedTool.of(getToolPath("nm", toolSearchPaths, executableFinder), "apple-nm", version);
Tool actool = VersionedTool.of(getToolPath("actool", toolSearchPaths, executableFinder), "apple-actool", version);
Tool ibtool = VersionedTool.of(getToolPath("ibtool", toolSearchPaths, executableFinder), "apple-ibtool", version);
Tool momc = VersionedTool.of(getToolPath("momc", toolSearchPaths, executableFinder), "apple-momc", version);
Tool xctest = VersionedTool.of(getToolPath("xctest", toolSearchPaths, executableFinder), "apple-xctest", version);
Tool dsymutil = VersionedTool.of(getToolPath("dsymutil", toolSearchPaths, executableFinder), "apple-dsymutil", version);
Tool lipo = VersionedTool.of(getToolPath("lipo", toolSearchPaths, executableFinder), "apple-lipo", version);
Tool lldb = VersionedTool.of(getToolPath("lldb", toolSearchPaths, executableFinder), "lldb", version);
Optional<Path> stubBinaryPath = targetSdk.getApplePlatform().getStubBinaryPath().map(input -> sdkPaths.getSdkPath().resolve(input));
CxxBuckConfig config = new CxxBuckConfig(buckConfig);
UserFlavor targetFlavor = UserFlavor.of(Flavor.replaceInvalidCharacters(targetSdk.getName() + "-" + targetArchitecture), String.format("SDK: %s, architecture: %s", targetSdk.getName(), targetArchitecture));
ImmutableBiMap.Builder<Path, Path> sanitizerPaths = ImmutableBiMap.builder();
sanitizerPaths.put(sdkPaths.getSdkPath(), Paths.get("APPLE_SDKROOT"));
sanitizerPaths.put(sdkPaths.getPlatformPath(), Paths.get("APPLE_PLATFORM_DIR"));
if (sdkPaths.getDeveloperPath().isPresent()) {
sanitizerPaths.put(sdkPaths.getDeveloperPath().get(), Paths.get("APPLE_DEVELOPER_DIR"));
}
DebugPathSanitizer compilerDebugPathSanitizer = new PrefixMapDebugPathSanitizer(config.getDebugPathSanitizerLimit(), File.separatorChar, Paths.get("."), sanitizerPaths.build(), filesystem.getRootPath().toAbsolutePath(), CxxToolProvider.Type.CLANG, filesystem);
DebugPathSanitizer assemblerDebugPathSanitizer = new MungingDebugPathSanitizer(config.getDebugPathSanitizerLimit(), File.separatorChar, Paths.get("."), sanitizerPaths.build());
ImmutableList<String> cflags = cflagsBuilder.build();
ImmutableMap.Builder<String, String> macrosBuilder = ImmutableMap.builder();
macrosBuilder.put("SDKROOT", sdkPaths.getSdkPath().toString());
macrosBuilder.put("PLATFORM_DIR", sdkPaths.getPlatformPath().toString());
macrosBuilder.put("CURRENT_ARCH", targetArchitecture);
if (sdkPaths.getDeveloperPath().isPresent()) {
macrosBuilder.put("DEVELOPER_DIR", sdkPaths.getDeveloperPath().get().toString());
}
ImmutableMap<String, String> macros = macrosBuilder.build();
Optional<String> buildVersion = Optional.empty();
Path platformVersionPlistPath = sdkPaths.getPlatformPath().resolve("version.plist");
try (InputStream versionPlist = Files.newInputStream(platformVersionPlistPath)) {
NSDictionary versionInfo = (NSDictionary) PropertyListParser.parse(versionPlist);
if (versionInfo != null) {
NSObject productBuildVersion = versionInfo.objectForKey("ProductBuildVersion");
if (productBuildVersion != null) {
buildVersion = Optional.of(productBuildVersion.toString());
} else {
LOG.warn("In %s, missing ProductBuildVersion. Build version will be unset for this platform.", platformVersionPlistPath);
}
} else {
LOG.warn("Empty version plist in %s. Build version will be unset for this platform.", platformVersionPlistPath);
}
} catch (NoSuchFileException e) {
LOG.warn("%s does not exist. Build version will be unset for this platform.", platformVersionPlistPath);
} catch (PropertyListFormatException | SAXException | ParserConfigurationException | ParseException | IOException e) {
// Some other error occurred, print the exception since it may contain error details.
LOG.warn(e, "Failed to parse %s. Build version will be unset for this platform.", platformVersionPlistPath);
}
PreprocessorProvider aspp = new PreprocessorProvider(new ConstantToolProvider(clangPath), CxxToolProvider.Type.CLANG);
CompilerProvider as = new CompilerProvider(new ConstantToolProvider(clangPath), CxxToolProvider.Type.CLANG);
PreprocessorProvider cpp = new PreprocessorProvider(new ConstantToolProvider(clangPath), CxxToolProvider.Type.CLANG);
CompilerProvider cc = new CompilerProvider(new ConstantToolProvider(clangPath), CxxToolProvider.Type.CLANG);
PreprocessorProvider cxxpp = new PreprocessorProvider(new ConstantToolProvider(clangXxPath), CxxToolProvider.Type.CLANG);
CompilerProvider cxx = new CompilerProvider(new ConstantToolProvider(clangXxPath), CxxToolProvider.Type.CLANG);
ImmutableList.Builder<String> whitelistBuilder = ImmutableList.builder();
whitelistBuilder.add("^" + Pattern.quote(sdkPaths.getSdkPath().toString()) + "\\/.*");
whitelistBuilder.add("^" + Pattern.quote(sdkPaths.getPlatformPath().toString() + "/Developer/Library/Frameworks") + "\\/.*");
for (Path toolchainPath : sdkPaths.getToolchainPaths()) {
LOG.debug("Apple toolchain path: %s", toolchainPath);
try {
whitelistBuilder.add("^" + Pattern.quote(toolchainPath.toRealPath().toString()) + "\\/.*");
} catch (IOException e) {
LOG.warn(e, "Apple toolchain path could not be resolved: %s", toolchainPath);
}
}
HeaderVerification headerVerification = config.getHeaderVerification().withPlatformWhitelist(whitelistBuilder.build());
LOG.debug("Headers verification platform whitelist: %s", headerVerification.getPlatformWhitelist());
CxxPlatform cxxPlatform = CxxPlatforms.build(targetFlavor, Platform.MACOS, config, as, aspp, cc, cxx, cpp, cxxpp, new DefaultLinkerProvider(LinkerProvider.Type.DARWIN, new ConstantToolProvider(clangXxPath)), ImmutableList.<String>builder().addAll(cflags).addAll(ldflagsBuilder.build()).build(), strip, new BsdArchiver(ar), ranlib, new PosixNmSymbolNameTool(nm), cflagsBuilder.build(), ImmutableList.of(), cflags, ImmutableList.of(), "dylib", "%s.dylib", "a", "o", compilerDebugPathSanitizer, assemblerDebugPathSanitizer, macros, Optional.empty(), headerVerification);
ApplePlatform applePlatform = targetSdk.getApplePlatform();
ImmutableList.Builder<Path> swiftOverrideSearchPathBuilder = ImmutableList.builder();
AppleSdkPaths.Builder swiftSdkPathsBuilder = AppleSdkPaths.builder().from(sdkPaths);
if (swiftToolChain.isPresent()) {
swiftOverrideSearchPathBuilder.add(swiftToolChain.get().getPath().resolve(USR_BIN));
swiftSdkPathsBuilder.setToolchainPaths(ImmutableList.of(swiftToolChain.get().getPath()));
}
Optional<SwiftPlatform> swiftPlatform = getSwiftPlatform(applePlatform.getName(), targetArchitecture + "-apple-" + applePlatform.getSwiftName().orElse(applePlatform.getName()) + minVersion, version, swiftSdkPathsBuilder.build(), swiftOverrideSearchPathBuilder.addAll(toolSearchPaths).build(), executableFinder);
platformBuilder.setCxxPlatform(cxxPlatform).setSwiftPlatform(swiftPlatform).setAppleSdk(targetSdk).setAppleSdkPaths(sdkPaths).setMinVersion(minVersion).setBuildVersion(buildVersion).setActool(actool).setIbtool(ibtool).setMomc(momc).setCopySceneKitAssets(getOptionalTool("copySceneKitAssets", toolSearchPaths, executableFinder, version)).setXctest(xctest).setDsymutil(dsymutil).setLipo(lipo).setStubBinary(stubBinaryPath).setLldb(lldb).setCodesignAllocate(getOptionalTool("codesign_allocate", toolSearchPaths, executableFinder, version)).setCodesignProvider(appleConfig.getCodesignProvider());
return platformBuilder.build();
}
use of javax.xml.parsers.ParserConfigurationException in project buck by facebook.
the class BuckXmlTestRunListener method addMainTestResult.
/**
* Adds one more XML element to the test_result.xml tracking the
* result of the whole process.
*/
private void addMainTestResult() {
try {
File resultFile = getResultFile(mReportDir);
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
Document doc = docBuilder.parse(resultFile);
Node testsuite = doc.getElementsByTagName("testsuite").item(0);
if (mRunFailureMessage != null) {
Element failureNode = doc.createElement("failure");
failureNode.setTextContent(mRunFailureMessage);
testsuite.appendChild(failureNode);
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
DOMSource source = new DOMSource(doc);
StreamResult result = new StreamResult(resultFile);
transformer.transform(source, result);
}
} catch (IOException | ParserConfigurationException | SAXException | TransformerException e) {
throw new RuntimeException(e);
}
}
Aggregations