Browse Source

Missing pieces from Craeg's patch.

Fix small backwards incompatibility introduced by last commit.


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@273515 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 22 years ago
parent
commit
1967c958ff
7 changed files with 40 additions and 96 deletions
  1. +0
    -1
      build.xml
  2. +3
    -3
      src/main/org/apache/tools/ant/taskdefs/optional/XMLValidateTask.java
  3. +0
    -72
      src/main/org/apache/tools/ant/types/EntityLocation.java
  4. +1
    -0
      src/main/org/apache/tools/ant/types/ResourceLocation.java
  5. +1
    -0
      src/main/org/apache/tools/ant/types/resolver/ApacheCatalog.java
  6. +1
    -0
      src/main/org/apache/tools/ant/types/resolver/ApacheCatalogResolver.java
  7. +34
    -20
      src/testcases/org/apache/tools/ant/types/XMLCatalogTest.java

+ 0
- 1
build.xml View File

@@ -292,7 +292,6 @@
<exclude name="**/GetTest.java" if="offline"/> <exclude name="**/GetTest.java" if="offline"/>
</patternset> </patternset>
<patternset id="teststhatfail"> <patternset id="teststhatfail">
<exclude name="${ant.package}/types/XMLCatalogTest.java"/>
</patternset> </patternset>


<!-- <!--


+ 3
- 3
src/main/org/apache/tools/ant/taskdefs/optional/XMLValidateTask.java View File

