stevel 2005/05/10 09:26:34
Modified: src/etc/testcases/taskdefs/optional schemavalidate.xml
src/main/org/apache/tools/ant/taskdefs/optional
XMLValidateTask.java
src/testcases/org/apache/tools/ant/taskdefs/optional
SchemaValidateTest.java
Log:
Patch XMLValidate to create a new parser every time, plus test case that
verifies it works.
Note that there is an extra change, the return code of doVerify() is now
boolean and not void. I have plans for an option to halt the build only if a
schema is valid (I'm using ant/gump) to validate XSD files, and want to test
that a schema correctly rejects invalid files. This is just a step on the way,
while I was in the method.
Revision Changes Path
1.4 +9 -0
ant/src/etc/testcases/taskdefs/optional/schemavalidate.xml
Index: schemavalidate.xml
===================================================================
RCS file:
/home/cvs/ant/src/etc/testcases/taskdefs/optional/schemavalidate.xml,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- schemavalidate.xml 22 Feb 2005 17:45:40 -0000 1.3
+++ schemavalidate.xml 10 May 2005 16:26:34 -0000 1.4
@@ -69,6 +69,15 @@
</schemavalidate>
</target>
+ <target name="testFileset">
+ <schemavalidate noNamespaceFile="${doc.xsd}"
+ >
+ <schema namespace="${namespace}" file="${doc-in-ns.xsd}" />
+ <fileset dir="xml"
+ includes="endpiece.xml, endpiece-ns-no-location.xml,
endpiece-no-schema.xml" />
+ </schemavalidate>
+ </target>
+
<target name="default" depends="testNoNamespace,testNSMapping" />
</project>
\ No newline at end of file
1.49 +8 -2
ant/src/main/org/apache/tools/ant/taskdefs/optional/XMLValidateTask.java
Index: XMLValidateTask.java
===================================================================
RCS file:
/home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/optional/XMLValidateTask.java,v
retrieving revision 1.48
retrieving revision 1.49
diff -u -r1.48 -r1.49
--- XMLValidateTask.java 23 Feb 2005 13:04:16 -0000 1.48
+++ XMLValidateTask.java 10 May 2005 16:26:34 -0000 1.49
@@ -285,7 +285,7 @@
"Specify at least one source - " + "a file or a fileset.");
}
- initValidator();
+
if (file != null) {
if (file.exists() && file.canRead() && file.isFile()) {
@@ -518,7 +518,10 @@
/**
* parse the file
*/
- protected void doValidate(File afile) {
+ protected boolean doValidate(File afile) {
+ //for every file, we have a new instance of the validator
+ initValidator();
+
try {
log("Validating " + afile.getName() + "... ",
Project.MSG_VERBOSE);
errorHandler.init(afile);
@@ -526,6 +529,7 @@
String uri = FILE_UTILS.toURI(afile.getAbsolutePath());
is.setSystemId(uri);
xmlReader.parse(is);
+ return true;
} catch (SAXException ex) {
log("Caught when validating: " + ex.toString(),
Project.MSG_DEBUG);
if (failOnError) {
@@ -548,6 +552,8 @@
log(afile + " is not a valid XML document", Project.MSG_ERR);
}
}
+ //if we got here. it was as a result of a caught and logged
exception.
+ return false;
}
/**
1.4 +3 -0
ant/src/testcases/org/apache/tools/ant/taskdefs/optional/SchemaValidateTest.java
Index: SchemaValidateTest.java
===================================================================
RCS file:
/home/cvs/ant/src/testcases/org/apache/tools/ant/taskdefs/optional/SchemaValidateTest.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- SchemaValidateTest.java 22 Feb 2005 17:45:40 -0000 1.3
+++ SchemaValidateTest.java 10 May 2005 16:26:34 -0000 1.4
@@ -92,4 +92,7 @@
executeTarget("testEqualsSchemasOK");
}
+ public void testFileset() throws Exception {
+ executeTarget("testFileset");
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]