Browse Source

Defer expansion of reference until the catalog gets used.

PR: 20965


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@275312 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 21 years ago
parent
commit
6c8567b428
4 changed files with 43 additions and 17 deletions
  1. +3
    -0
      WHATSNEW
  2. +10
    -0
      src/etc/testcases/taskdefs/optional/xmlvalidate.xml
  3. +22
    -16
      src/main/org/apache/tools/ant/types/XMLCatalog.java
  4. +8
    -1
      src/testcases/org/apache/tools/ant/taskdefs/optional/XmlValidateTest.java

+ 3
- 0
WHATSNEW View File

@@ -248,6 +248,9 @@ Fixed bugs:
* <splash> could fail on JVMs that use null to indicate the system classloader. * <splash> could fail on JVMs that use null to indicate the system classloader.
Bugzilla Report 23320. Bugzilla Report 23320.


* <xmlcatalog>s only worked when defined inside of tasks. Bugzilla
Report 20965.

Other changes: Other changes:
-------------- --------------
* All tasks can be used outside of <target>s. Note that some tasks * All tasks can be used outside of <target>s. Note that some tasks


+ 10
- 0
src/etc/testcases/taskdefs/optional/xmlvalidate.xml View File

@@ -25,6 +25,16 @@
</xmlvalidate> </xmlvalidate>
</target> </target>


<target name="xmlcatalogViaRefid">
<xmlcatalog classpath="xml" id="cat">
<dtd publicID="-//stevo//DTD doc 1.0//EN" location="doc.dtd"/>
</xmlcatalog>
<xmlvalidate warn="false">
<xmlcatalog refid="cat"/>
<fileset dir="xml" includes="**/about.xml"/>
</xmlvalidate>
</target>

<target name="xmlcatalognested"> <target name="xmlcatalognested">
<xmlvalidate warn="false"> <xmlvalidate warn="false">
<fileset dir="xml" includes="**/about.xml"/> <fileset dir="xml" includes="**/about.xml"/>


+ 22
- 16
src/main/org/apache/tools/ant/types/XMLCatalog.java View File

@@ -208,7 +208,7 @@ public class XMLCatalog extends DataType
* @return the elements of the catalog - ResourceLocation objects * @return the elements of the catalog - ResourceLocation objects
*/ */
private Vector getElements() { private Vector getElements() {
return elements;
return getRef().elements;
} }


/** /**
@@ -217,7 +217,7 @@ public class XMLCatalog extends DataType
* @return the classpath * @return the classpath
*/ */
private Path getClasspath() { private Path getClasspath() {
return classpath;
return getRef().classpath;
} }


/** /**
@@ -335,7 +335,7 @@ public class XMLCatalog extends DataType
* @return the catalog path * @return the catalog path
*/ */
public Path getCatalogPath() { public Path getCatalogPath() {
return this.catalogPath;
return getRef().catalogPath;
} }




@@ -421,17 +421,6 @@ public class XMLCatalog extends DataType
if (!elements.isEmpty()) { if (!elements.isEmpty()) {
throw tooManyAttributes(); throw tooManyAttributes();
} }
// change this to get the objects from the other reference
Object o = r.getReferencedObject(getProject());
// we only support references to other XMLCatalogs
if (o instanceof XMLCatalog) {
// set all elements from referenced catalog to this one
XMLCatalog catalog = (XMLCatalog) o;
setElements(catalog.getElements());
} else {
String msg = r.getRefId() + " does not refer to an XMLCatalog";
throw new BuildException(msg);
}
super.setRefid(r); super.setRefid(r);
} }


@@ -443,6 +432,10 @@ public class XMLCatalog extends DataType
public InputSource resolveEntity(String publicId, String systemId) public InputSource resolveEntity(String publicId, String systemId)
throws SAXException, IOException { throws SAXException, IOException {


if (isReference()) {
return getRef().resolveEntity(publicId, systemId);
}

if (!isChecked()) { if (!isChecked()) {
// make sure we don't have a circular reference here // make sure we don't have a circular reference here
Stack stk = new Stack(); Stack stk = new Stack();
@@ -472,6 +465,10 @@ public class XMLCatalog extends DataType
public Source resolve(String href, String base) public Source resolve(String href, String base)
throws TransformerException { throws TransformerException {


if (isReference()) {
return getRef().resolve(href, base);
}

if (!isChecked()) { if (!isChecked()) {
// make sure we don't have a circular reference here // make sure we don't have a circular reference here
Stack stk = new Stack(); Stack stk = new Stack();
@@ -515,6 +512,16 @@ public class XMLCatalog extends DataType
return source; return source;
} }


/**
* @since Ant 1.6
*/
private XMLCatalog getRef() {
if (!isReference()) {
return this;
}
return (XMLCatalog) getCheckedRef(XMLCatalog.class, "xmlcatalog");
}

/** /**
* The instance of the CatalogResolver strategy to use. * The instance of the CatalogResolver strategy to use.
*/ */
@@ -576,9 +583,8 @@ public class XMLCatalog extends DataType
&& getCatalogPath().list().length != 0) { && getCatalogPath().list().length != 0) {
log("Warning: catalogpath listing external catalogs" log("Warning: catalogpath listing external catalogs"
+ " will be ignored", Project.MSG_WARN); + " will be ignored", Project.MSG_WARN);
log("Failed to load Apache resolver: "
+ ex, Project.MSG_DEBUG);
} }
log("Failed to load Apache resolver: " + ex, Project.MSG_DEBUG);
} }
} }
return catalogResolver; return catalogResolver;


+ 8
- 1
src/testcases/org/apache/tools/ant/taskdefs/optional/XmlValidateTest.java View File

@@ -1,7 +1,7 @@
/* /*
* The Apache Software License, Version 1.1 * The Apache Software License, Version 1.1
* *
* Copyright (c) 2002 The Apache Software Foundation. All rights
* Copyright (c) 2002-2003 The Apache Software Foundation. All rights
* reserved. * reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -125,6 +125,13 @@ public class XmlValidateTest extends BuildFileTest {
executeTarget("xmlcatalog"); executeTarget("xmlcatalog");
} }


/**
*
*/
public void testXmlCatalogViaRefid() {
executeTarget("xmlcatalogViaRefid");
}

/** /**
* Test that the nested dtd element is used when resolver.jar is not * Test that the nested dtd element is used when resolver.jar is not
* present. This test should pass either way. * present. This test should pass either way.


Loading…
Cancel
Save