Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -380,13 +380,10 @@ private void doScanZippedNetBeansOrgSources() throws IOException {

private String parseCNB(final ZipEntry projectXML) throws IOException {
Document doc;
InputStream is = nbSrcZip.getInputStream(projectXML);
try {
doc = XMLUtil.parse(new InputSource(is), false, true, null, null);
try (InputStream is = nbSrcZip.getInputStream(projectXML)) {
doc = XMLUtil.parse(new InputSource(is), false, true, true, null, null);
} catch (SAXException e) {
throw (IOException) new IOException(projectXML + ": " + e.toString()).initCause(e); // NOI18N
} finally {
is.close();
throw new IOException(projectXML + ": " + e.toString(), e); // NOI18N
}
Element docel = doc.getDocumentElement();
Element type = XMLUtil.findElement(docel, "type", "http://www.netbeans.org/ns/project/1"); // NOI18N
Expand Down
2 changes: 1 addition & 1 deletion ergonomics/ide.ergonomics/nbproject/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
javac.source=1.8
javac.release=21
javac.compilerargs=-Xlint -Xlint:-serial

javadoc.arch=${basedir}/arch.xml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.File;
import java.io.FileInputStream;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collection;
Expand All @@ -38,7 +39,6 @@
import javax.swing.Icon;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.xml.parsers.DocumentBuilder;
import org.netbeans.api.autoupdate.UpdateElement;
import org.netbeans.api.progress.ProgressHandle;
import org.netbeans.api.project.Project;
Expand All @@ -63,15 +63,15 @@
import org.openide.util.lookup.ProxyLookup;
import org.openide.util.lookup.ServiceProvider;
import org.w3c.dom.Document;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.netbeans.api.project.ui.OpenProjects;
import org.netbeans.spi.project.ui.LogicalViewProvider;
import org.openide.filesystems.FileUtil;
import org.openide.loaders.DataFolder;
import org.openide.nodes.FilterNode;
import org.openide.util.NbBundle;
import org.openide.util.RequestProcessor.Task;
import org.openide.xml.XMLUtil;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

/**
Expand Down Expand Up @@ -116,20 +116,15 @@ Document dom(String relative) {
}
File f = FileUtil.toFile(fo);
try {
DocumentBuilder b = DocumentBuilderFactory.newInstance().newDocumentBuilder();
if (f != null) {
doc = b.parse(f);
} else {
InputStream is = fo.getInputStream();
doc = b.parse(is);
InputStream is = f != null ? new FileInputStream(f) : fo.getInputStream();
try (is) {
doc = XMLUtil.parse(new InputSource(is), false, false, true, null, null);
}
if (doms == null) {
doms = new HashMap<String,Document>();
}
doms.put(relative, doc);
return doc;
} catch (ParserConfigurationException parserConfigurationException) {
LOG.log(Level.WARNING, "Cannot configure XML parser", parserConfigurationException); // NOI18N
} catch (SAXException sAXException) {
LOG.log(Level.INFO, "XML broken in " + f, sAXException); // NOI18N
} catch (Exception any) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public ProjectProblemsProvider getProblemProvider() {

private Document loadConfig(FileObject config) throws IOException, SAXException {
synchronized (configIOLock) {
return XMLUtil.parse(new InputSource(config.toURL().toString()), false, true, null, null);
return XMLUtil.parse(new InputSource(config.toURL().toString()), false, true, true, null, null);
}
}

Expand Down Expand Up @@ -281,7 +281,7 @@ public void run() {
if (str != null) {
Document doc;
try {
doc = XMLUtil.parse(new InputSource(new StringReader(str)), false, true, null, null);
doc = XMLUtil.parse(new InputSource(new StringReader(str)), false, true, true, null, null);
return XMLUtil.findElement(doc.getDocumentElement(), elementName, namespace);
} catch (SAXException ex) {
LOG.log(Level.FINE, "cannot parse", ex);
Expand Down Expand Up @@ -327,7 +327,7 @@ private void lazyAttachListener() {
String str = (String) projectDirectory.getAttribute(AUX_CONFIG);
if (str != null) {
try {
doc = XMLUtil.parse(new InputSource(new StringReader(str)), false, true, null, null);
doc = XMLUtil.parse(new InputSource(new StringReader(str)), false, true, true, null, null);
} catch (SAXException ex) {
LOG.log(Level.FINE, "cannot parse", ex);
} catch (IOException ex) {
Expand Down Expand Up @@ -396,7 +396,7 @@ private void lazyAttachListener() {
String str = (String) projectDirectory.getAttribute(AUX_CONFIG);
if (str != null) {
try {
doc = XMLUtil.parse(new InputSource(new StringReader(str)), false, true, null, null);
doc = XMLUtil.parse(new InputSource(new StringReader(str)), false, true, true, null, null);
} catch (SAXException | IOException ex) {
Exceptions.printStackTrace(ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ private byte[] applyBuildExtensions(byte[] resultData, AntBuildExtender ext) {
ByteArrayInputStream in2 = new ByteArrayInputStream(resultData);
InputSource is = new InputSource(in2);

Document doc = XMLUtil.parse(is, false, true, null, null);
Document doc = XMLUtil.parse(is, false, true, true, null, null);
Element el = doc.getDocumentElement();
Node firstSubnode = el.getFirstChild();
//TODO check if first one is text and use it as indentation..
Expand Down Expand Up @@ -495,11 +495,7 @@ private byte[] applyBuildExtensions(byte[] resultData, AntBuildExtender ext) {
XMLUtil.write(doc, out, "UTF-8"); //NOI18N
return out.toByteArray();
}
catch (IOException ex) {
Exceptions.printStackTrace(ex);
return resultData;
}
catch (SAXException ex) {
catch (IOException | SAXException ex) {
Exceptions.printStackTrace(ex);
return resultData;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@
import java.util.concurrent.Callable;
import java.util.logging.Logger;
import javax.swing.Icon;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.netbeans.api.annotations.common.NonNull;
import org.netbeans.api.annotations.common.NullAllowed;
import org.netbeans.api.java.classpath.ClassPath;
Expand Down Expand Up @@ -579,23 +576,6 @@ public Project getOwningProject() {

}

private static final DocumentBuilder db;
static {
try {
db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
} catch (ParserConfigurationException e) {
throw new AssertionError(e);
}
}
// private static Document createNewDocument() {
// // #50198: for thread safety, use a separate document.
// // Using XMLUtil.createDocument is much too slow.
// synchronized (db) {
// return db.newDocument();
// }
// }
//
//
@NonNull
private Runnable newStartMainUpdaterAction() {
return () -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
package org.netbeans.modules.maven.grammar;

import java.io.IOException;
import java.util.concurrent.atomic.AtomicReference;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.netbeans.api.annotations.common.StaticResource;
Expand All @@ -42,7 +41,6 @@
import org.openide.filesystems.FileLock;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileUtil;
import org.openide.filesystems.MIMEResolver;
import org.openide.loaders.DataObjectExistsException;
import org.openide.loaders.MultiDataObject;
import org.openide.loaders.MultiFileLoader;
Expand Down Expand Up @@ -187,7 +185,7 @@ static String annotateWithProjectName(FileObject primaryFile) { // #154508
if (primaryFile.getNameExt().equals("pom.xml")) { // NOI18N
try {
//TODO faster and less memory intensive to have just FileObject().asText()-> regexp?
Element artifactId = XMLUtil.findElement(XMLUtil.parse(new InputSource(primaryFile.toURL().toString()), false, false, XMLUtil.defaultErrorHandler(), null).getDocumentElement(), "artifactId", null); // NOI18N
Element artifactId = XMLUtil.findElement(XMLUtil.parse(new InputSource(primaryFile.toURL().toString()), false, false, true, XMLUtil.defaultErrorHandler(), null).getDocumentElement(), "artifactId", null); // NOI18N
if (artifactId != null) {
String text = XMLUtil.findText(artifactId);
if (text != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ public static Map<String,List<String>> getLifecyclePlugins(String packaging, @Nu
return Collections.emptyMap();
}
private static Map<String,List<String>> parsePhases(String u, String packaging) throws Exception {
Document doc = XMLUtil.parse(new InputSource(u), false, false, XMLUtil.defaultErrorHandler(), null);
Document doc = XMLUtil.parse(new InputSource(u), false, false, true, XMLUtil.defaultErrorHandler(), null);
for (Element componentsEl : XMLUtil.findSubElements(doc.getDocumentElement())) {
for (Element componentEl : XMLUtil.findSubElements(componentsEl)) {
if (XMLUtil.findText(XMLUtil.findElement(componentEl, "role", null)).trim().equals("org.apache.maven.lifecycle.mapping.LifecycleMapping")
Expand Down Expand Up @@ -379,8 +379,8 @@ private static Map<String,List<String>> parsePhases(String u, String packaging)
return null;
}
LOG.log(Level.FINER, "parsing plugin.xml from {0}", jar);
try {
return XMLUtil.parse(new InputSource("jar:" + BaseUtilities.toURI(jar) + "!/META-INF/maven/plugin.xml"), false, false, XMLUtil.defaultErrorHandler(), null);
try {
return XMLUtil.parse(new InputSource("jar:" + BaseUtilities.toURI(jar) + "!/META-INF/maven/plugin.xml"), false, false, true, XMLUtil.defaultErrorHandler(), null);
} catch (Exception x) {
LOG.log(Level.FINE, "could not parse " + jar, x.toString());
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public ProjectProblemsProvider getProblemProvider() {

private Document loadConfig(FileObject config) throws IOException, SAXException {
synchronized (configIOLock) {
return XMLUtil.parse(new InputSource(config.toURL().toString()), false, true, null, null);
return XMLUtil.parse(new InputSource(config.toURL().toString()), false, true, true, null, null);
}
}

Expand Down Expand Up @@ -283,7 +283,7 @@ public void run() {
if (str != null) {
Document doc;
try {
doc = XMLUtil.parse(new InputSource(new StringReader(str)), false, true, null, null);
doc = XMLUtil.parse(new InputSource(new StringReader(str)), false, true, true, null, null);
return XMLUtil.findElement(doc.getDocumentElement(), elementName, namespace);
} catch (SAXException ex) {
LOG.log(Level.FINE, "cannot parse", ex);
Expand Down Expand Up @@ -329,7 +329,7 @@ private void lazyAttachListener() {
String str = (String) projectDirectory.getAttribute(AUX_CONFIG);
if (str != null) {
try {
doc = XMLUtil.parse(new InputSource(new StringReader(str)), false, true, null, null);
doc = XMLUtil.parse(new InputSource(new StringReader(str)), false, true, true, null, null);
} catch (SAXException ex) {
LOG.log(Level.FINE, "cannot parse", ex);
} catch (IOException ex) {
Expand Down Expand Up @@ -398,7 +398,7 @@ private void lazyAttachListener() {
String str = (String) projectDirectory.getAttribute(AUX_CONFIG);
if (str != null) {
try {
doc = XMLUtil.parse(new InputSource(new StringReader(str)), false, true, null, null);
doc = XMLUtil.parse(new InputSource(new StringReader(str)), false, true, true, null, null);
} catch (SAXException ex) {
Exceptions.printStackTrace(ex);
} catch (IOException ex) {
Expand All @@ -423,7 +423,7 @@ private void lazyAttachListener() {
try {
ByteArrayOutputStream wr = new ByteArrayOutputStream();
XMLUtil.write(doc, wr, "UTF-8"); //NOI18N
projectDirectory.setAttribute(AUX_CONFIG, wr.toString("UTF-8"));
projectDirectory.setAttribute(AUX_CONFIG, wr.toString(StandardCharsets.UTF_8));
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ public Map<String, String> loadRequiredProperties() {
if (entry != null) {
InputStream in = jf.getInputStream(entry);
try {
Document doc = XMLUtil.parse(new InputSource(in), false, false, XMLUtil.defaultErrorHandler(), null);
Document doc = XMLUtil.parse(new InputSource(in), false, false, true, XMLUtil.defaultErrorHandler(), null);
NodeList nl = doc.getElementsByTagName("requiredProperty");
for (int i = 0; i < nl.getLength(); i++) {
Element rP = (Element) nl.item(i);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ public Image getOpenedIcon(int type) {
}
LOG.log(Level.FINER, "parsing plugin.xml from {0}", jar);
try {
return XMLUtil.parse(new InputSource("jar:" + Utilities.toURI(jar) + "!/META-INF/maven/plugin.xml"), false, false, XMLUtil.defaultErrorHandler(), null);
return XMLUtil.parse(new InputSource("jar:" + Utilities.toURI(jar) + "!/META-INF/maven/plugin.xml"), false, false, true, XMLUtil.defaultErrorHandler(), null);
} catch (Exception x) {
LOG.log(Level.FINE, "could not parse " + jar, x.toString());
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,7 @@ private static boolean modifyBuildXml(Project proj) throws IOException {
}
Document xmlDoc = null;
try {
xmlDoc = XMLUtil.parse(new InputSource(buildXmlFO.toURL().toExternalForm()), false, true, null, null);
xmlDoc = XMLUtil.parse(new InputSource(buildXmlFO.toURL().toExternalForm()), false, true, true, null, null);
} catch (SAXException ex) {
Exceptions.printStackTrace(ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringReader;
import java.nio.file.NoSuchFileException;
import java.nio.file.Files;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.parsers.DocumentBuilder;
Expand All @@ -41,6 +42,7 @@
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.netbeans.modules.maven.api.FileUtilities;
import org.openide.xml.XMLUtil;

final class MavenUtilities {

Expand Down Expand Up @@ -70,23 +72,16 @@ private String readProperty(final String tag) {
if (!this.settings.isFile()) {
return null;
}
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder;
dBuilder = dbFactory.newDocumentBuilder();
Document settingsDoc = dBuilder.parse(this.settings);
NodeList elementsByTagName = settingsDoc.getElementsByTagName(tag);
if (elementsByTagName.getLength() >0) return elementsByTagName.item(0).getTextContent();
return null;
} catch (NoSuchFileException ex) {
LOG.log(Level.FINE, "Cannot find " + settings, ex);
return null;
} catch (IOException ex) {
LOG.log(Level.INFO, "Cannot read " + settings, ex);
return null;
} catch (ParserConfigurationException ex) {
LOG.log(Level.INFO, "Cannot read " + settings, ex);

try (InputStream is = Files.newInputStream(settings.toPath())) {
Document settingsDoc = XMLUtil.parse(new InputSource(is), false, false, true, null, null);
NodeList elementsByTagName = settingsDoc.getElementsByTagName(tag);
if (elementsByTagName.getLength() > 0) {
return elementsByTagName.item(0).getTextContent();
}
}
return null;
} catch (SAXException ex) {
} catch (IOException | SAXException ex) {
LOG.log(Level.INFO, "Cannot read " + settings, ex);
return null;
}
Expand Down
Loading
Loading