diff options
author | sarsenau | 2002-06-11 18:17:19 +0000 |
---|---|---|
committer | sarsenau | 2002-06-11 18:17:19 +0000 |
commit | 3423707b029e2eead0129523d62b61b18ff08eac (patch) | |
tree | b028ad4db83e718f39da279db1fc3c2ee62cbe92 /org.eclipse.ui.externaltools | |
parent | 92d5ea18da4779969cab204ef1bb6828f118cfd1 (diff) | |
download | eclipse.platform.debug-3423707b029e2eead0129523d62b61b18ff08eac.tar.gz eclipse.platform.debug-3423707b029e2eead0129523d62b61b18ff08eac.tar.xz eclipse.platform.debug-3423707b029e2eead0129523d62b61b18ff08eac.zip |
Fix PR 18692 - [External Tools] Including XML files in ANT does not work anymore in F2
Diffstat (limited to 'org.eclipse.ui.externaltools')
-rw-r--r-- | org.eclipse.ui.externaltools/External Tools/org/eclipse/ui/externaltools/internal/core/AntUtil.java | 57 |
1 files changed, 46 insertions, 11 deletions
diff --git a/org.eclipse.ui.externaltools/External Tools/org/eclipse/ui/externaltools/internal/core/AntUtil.java b/org.eclipse.ui.externaltools/External Tools/org/eclipse/ui/externaltools/internal/core/AntUtil.java index 445e069a8..e214b9cd2 100644 --- a/org.eclipse.ui.externaltools/External Tools/org/eclipse/ui/externaltools/internal/core/AntUtil.java +++ b/org.eclipse.ui.externaltools/External Tools/org/eclipse/ui/externaltools/internal/core/AntUtil.java @@ -13,16 +13,11 @@ import java.io.*; import javax.xml.parsers.*; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.*; import org.eclipse.ui.IMemento; import org.eclipse.ui.XMLMemento; import org.w3c.dom.*; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; +import org.xml.sax.*; /** * General utility class dealing with Ant files @@ -59,7 +54,8 @@ public final class AntUtil { private static IMemento getMemento(IPath path) throws CoreException { try { Reader reader = new FileReader(path.toFile()); - return createReadRoot(reader); + IPath basePath = path.removeLastSegments(1).addTrailingSeparator(); + return createReadRoot(reader, basePath.toOSString()); } catch (FileNotFoundException e) { processException(e, "AntUtil.antFileNotFound"); //$NON-NLS-1$ } @@ -74,14 +70,21 @@ public final class AntUtil { * and returns a root memento for reading the document. * * @param reader the reader used to create the memento's document + * @param baseDir the directory to use to resolve relative file names + * in XML document. This directory must exist and include a + * trailing separator. The directory format, including the separators, + * must be valid for the platform. * @return the root memento for reading the document - * @throws CoreException if IO problems, or invalid format. + * @throws CoreException if IO problems, or invalid XML format. */ - private static XMLMemento createReadRoot(Reader reader) throws CoreException { + private static XMLMemento createReadRoot(Reader reader, String baseDir) throws CoreException { try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder parser = factory.newDocumentBuilder(); - Document document = parser.parse(new InputSource(reader)); + parser.setEntityResolver(new AntEntityResolver(baseDir)); + InputSource source = new InputSource(reader); + source.setSystemId(baseDir); + Document document = parser.parse(source); NodeList list = document.getChildNodes(); for(int i=0; i < list.getLength(); i++) { Node node = list.item(i); @@ -147,4 +150,36 @@ public final class AntUtil { IStatus status = new Status(IStatus.ERROR, ExternalToolsPlugin.PLUGIN_ID, 0, problem, e); throw new CoreException(status); } + + /** + * EntityResolver used when parsing Ant files to find targets. + */ + private static class AntEntityResolver implements EntityResolver { + private String baseDir; + + public AntEntityResolver(String baseDir) { + this.baseDir = baseDir; + } + + public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { + if (systemId == null) + return null; + + // remove "file:" prefix + if (systemId.startsWith("file:")) { //$NON-NLS-1$ + // 5 is the length of the string "file:" + systemId = systemId.substring(5); + File file = new File(systemId); + // If the file is not absolute, the systemId is relative + // to the baseDir. + if (!file.isAbsolute()) + file = new File(baseDir, systemId); + Reader reader = new FileReader(file); + return new InputSource(reader); + } + + // use default behaviour if systemId does not have "file:" prefix + return null; + } + } } |