@@ -65,7 +65,7 @@ import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DirectoryScanner; import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.Project; import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task; import org.apache.tools.ant.Task;
import org.apache.tools.ant.types.ResourceLocation;
import org.apache.tools.ant.types.DTDLocation;
import org.apache.tools.ant.types.FileSet; import org.apache.tools.ant.types.FileSet;
import org.apache.tools.ant.types.Path; import org.apache.tools.ant.types.Path;
import org.apache.tools.ant.types.Reference; import org.apache.tools.ant.types.Reference;
@@ -248,8 +248,8 @@ public class XMLValidateTask extends Task {
* This stores the location of a DTD. The DTD is identified * This stores the location of a DTD. The DTD is identified
* by its public Id. * by its public Id.
*/ */
public ResourceLocation createDTD() {
ResourceLocation dtdLocation = new ResourceLocation();
public DTDLocation createDTD() {
DTDLocation dtdLocation = new DTDLocation();
xmlCatalog.addDTD(dtdLocation); xmlCatalog.addDTD(dtdLocation);
return dtdLocation; return dtdLocation;
} }


+ 0
- 72
src/main/org/apache/tools/ant/types/EntityLocation.java View File

@@ -1,72 +0,0 @@
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Ant", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.tools.ant.types;

/**
* Helper class to handle the Entity nested element. Instances of
* this class correspond to the <code>URI</code> catalog entry type of
* the <a
* href="http://oasis-open.org/committees/entity/spec-2001-08-06.html">
* OASIS "Open Catalog" standard</a>.</p>
*
* <p>Possible Future Enhancement: Bring the Ant element name into
* conformance with the OASIS standard.</p>
*
* @see org.apache.xml.resolver.Catalog
* @author Conor MacNeill
* @author dIon Gillard
* @author <a href="mailto:cstrong@arielpartners.com">Craeg Strong</a>
*/
public class EntityLocation extends ResourceLocation {
}

+ 1
- 0
src/main/org/apache/tools/ant/types/ResourceLocation.java View File

@@ -75,6 +75,7 @@ import java.net.URL;
* @author dIon Gillard * @author dIon Gillard
* @author <a href="mailto:cstrong@arielpartners.com">Craeg Strong</a> * @author <a href="mailto:cstrong@arielpartners.com">Craeg Strong</a>
* @version $Id$ * @version $Id$
* @since Ant 1.6
*/ */


import java.net.URL; import java.net.URL;


+ 1
- 0
src/main/org/apache/tools/ant/types/resolver/ApacheCatalog.java View File

@@ -75,6 +75,7 @@ import org.apache.xml.resolver.helpers.PublicId;
* @see org.apache.tools.ant.types.XMLCatalog.CatalogResolver * @see org.apache.tools.ant.types.XMLCatalog.CatalogResolver
* @author <a href="mailto:cstrong@arielpartners.com">Craeg Strong</a> * @author <a href="mailto:cstrong@arielpartners.com">Craeg Strong</a>
* @version $Id$ * @version $Id$
* @since Ant 1.6
*/ */
public class ApacheCatalog extends Catalog { public class ApacheCatalog extends Catalog {




+ 1
- 0
src/main/org/apache/tools/ant/types/resolver/ApacheCatalogResolver.java View File

@@ -96,6 +96,7 @@ import org.apache.xml.resolver.tools.CatalogResolver;
* @see org.apache.xml.resolver.CatalogManager * @see org.apache.xml.resolver.CatalogManager
* @author <a href="mailto:cstrong@arielpartners.com">Craeg Strong</a> * @author <a href="mailto:cstrong@arielpartners.com">Craeg Strong</a>
* @version $Id$ * @version $Id$
* @since Ant 1.6
*/ */


public class ApacheCatalogResolver extends CatalogResolver { public class ApacheCatalogResolver extends CatalogResolver {


+ 34
- 20
src/testcases/org/apache/tools/ant/types/XMLCatalogTest.java View File

@@ -57,18 +57,20 @@ package org.apache.tools.ant.types;
import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DefaultLogger; import org.apache.tools.ant.DefaultLogger;
import org.apache.tools.ant.Project; import org.apache.tools.ant.Project;
import org.apache.tools.ant.util.FileUtils;
import org.apache.tools.ant.util.JAXPUtils;


import junit.framework.TestCase; import junit.framework.TestCase;


import java.io.File; import java.io.File;


import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL;


import org.xml.sax.InputSource; import org.xml.sax.InputSource;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;


import javax.xml.transform.Source; import javax.xml.transform.Source;
import javax.xml.transform.sax.SAXSource;
import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerException;


/** /**
@@ -81,7 +83,6 @@ public class XMLCatalogTest extends TestCase {


private Project project; private Project project;
private XMLCatalog catalog; private XMLCatalog catalog;
private FileUtils fileUtils = FileUtils.newFileUtils();


private XMLCatalog newCatalog() { private XMLCatalog newCatalog() {
XMLCatalog cat = new XMLCatalog(); XMLCatalog cat = new XMLCatalog();
@@ -90,7 +91,7 @@ public class XMLCatalogTest extends TestCase {
} }


private String toURLString(File file) throws MalformedURLException { private String toURLString(File file) throws MalformedURLException {
return fileUtils.getFileURL(file).toString();
return JAXPUtils.getSystemId(file);
} }


public XMLCatalogTest(String name) { public XMLCatalogTest(String name) {
@@ -129,7 +130,16 @@ public class XMLCatalogTest extends TestCase {


try { try {
Source result = catalog.resolve("i/dont/exist.dtd", null); Source result = catalog.resolve("i/dont/exist.dtd", null);
assertNull("Empty catalog should return null", result);
String expected = toURLString(new File(project.getBaseDir() +
"/i/dont/exist.dtd"));
//
// These shenanigans are necessary b/c Norm Walsh's resolver
// has a different idea of how file URLs are created on windoze
// ie file://c:/foo instead of file:///c:/foo
//
String resultStr = new URL(((SAXSource)result).getInputSource().getSystemId()).getFile();
assertTrue("Empty catalog should return input",
expected.endsWith(resultStr));
} catch (Exception e) { } catch (Exception e) {
fail("resolve() failed!" + e.toString()); fail("resolve() failed!" + e.toString());
} }
@@ -137,7 +147,7 @@ public class XMLCatalogTest extends TestCase {


public void testNonExistentEntry() { public void testNonExistentEntry() {


DTDLocation dtd = new DTDLocation();
ResourceLocation dtd = new ResourceLocation();
dtd.setPublicId("PUBLIC ID ONE"); dtd.setPublicId("PUBLIC ID ONE");
dtd.setLocation("i/dont/exist.dtd"); dtd.setLocation("i/dont/exist.dtd");


@@ -151,7 +161,11 @@ public class XMLCatalogTest extends TestCase {


try { try {
Source result = catalog.resolve("i/dont/exist.dtd", null); Source result = catalog.resolve("i/dont/exist.dtd", null);
assertNull("Nonexistent Catalog entry should not be returned", result);
String expected = toURLString(new File(project.getBaseDir().toURL() +
"/i/dont/exist.dtd"));
String resultStr = new URL(((SAXSource)result).getInputSource().getSystemId()).getFile();
assertTrue("Nonexistent Catalog entry return input",
expected.endsWith(resultStr));
} catch (Exception e) { } catch (Exception e) {
fail("resolve() failed!" + e.toString()); fail("resolve() failed!" + e.toString());
} }
@@ -166,7 +180,7 @@ public class XMLCatalogTest extends TestCase {
be.getMessage()); be.getMessage());
} }


DTDLocation dtd = new DTDLocation();
ResourceLocation dtd = new ResourceLocation();
dtd.setPublicId("PUBLIC ID ONE"); dtd.setPublicId("PUBLIC ID ONE");
dtd.setLocation("i/dont/exist.dtd"); dtd.setLocation("i/dont/exist.dtd");
catalog.addDTD(dtd); catalog.addDTD(dtd);
@@ -235,7 +249,7 @@ public class XMLCatalogTest extends TestCase {


public void testSimpleEntry() { public void testSimpleEntry() {


DTDLocation dtd = new DTDLocation();
ResourceLocation dtd = new ResourceLocation();
dtd.setPublicId("-//stevo//DTD doc 1.0//EN"); dtd.setPublicId("-//stevo//DTD doc 1.0//EN");
String sysid = "src/etc/testcases/taskdefs/optional/xml/doc.dtd"; String sysid = "src/etc/testcases/taskdefs/optional/xml/doc.dtd";
dtd.setLocation(sysid); dtd.setLocation(sysid);
@@ -259,7 +273,7 @@ public class XMLCatalogTest extends TestCase {
String sysid = "src/etc/testcases/taskdefs/optional/xml/doc.dtd"; String sysid = "src/etc/testcases/taskdefs/optional/xml/doc.dtd";


// catalog2 --> catalog1 --> catalog // catalog2 --> catalog1 --> catalog
DTDLocation dtd = new DTDLocation();
ResourceLocation dtd = new ResourceLocation();
dtd.setPublicId(publicId); dtd.setPublicId(publicId);
dtd.setLocation(sysid); dtd.setLocation(sysid);
catalog.addDTD(dtd); catalog.addDTD(dtd);
@@ -268,7 +282,7 @@ public class XMLCatalogTest extends TestCase {
String uri = "http://foo.com/bar/blah.xml"; String uri = "http://foo.com/bar/blah.xml";
String uriLoc = "src/etc/testcases/taskdefs/optional/xml/about.xml"; String uriLoc = "src/etc/testcases/taskdefs/optional/xml/about.xml";


DTDLocation entity = new DTDLocation();
ResourceLocation entity = new ResourceLocation();
entity.setPublicId(uri); entity.setPublicId(uri);
entity.setLocation(uriLoc); entity.setLocation(uriLoc);
catalog.addEntity(entity); catalog.addEntity(entity);
@@ -310,7 +324,7 @@ public class XMLCatalogTest extends TestCase {
String publicId = "-//stevo//DTD doc 1.0//EN"; String publicId = "-//stevo//DTD doc 1.0//EN";
String dtdLoc = "src/etc/testcases/taskdefs/optional/xml/doc.dtd"; String dtdLoc = "src/etc/testcases/taskdefs/optional/xml/doc.dtd";


DTDLocation dtd = new DTDLocation();
ResourceLocation dtd = new ResourceLocation();
dtd.setPublicId(publicId); dtd.setPublicId(publicId);
dtd.setLocation(dtdLoc); dtd.setLocation(dtdLoc);
catalog.addDTD(dtd); catalog.addDTD(dtd);
@@ -319,7 +333,7 @@ public class XMLCatalogTest extends TestCase {
String uri = "http://foo.com/bar/blah.xml"; String uri = "http://foo.com/bar/blah.xml";
String uriLoc = "src/etc/testcases/taskdefs/optional/xml/about.xml"; String uriLoc = "src/etc/testcases/taskdefs/optional/xml/about.xml";


DTDLocation entity = new DTDLocation();
ResourceLocation entity = new ResourceLocation();
entity.setPublicId(uri); entity.setPublicId(uri);
entity.setLocation(uriLoc); entity.setLocation(uriLoc);
catalog.addEntity(entity); catalog.addEntity(entity);
@@ -355,12 +369,12 @@ public class XMLCatalogTest extends TestCase {
String uriLoc = "etc/testcases/taskdefs/optional/xml/about.xml"; String uriLoc = "etc/testcases/taskdefs/optional/xml/about.xml";
String base = null; String base = null;
try { try {
base = toURLString(project.getBaseDir()) + "src/";
base = toURLString(project.getBaseDir()) + "/src/";
} catch (MalformedURLException ex) { } catch (MalformedURLException ex) {
fail (ex.toString()); fail (ex.toString());
} }


DTDLocation entity = new DTDLocation();
ResourceLocation entity = new ResourceLocation();
entity.setPublicId(uri); entity.setPublicId(uri);
entity.setLocation(uriLoc); entity.setLocation(uriLoc);
catalog.addEntity(entity); catalog.addEntity(entity);
@@ -383,7 +397,7 @@ public class XMLCatalogTest extends TestCase {
String dtdLoc = "testcases/taskdefs/optional/xml/doc.dtd"; String dtdLoc = "testcases/taskdefs/optional/xml/doc.dtd";
String path1 = project.getBaseDir().toString() + "/src/etc"; String path1 = project.getBaseDir().toString() + "/src/etc";


DTDLocation dtd = new DTDLocation();
ResourceLocation dtd = new ResourceLocation();
dtd.setPublicId(publicId); dtd.setPublicId(publicId);
dtd.setLocation(dtdLoc); dtd.setLocation(dtdLoc);
catalog.addDTD(dtd); catalog.addDTD(dtd);
@@ -393,7 +407,7 @@ public class XMLCatalogTest extends TestCase {
String uriLoc = "etc/testcases/taskdefs/optional/xml/about.xml"; String uriLoc = "etc/testcases/taskdefs/optional/xml/about.xml";
String path2 = project.getBaseDir().toString() + "/src"; String path2 = project.getBaseDir().toString() + "/src";


DTDLocation entity = new DTDLocation();
ResourceLocation entity = new ResourceLocation();
entity.setPublicId(uri); entity.setPublicId(uri);
entity.setLocation(uriLoc); entity.setLocation(uriLoc);
catalog.addEntity(entity); catalog.addEntity(entity);
@@ -407,8 +421,8 @@ public class XMLCatalogTest extends TestCase {
InputSource result = catalog.resolveEntity(publicId, InputSource result = catalog.resolveEntity(publicId,
"nap:chemical+brothers"); "nap:chemical+brothers");
assertNotNull(result); assertNotNull(result);
assertEquals(toURLString(dtdFile),
result.getSystemId());
String resultStr = new URL(result.getSystemId()).getFile();
assertTrue(toURLString(dtdFile).endsWith(resultStr));
} catch (Exception e) { } catch (Exception e) {
fail("resolveEntity() failed!" + e.toString()); fail("resolveEntity() failed!" + e.toString());
} }
@@ -416,8 +430,8 @@ public class XMLCatalogTest extends TestCase {
try { try {
Source result = catalog.resolve(uri, null); Source result = catalog.resolve(uri, null);
assertNotNull(result); assertNotNull(result);
assertEquals(toURLString(xmlFile),
result.getSystemId());
String resultStr = new URL(result.getSystemId()).getFile();
assertTrue(toURLString(xmlFile).endsWith(resultStr));
} catch (Exception e) { } catch (Exception e) {
fail("resolve() failed!" + e.toString()); fail("resolve() failed!" + e.toString());
} }


Loading…
Cancel
Save