From 7fc0d42636ae70a69d8dc312090c5fe80ae32f0c Mon Sep 17 00:00:00 2001 From: Conor MacNeill Date: Sun, 21 Apr 2002 13:42:03 +0000 Subject: [PATCH] Improve XML parser issue reporting git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@272535 13f79535-47bb-0310-9956-ffa450edef68 --- src/main/org/apache/tools/ant/Main.java | 16 +------------- .../org/apache/tools/ant/ProjectHelper.java | 22 +++++++++++++------ .../tools/ant/helper/ProjectHelperImpl.java | 5 ++++- 3 files changed, 20 insertions(+), 23 deletions(-) diff --git a/src/main/org/apache/tools/ant/Main.java b/src/main/org/apache/tools/ant/Main.java index 6844383ad..ec03c769c 100644 --- a/src/main/org/apache/tools/ant/Main.java +++ b/src/main/org/apache/tools/ant/Main.java @@ -565,21 +565,7 @@ public class Main { project.setUserProperty("ant.file", buildFile.getAbsolutePath()); - // first use the ProjectHelper to create the project object - // from the given build file. - String noParserMessage = "No JAXP compliant XML parser found. " - + "Please visit http://xml.apache.org " - + "for a suitable parser"; - try { - Class.forName("javax.xml.parsers.SAXParserFactory"); - ProjectHelper.configureProject(project, buildFile); - } catch (NoClassDefFoundError ncdfe) { - throw new BuildException(noParserMessage, ncdfe); - } catch (ClassNotFoundException cnfe) { - throw new BuildException(noParserMessage, cnfe); - } catch (NullPointerException npe) { - throw new BuildException(noParserMessage, npe); - } + ProjectHelper.configureProject(project, buildFile); if (projectHelp) { printDescription(project); diff --git a/src/main/org/apache/tools/ant/ProjectHelper.java b/src/main/org/apache/tools/ant/ProjectHelper.java index ab1d81b7b..6fae21911 100644 --- a/src/main/org/apache/tools/ant/ProjectHelper.java +++ b/src/main/org/apache/tools/ant/ProjectHelper.java @@ -139,7 +139,7 @@ public class ProjectHelper { + "in a helper plugin " + this.getClass().getName()); } - + /** * Discovers a project helper instance. Uses the same patterns * as JAXP, commons-logging, etc: a system property, a JDK1.3 @@ -159,14 +159,15 @@ public class ProjectHelper { ProjectHelper helper = null; // First, try the system property + String helperClass = System.getProperty(HELPER_PROPERTY); try { - String helperClass = System.getProperty(HELPER_PROPERTY); if (helperClass != null) { helper = newHelper(helperClass); } } catch (SecurityException e) { - // It's ok, we'll try next option - ; + System.out.println("Unable to load ProjectHelper class \"" + + helperClass + " specified in system property " + + HELPER_PROPERTY); } // A JDK1.3 'service' ( like in JAXP ). That will plug a helper @@ -203,15 +204,22 @@ public class ProjectHelper { } } } catch (Exception ex) { - ; + System.out.println("Unable to load ProjectHelper " + + "from service \"" + SERVICE_ID); } } if (helper != null) { return helper; } else { - // Default - return new ProjectHelperImpl(); + try { + // Default + return new ProjectHelperImpl(); + } catch (Throwable e) { + String message = "Unable to load default ProjectHelper due to " + + e.getClass().getName() + ": " + e.getMessage(); + throw new BuildException(message, e); + } } } diff --git a/src/main/org/apache/tools/ant/helper/ProjectHelperImpl.java b/src/main/org/apache/tools/ant/helper/ProjectHelperImpl.java index 77e24c66e..e8eece490 100644 --- a/src/main/org/apache/tools/ant/helper/ProjectHelperImpl.java +++ b/src/main/org/apache/tools/ant/helper/ProjectHelperImpl.java @@ -71,7 +71,7 @@ import org.xml.sax.helpers.XMLReaderAdapter; import javax.xml.parsers.SAXParserFactory; import javax.xml.parsers.SAXParser; import javax.xml.parsers.ParserConfigurationException; - +import javax.xml.parsers.FactoryConfigurationError; import org.apache.tools.ant.ProjectHelper; import org.apache.tools.ant.UnknownElement; import org.apache.tools.ant.Project; @@ -165,6 +165,9 @@ public class ProjectHelperImpl extends ProjectHelper { parser.parse(inputSource); } catch (ParserConfigurationException exc) { throw new BuildException("Parser has not been configured correctly", exc); + } catch (FactoryConfigurationError e) { + throw new BuildException("XML parser has not been configured " + + "correctly: " + e.getMessage(), e); } catch (SAXParseException exc) { Location location = new Location(buildFile.toString(), exc.getLineNumber(),