bodewig 2002/09/30 02:40:39
Modified: . WHATSNEW
src/main/org/apache/tools/ant/taskdefs/optional
XMLValidateTask.java
src/testcases/org/apache/tools/ant/taskdefs/optional
XmlValidateTest.java
Log:
Throw BuildException in <xmlvalidate> if a requested feature is not
supported.
Make <xmlvalidate>'s unit tests handle parsers without knowledge about
XML Schema gracefully, passes with Crimson and Xerces on my box now.
Revision Changes Path
1.295 +1 -1 jakarta-ant/WHATSNEW
Index: WHATSNEW
===================================================================
RCS file: /home/cvs/jakarta-ant/WHATSNEW,v
retrieving revision 1.294
retrieving revision 1.295
diff -u -r1.294 -r1.295
--- WHATSNEW 27 Sep 2002 09:30:37 -0000 1.294
+++ WHATSNEW 30 Sep 2002 09:40:39 -0000 1.295
@@ -42,7 +42,7 @@
* <property environment=... /> now works on OS/400.
-* <filterset> nested into <filterset>s didn't work.
+* <filterset>s nested into <filterset>s didn't work.
Other changes:
--------------
1.27 +12 -28
jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/XMLValidateTask.java
Index: XMLValidateTask.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/XMLValidateTask.java,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -r1.26 -r1.27
--- XMLValidateTask.java 23 Sep 2002 14:59:42 -0000 1.26
+++ XMLValidateTask.java 30 Sep 2002 09:40:39 -0000 1.27
@@ -345,7 +345,8 @@
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 @@
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 @@
* @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;
}
/**
1.5 +32 -6
jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs/optional/XmlValidateTest.java
Index: XmlValidateTest.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs/optional/XmlValidateTest.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- XmlValidateTest.java 23 Sep 2002 14:59:42 -0000 1.4
+++ XmlValidateTest.java 30 Sep 2002 09:40:39 -0000 1.5
@@ -56,6 +56,7 @@
import java.io.*;
import java.util.Properties;
+import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.BuildFileTest;
/**
@@ -130,16 +131,41 @@
/**
* 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);
+ }
+ }
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>