diff --git a/WHATSNEW b/WHATSNEW index 89df3984f..e5a220f4c 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -248,6 +248,9 @@ Fixed bugs: * could fail on JVMs that use null to indicate the system classloader. Bugzilla Report 23320. +* s only worked when defined inside of tasks. Bugzilla + Report 20965. + Other changes: -------------- * All tasks can be used outside of s. Note that some tasks diff --git a/src/etc/testcases/taskdefs/optional/xmlvalidate.xml b/src/etc/testcases/taskdefs/optional/xmlvalidate.xml index 76c26fcce..7dcd5af19 100644 --- a/src/etc/testcases/taskdefs/optional/xmlvalidate.xml +++ b/src/etc/testcases/taskdefs/optional/xmlvalidate.xml @@ -25,6 +25,16 @@ + + + + + + + + + + diff --git a/src/main/org/apache/tools/ant/types/XMLCatalog.java b/src/main/org/apache/tools/ant/types/XMLCatalog.java index ac4002432..39cb4ddf5 100644 --- a/src/main/org/apache/tools/ant/types/XMLCatalog.java +++ b/src/main/org/apache/tools/ant/types/XMLCatalog.java @@ -208,7 +208,7 @@ public class XMLCatalog extends DataType * @return the elements of the catalog - ResourceLocation objects */ private Vector getElements() { - return elements; + return getRef().elements; } /** @@ -217,7 +217,7 @@ public class XMLCatalog extends DataType * @return the classpath */ private Path getClasspath() { - return classpath; + return getRef().classpath; } /** @@ -335,7 +335,7 @@ public class XMLCatalog extends DataType * @return the catalog path */ public Path getCatalogPath() { - return this.catalogPath; + return getRef().catalogPath; } @@ -421,17 +421,6 @@ public class XMLCatalog extends DataType if (!elements.isEmpty()) { 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); } @@ -443,6 +432,10 @@ public class XMLCatalog extends DataType public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { + if (isReference()) { + return getRef().resolveEntity(publicId, systemId); + } + if (!isChecked()) { // make sure we don't have a circular reference here Stack stk = new Stack(); @@ -472,6 +465,10 @@ public class XMLCatalog extends DataType public Source resolve(String href, String base) throws TransformerException { + if (isReference()) { + return getRef().resolve(href, base); + } + if (!isChecked()) { // make sure we don't have a circular reference here Stack stk = new Stack(); @@ -515,6 +512,16 @@ public class XMLCatalog extends DataType 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. */ @@ -576,9 +583,8 @@ public class XMLCatalog extends DataType && getCatalogPath().list().length != 0) { log("Warning: catalogpath listing external catalogs" + " 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; 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 80799ce2a..ce287e1e8 100644 --- a/src/testcases/org/apache/tools/ant/taskdefs/optional/XmlValidateTest.java +++ b/src/testcases/org/apache/tools/ant/taskdefs/optional/XmlValidateTest.java @@ -1,7 +1,7 @@ /* * 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. * * Redistribution and use in source and binary forms, with or without @@ -125,6 +125,13 @@ public class XmlValidateTest extends BuildFileTest { executeTarget("xmlcatalog"); } + /** + * + */ + public void testXmlCatalogViaRefid() { + executeTarget("xmlcatalogViaRefid"); + } + /** * Test that the nested dtd element is used when resolver.jar is not * present. This test should pass either way.