diff --git a/WHATSNEW b/WHATSNEW
index 685413ea5..fb4d2e514 100644
--- a/WHATSNEW
+++ b/WHATSNEW
@@ -42,7 +42,7 @@ Fixed bugs:
* now works on OS/400.
-* nested into s didn't work.
+* s nested into s didn't work.
Other changes:
--------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/XMLValidateTask.java b/src/main/org/apache/tools/ant/taskdefs/optional/XMLValidateTask.java
index 0f78f3e81..d02d208e9 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/XMLValidateTask.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/XMLValidateTask.java
@@ -345,7 +345,8 @@ public class XMLValidateTask extends Task {
log("Using SAX1 parser " + reader.getClass().getName(),
Project.MSG_VERBOSE);
} else {
- throw new BuildException(INIT_FAILED_MSG + readerClassName
+ throw new BuildException(INIT_FAILED_MSG
+ + reader.getClass().getName()
+ " implements nor SAX1 Parser nor SAX2 XMLReader.");
}
}
@@ -356,19 +357,12 @@ public class XMLValidateTask extends Task {
if (!(xmlReader instanceof ParserAdapter)) {
// turn validation on
if (!lenient) {
- boolean ok = setFeature("http://xml.org/sax/features/validation", true, true);
- if (!ok) {
- throw new BuildException(INIT_FAILED_MSG
- + readerClassName
- + " doesn't provide validation");
- }
+ setFeature("http://xml.org/sax/features/validation", true);
}
// set the feature from the attribute list
for (int i = 0; i < attributeList.size(); i++) {
Attribute feature = (Attribute) attributeList.elementAt(i);
- setFeature(feature.getName(),
- feature.getValue(),
- true);
+ setFeature(feature.getName(), feature.getValue());
}
}
@@ -381,30 +375,20 @@ public class XMLValidateTask extends Task {
* @param warn whether to war if the parser does not support the feature
*/
- private boolean setFeature(String feature, boolean value, boolean warn) {
+ private void setFeature(String feature, boolean value)
+ throws BuildException {
- boolean toReturn = false;
try {
xmlReader.setFeature(feature, value);
- toReturn = true;
} catch (SAXNotRecognizedException e) {
- if (warn) {
- log("Could not set feature '"
- + feature
- + "' because the '" +
- readerClassName + "' parser doesn't recognize it",
- Project.MSG_WARN);
- }
+ throw new BuildException("Parser " + xmlReader.getClass().getName()
+ + " doesn't recognize feature "
+ + feature, e, getLocation());
} catch (SAXNotSupportedException e) {
- if (warn) {
- log("Could not set feature '"
- + feature
- + "' because the '" +
- readerClassName + "' parser doesn't support it",
- Project.MSG_WARN);
- }
+ throw new BuildException("Parser " + xmlReader.getClass().getName()
+ + " doesn't support feature "
+ + feature, e, getLocation());
}
- return toReturn;
}
/**
diff --git a/src/testcases/org/apache/tools/ant/taskdefs/optional/XmlValidateTest.java b/src/testcases/org/apache/tools/ant/taskdefs/optional/XmlValidateTest.java
index 4e761d8fb..410e1d37a 100644
--- a/src/testcases/org/apache/tools/ant/taskdefs/optional/XmlValidateTest.java
+++ b/src/testcases/org/apache/tools/ant/taskdefs/optional/XmlValidateTest.java
@@ -56,6 +56,7 @@ package org.apache.tools.ant.taskdefs.optional;
import java.io.*;
import java.util.Properties;
+import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.BuildFileTest;
/**
@@ -130,16 +131,41 @@ public class XmlValidateTest extends BuildFileTest {
/**
* Test xml schema validation
*/
- public void testXmlSchemaGood() {
- executeTarget("testSchemaGood");
+ public void testXmlSchemaGood() throws BuildException {
+ try {
+ executeTarget("testSchemaGood");
+ } catch (BuildException e) {
+ if (e.getMessage()
+ .endsWith(" doesn't recognize feature http://apache.org/xml/features/validation/schema") ||
+ e.getMessage()
+ .endsWith(" doesn't support feature http://apache.org/xml/features/validation/schema")) {
+ System.err.println(" skipped, parser doesn't support schema");
+ } else {
+ throw e;
+ }
+ }
}
/**
* Test xml schema validation
*/
public void testXmlSchemaBad() {
- expectBuildExceptionContaining(
- "testSchemaBad",
- "Bad Schema Validation", "not a valid XML document");
-
+ try {
+ executeTarget("testSchemaBad");
+ fail("Should throw BuildException because 'Bad Schema Validation'");
+
+ expectBuildExceptionContaining("testSchemaBad",
+ "Bad Schema Validation",
+ "not a valid XML document");
+ } catch (BuildException e) {
+ if (e.getMessage()
+ .endsWith(" doesn't recognize feature http://apache.org/xml/features/validation/schema") ||
+ e.getMessage()
+ .endsWith(" doesn't support feature http://apache.org/xml/features/validation/schema")) {
+ System.err.println(" skipped, parser doesn't support schema");
+ } else {
+ assertTrue(e.getMessage()
+ .indexOf("not a valid XML document") > -1);
+ }
+ }
}
}