Skip to content

Commit

Permalink
Refactor XML file handling
Browse files Browse the repository at this point in the history
  • Loading branch information
jonahgraham committed Aug 16, 2023
1 parent b9cfdf9 commit c7169b3
Show file tree
Hide file tree
Showing 63 changed files with 414 additions and 241 deletions.
4 changes: 2 additions & 2 deletions build/org.eclipse.cdt.autotools.core/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %Bundle-Name.0
Bundle-SymbolicName: org.eclipse.cdt.autotools.core;singleton:=true
Bundle-Version: 2.2.0.qualifier
Bundle-Version: 2.2.100.qualifier
Bundle-Activator: org.eclipse.cdt.autotools.core.AutotoolsPlugin
Bundle-Localization: plugin
Require-Bundle: org.eclipse.ui;bundle-version="3.4.0",
Expand All @@ -13,7 +13,7 @@ Require-Bundle: org.eclipse.ui;bundle-version="3.4.0",
org.eclipse.core.resources;bundle-version="3.4.0",
org.eclipse.ui.ide;bundle-version="3.4.0",
org.eclipse.cdt.managedbuilder.core;bundle-version="5.0.100",
org.eclipse.cdt.core;bundle-version="6.5.0",
org.eclipse.cdt.core;bundle-version="8.3.0",
org.eclipse.cdt.ui;bundle-version="5.1.0",
org.eclipse.cdt.managedbuilder.ui;bundle-version="5.0.100",
org.eclipse.cdt.managedbuilder.gnu.ui;bundle-version="5.0.100",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import java.util.Random;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.eclipse.cdt.autotools.core.AutotoolsNewProjectNature;
Expand All @@ -38,6 +37,7 @@
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
import org.eclipse.cdt.core.settings.model.extension.CConfigurationData;
import org.eclipse.cdt.internal.autotools.core.configure.AutotoolsConfiguration.Option;
import org.eclipse.cdt.internal.core.XmlProcessorFactoryCdt;
import org.eclipse.cdt.managedbuilder.core.BuildException;
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
import org.eclipse.cdt.managedbuilder.core.IHoldsOptions;
Expand All @@ -55,6 +55,7 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
Expand Down Expand Up @@ -203,8 +204,7 @@ private Map<String, IAConfiguration> getSavedConfigs(IProject project) {
IPath fileLocation = project.getLocation().append(CFG_FILE_NAME);
File dirFile = fileLocation.toFile();
Map<String, IAConfiguration> cfgList = new HashMap<>();
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
DocumentBuilder db = XmlProcessorFactoryCdt.createDocumentBuilderWithErrorOnDOCTYPE();
if (dirFile.exists()) {
Document d = db.parse(dirFile);
Element e = d.getDocumentElement();
Expand Down Expand Up @@ -269,7 +269,8 @@ else if (nameNode != null) {
}
}
} catch (ParserConfigurationException | SAXException | IOException e) {
e.printStackTrace();
Platform.getLog(AutotoolsConfigurationManager.class)
.error("Error while parsing .autotools file in project", e); //$NON-NLS-1$
}
}
return list;
Expand Down
4 changes: 2 additions & 2 deletions build/org.eclipse.cdt.autotools.tests/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %bundleName
Bundle-SymbolicName: org.eclipse.cdt.autotools.tests;singleton:=true
Bundle-Version: 2.1.0.qualifier
Bundle-Version: 2.1.100.qualifier
Bundle-Vendor: %provider
Bundle-Localization: plugin
Require-Bundle: org.eclipse.ui,
Expand All @@ -13,7 +13,7 @@ Require-Bundle: org.eclipse.ui,
org.junit,
org.eclipse.ui.ide,
org.eclipse.jface.text,
org.eclipse.cdt.core,
org.eclipse.cdt.core;bundle-version="8.3.0",
org.eclipse.cdt.autotools.ui;bundle-version="1.0.0",
org.eclipse.cdt.core.tests
Bundle-ActivationPolicy: lazy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@
import java.util.Map;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.eclipse.cdt.autotools.core.AutotoolsOptionConstants;
import org.eclipse.cdt.autotools.core.IAutotoolsOption;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
import org.eclipse.cdt.internal.autotools.core.configure.AutotoolsConfigurationManager;
import org.eclipse.cdt.internal.core.XmlProcessorFactoryCdt;
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
import org.eclipse.cdt.managedbuilder.core.ManagedCProjectNature;
Expand Down Expand Up @@ -535,8 +535,7 @@ public void testGetAndUpdateConfigureOptions() throws Exception {
try {
IPath fileLocation = testProject.getLocation().append(".autotools"); //$NON-NLS-1$
File dirFile = fileLocation.toFile();
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
DocumentBuilder db = XmlProcessorFactoryCdt.createDocumentBuilderWithErrorOnDOCTYPE();
assertTrue(dirFile.exists());
Document d = db.parse(dirFile);
Element e = d.getDocumentElement();
Expand Down
4 changes: 2 additions & 2 deletions build/org.eclipse.cdt.autotools.ui.tests/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %bundleName
Bundle-SymbolicName: org.eclipse.cdt.autotools.ui.tests
Bundle-Version: 1.1.0.qualifier
Bundle-Version: 1.1.100.qualifier
Bundle-Localization: plugin
Require-Bundle: org.eclipse.swtbot.go,
org.eclipse.core.resources,
org.eclipse.cdt.core
org.eclipse.cdt.core;bundle-version="8.3.0"
Bundle-ActivationPolicy: lazy
Fragment-Host: org.eclipse.cdt.autotools.ui
Bundle-RequiredExecutionEnvironment: JavaSE-17
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
import java.util.regex.Pattern;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.eclipse.cdt.internal.core.XmlProcessorFactoryCdt;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRoot;
Expand Down Expand Up @@ -108,8 +108,7 @@ public void t1canSetConfigParm() throws Exception {
File f = new File(path.toOSString());
assertTrue(f.exists());

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
DocumentBuilder db = XmlProcessorFactoryCdt.createDocumentBuilderWithErrorOnDOCTYPE();
Document d = db.parse(f);
Element e = d.getDocumentElement();
// Get the stored configuration data
Expand Down Expand Up @@ -320,8 +319,7 @@ public void t3newConfigCopiesParms() throws Exception {
path = project.getLocation().append(".autotools");
f = new File(path.toOSString());
assertTrue(f.exists());
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
DocumentBuilder db = XmlProcessorFactoryCdt.createDocumentBuilderWithErrorOnDOCTYPE();
Document d = db.parse(f);
Element e = d.getDocumentElement();
// Get the stored configuration data
Expand Down
4 changes: 2 additions & 2 deletions build/org.eclipse.cdt.autotools.ui/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %Bundle-Name.0
Bundle-SymbolicName: org.eclipse.cdt.autotools.ui;singleton:=true
Bundle-Version: 2.2.100.qualifier
Bundle-Version: 2.2.200.qualifier
Bundle-Activator: org.eclipse.cdt.autotools.ui.AutotoolsUIPlugin
Bundle-Localization: plugin
Bundle-Vendor: %provider
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
org.eclipse.cdt.autotools.core;bundle-version="1.0.0",
org.eclipse.cdt.core;bundle-version="5.1.0",
org.eclipse.cdt.core;bundle-version="8.3.0",
org.eclipse.core.resources;bundle-version="3.5.0",
org.eclipse.cdt.managedbuilder.core;bundle-version="6.0.0",
org.eclipse.jface.text;bundle-version="3.5.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.eclipse.cdt.internal.autotools.ui.HTMLPrinter;
import org.eclipse.cdt.internal.autotools.ui.HTMLTextPresenter;
import org.eclipse.cdt.internal.autotools.ui.preferences.AutotoolsEditorPreferenceConstants;
import org.eclipse.cdt.internal.core.XmlProcessorFactoryCdt;
import org.eclipse.core.filesystem.URIUtil;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
Expand Down Expand Up @@ -168,12 +169,14 @@ protected static Document getACDoc(String acDocVer) {
docStream = new FileInputStream(p.toFile());
}
}
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilderFactory factory = XmlProcessorFactoryCdt
.createDocumentBuilderFactoryIgnoringDOCTYPE();
factory.setValidating(false);
try {
DocumentBuilder builder = factory.newDocumentBuilder();
doc = builder.parse(docStream);
} catch (SAXException | ParserConfigurationException | IOException saxEx) {
AutotoolsPlugin.log(saxEx);
doc = null;
} finally {
if (docStream != null)
Expand Down Expand Up @@ -218,7 +221,8 @@ protected static Document getAMDoc(String amDocVer) {
docStream = new FileInputStream(p.toFile());
}
}
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilderFactory factory = XmlProcessorFactoryCdt
.createDocumentBuilderFactoryIgnoringDOCTYPE();
factory.setValidating(false);
try {
DocumentBuilder builder = factory.newDocumentBuilder();
Expand Down
4 changes: 2 additions & 2 deletions build/org.eclipse.cdt.make.core/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.cdt.make.core; singleton:=true
Bundle-Version: 7.6.200.qualifier
Bundle-Version: 7.6.300.qualifier
Bundle-Activator: org.eclipse.cdt.make.core.MakeCorePlugin
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Expand All @@ -19,7 +19,7 @@ Export-Package: org.eclipse.cdt.make.core,
org.eclipse.cdt.make.internal.core.scannerconfig.jobs;x-internal:=true,
org.eclipse.cdt.make.internal.core.scannerconfig.util;x-internal:=true,
org.eclipse.cdt.make.internal.core.scannerconfig2;x-internal:=true
Require-Bundle: org.eclipse.cdt.core;bundle-version="[8.0.0,9.0.0)",
Require-Bundle: org.eclipse.cdt.core;bundle-version="[8.3.0,9.0.0)",
org.eclipse.core.resources;bundle-version="[3.2.0,4.0.0)",
org.eclipse.core.variables;bundle-version="[3.1.100,4.0.0)",
org.eclipse.core.runtime;bundle-version="[3.2.0,4.0.0)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@
import java.util.List;
import java.util.Map.Entry;

import javax.xml.parsers.DocumentBuilderFactory;

import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.ICDescriptor;
import org.eclipse.cdt.core.settings.model.ICStorageElement;
import org.eclipse.cdt.core.settings.model.XmlStorageUtil;
import org.eclipse.cdt.internal.core.XmlProcessorFactoryCdt;
import org.eclipse.cdt.make.core.IMakeCommonBuildInfo;
import org.eclipse.cdt.make.core.IMakeTarget;
import org.eclipse.cdt.make.core.MakeCorePlugin;
Expand Down Expand Up @@ -237,7 +236,7 @@ public void saveTargets() throws CoreException {
*/
protected ICStorageElement translateInputStreamToDocument(InputStream input) {
try {
Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(input);
Document document = XmlProcessorFactoryCdt.createDocumentBuilderWithErrorOnDOCTYPE().parse(input);
return XmlStorageUtil.createCStorageTree(document);
} catch (Exception e) {
MakeCorePlugin.log(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,14 @@
import java.util.Map;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import org.eclipse.cdt.internal.core.XmlProcessorFactoryCdt;
import org.eclipse.cdt.make.core.MakeCorePlugin;
import org.eclipse.cdt.make.core.scannerconfig.IDiscoveredPathManager.IDiscoveredScannerInfoSerializable;
import org.eclipse.cdt.make.core.scannerconfig.InfoContext;
Expand Down Expand Up @@ -159,7 +158,7 @@ private Document getDocument(IProject project) throws CoreException {
Document document = ref != null ? ref.get() : null;
if (document == null) {
try {
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
DocumentBuilder builder = XmlProcessorFactoryCdt.createDocumentBuilderWithErrorOnDOCTYPE();
IPath path = getDiscoveredScannerConfigStore(project);
if (path.toFile().exists()) {
// read form file
Expand Down Expand Up @@ -292,7 +291,8 @@ public void saveDiscoveredScannerInfoToState(IProject project, InfoContext conte

// Transform the document to something we can save in a file
ByteArrayOutputStream stream = new ByteArrayOutputStream();
Transformer transformer = TransformerFactory.newInstance().newTransformer();
Transformer transformer = XmlProcessorFactoryCdt.createTransformerFactoryWithErrorOnDOCTYPE()
.newTransformer();
transformer.setOutputProperty(OutputKeys.METHOD, "xml"); //$NON-NLS-1$
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); //$NON-NLS-1$
transformer.setOutputProperty(OutputKeys.INDENT, "yes"); //$NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Export-Package: org.eclipse.cdt.build.core.scannerconfig,
org.eclipse.cdt.managedbuilder.templateengine,
org.eclipse.cdt.managedbuilder.templateengine.processes,
org.eclipse.cdt.newmake.core
Require-Bundle: org.eclipse.cdt.core;bundle-version="[8.0.0,9.0.0)",
Require-Bundle: org.eclipse.cdt.core;bundle-version="[8.3.0,9.0.0)",
org.eclipse.core.resources;bundle-version="[3.14.0,4.0.0)",
org.eclipse.core.runtime;bundle-version="[3.2.0,4.0.0)",
org.eclipse.ui;bundle-version="[3.2.0,4.0.0)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,12 @@
import java.util.TreeMap;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.FactoryConfigurationError;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.TransformerFactoryConfigurationError;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
Expand All @@ -67,6 +65,7 @@
import org.eclipse.cdt.core.settings.model.ICSettingEntry;
import org.eclipse.cdt.core.settings.model.XmlStorageUtil;
import org.eclipse.cdt.core.settings.model.extension.CConfigurationData;
import org.eclipse.cdt.internal.core.XmlProcessorFactoryCdt;
import org.eclipse.cdt.managedbuilder.buildproperties.IBuildProperty;
import org.eclipse.cdt.managedbuilder.buildproperties.IBuildPropertyManager;
import org.eclipse.cdt.managedbuilder.envvar.IEnvironmentVariableProvider;
Expand Down Expand Up @@ -1089,7 +1088,7 @@ public static boolean saveBuildInfoLegacy(IProject project, boolean force) {
// Create document
Exception err = null;
try {
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
DocumentBuilder builder = XmlProcessorFactoryCdt.createDocumentBuilderWithErrorOnDOCTYPE();
Document doc = builder.newDocument();

// Get the build information for the project
Expand All @@ -1111,7 +1110,8 @@ public static boolean saveBuildInfoLegacy(IProject project, boolean force) {

// Transform the document to something we can save in a file
ByteArrayOutputStream stream = new ByteArrayOutputStream();
Transformer transformer = TransformerFactory.newInstance().newTransformer();
Transformer transformer = XmlProcessorFactoryCdt.createTransformerFactoryWithErrorOnDOCTYPE()
.newTransformer();
transformer.setOutputProperty(OutputKeys.METHOD, "xml"); //$NON-NLS-1$
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); //$NON-NLS-1$
transformer.setOutputProperty(OutputKeys.INDENT, "yes"); //$NON-NLS-1$
Expand Down Expand Up @@ -1261,7 +1261,7 @@ private static boolean updateBuildInfo(IProject project, boolean force) throws C
// Create document
Exception err = null;
try {
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
DocumentBuilder builder = XmlProcessorFactoryCdt.createDocumentBuilderWithErrorOnDOCTYPE();
Document doc = builder.newDocument();
// Get the build information for the project
Expand All @@ -1284,7 +1284,7 @@ private static boolean updateBuildInfo(IProject project, boolean force) throws C
// Transform the document to something we can save in a file
ByteArrayOutputStream stream = new ByteArrayOutputStream();
Transformer transformer = TransformerFactory.newInstance().newTransformer();
Transformer transformer = XmlProcessorFactoryCdt.createTransformerFactoryWithErrorOnDOCTYPE().newTransformer();
transformer.setOutputProperty(OutputKeys.METHOD, "xml"); //$NON-NLS-1$
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); //$NON-NLS-1$
transformer.setOutputProperty(OutputKeys.INDENT, "yes"); //$NON-NLS-1$
Expand Down Expand Up @@ -1836,7 +1836,7 @@ private static ManagedBuildInfo loadOldStyleBuildInfo(final IProject project) th

// So there is a project file, load the information there
try (InputStream stream = new FileInputStream(cdtbuild)) {
DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
DocumentBuilder parser = XmlProcessorFactoryCdt.createDocumentBuilderWithErrorOnDOCTYPE();
Document document = parser.parse(stream);
String fileVersion = null;

Expand Down Expand Up @@ -2516,7 +2516,7 @@ public static boolean manages(IResource resource) {
// if (file.exists()) {
// try {
// InputStream stream = file.getContents();
// DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
// DocumentBuilder parser = XmlProcessorFactoryCdt.createDocumentBuilderWithErrorOnDOCTYPE();
// Document document = parser.parse(stream);
// NodeList nodes = document.getElementsByTagName(ROOT_NODE_NAME);
// return (nodes.getLength() > 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
import java.util.Vector;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.eclipse.cdt.internal.core.XmlProcessorFactoryCdt;
import org.eclipse.cdt.managedbuilder.core.BuildException;
import org.eclipse.cdt.managedbuilder.core.IBuildObject;
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
Expand Down Expand Up @@ -709,7 +709,7 @@ public static void doProjectUpdate(IProgressMonitor monitor, final IProject proj
try {
// Load the old build file
InputStream stream = new FileInputStream(settingsFile);
DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
DocumentBuilder parser = XmlProcessorFactoryCdt.createDocumentBuilderWithErrorOnDOCTYPE();
Document document = parser.parse(stream);

// Clone the target based on the proper target definition
Expand Down
Loading

0 comments on commit c7169b3

Please sign in to comment.