git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@817702 13f79535-47bb-0310-9956-ffa450edef68master
@@ -513,6 +513,11 @@ Other changes: | |||||
are instances or subclasses of FileResource. | are instances or subclasses of FileResource. | ||||
Bugzilla Report 43348 | Bugzilla Report 43348 | ||||
* There is now a URLProvider interface for resources that act as a | |||||
source of URLs. This should be used by tasks that require resources | |||||
to provide URLs, rather than require that all resources are | |||||
instances or subclasses of URLResource. | |||||
* Fixcrlf now gives better error messages on bad directory attributes. | * Fixcrlf now gives better error messages on bad directory attributes. | ||||
Bugzilla Report 43936 | Bugzilla Report 43936 | ||||
@@ -54,7 +54,7 @@ import org.apache.tools.ant.types.XMLCatalog; | |||||
import org.apache.tools.ant.types.Resource; | import org.apache.tools.ant.types.Resource; | ||||
import org.apache.tools.ant.types.resources.FileProvider; | import org.apache.tools.ant.types.resources.FileProvider; | ||||
import org.apache.tools.ant.types.resources.FileResource; | import org.apache.tools.ant.types.resources.FileResource; | ||||
import org.apache.tools.ant.types.resources.URLResource; | |||||
import org.apache.tools.ant.types.resources.URLProvider; | |||||
import org.apache.tools.ant.util.FileUtils; | import org.apache.tools.ant.util.FileUtils; | ||||
import org.apache.tools.ant.util.JAXPUtils; | import org.apache.tools.ant.util.JAXPUtils; | ||||
import org.xml.sax.EntityResolver; | import org.xml.sax.EntityResolver; | ||||
@@ -266,13 +266,13 @@ public class TraXLiaison implements XSLTLiaison3, ErrorListener, XSLTLoggerAware | |||||
} | } | ||||
private String resourceToURI(Resource resource) { | private String resourceToURI(Resource resource) { | ||||
// TODO turn URLResource into Provider | |||||
FileProvider fp = (FileProvider) resource.as(FileProvider.class); | FileProvider fp = (FileProvider) resource.as(FileProvider.class); | ||||
if (fp != null) { | if (fp != null) { | ||||
return FILE_UTILS.toURI(fp.getFile().getAbsolutePath()); | return FILE_UTILS.toURI(fp.getFile().getAbsolutePath()); | ||||
} | } | ||||
if (resource instanceof URLResource) { | |||||
URL u = ((URLResource) resource).getURL(); | |||||
URLProvider up = (URLProvider) resource.as(URLProvider.class); | |||||
if (up != null) { | |||||
URL u = up.getURL(); | |||||
return String.valueOf(u); | return String.valueOf(u); | ||||
} else { | } else { | ||||
return resource.getName(); | return resource.getName(); | ||||
@@ -0,0 +1,35 @@ | |||||
/* | |||||
* Licensed to the Apache Software Foundation (ASF) under one or more | |||||
* contributor license agreements. See the NOTICE file distributed with | |||||
* this work for additional information regarding copyright ownership. | |||||
* The ASF licenses this file to You under the Apache License, Version 2.0 | |||||
* (the "License"); you may not use this file except in compliance with | |||||
* the License. You may obtain a copy of the License at | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | |||||
* distributed under the License is distributed on an "AS IS" BASIS, | |||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||||
* See the License for the specific language governing permissions and | |||||
* limitations under the License. | |||||
* | |||||
*/ | |||||
package org.apache.tools.ant.types.resources; | |||||
import java.net.URL; | |||||
/** | |||||
* This is an interface that resources that can provide an URL should implement. | |||||
* This is a refactoring of {@link URLResource}, to allow other resources | |||||
* to act as sources of URLs. | |||||
* @since Ant 1.8 | |||||
*/ | |||||
public interface URLProvider { | |||||
/** | |||||
* Get the URL represented by this Resource. | |||||
* @return the file. | |||||
*/ | |||||
URL getURL(); | |||||
} |
@@ -39,7 +39,7 @@ import org.apache.tools.ant.util.FileUtils; | |||||
* Exposes a URL as a Resource. | * Exposes a URL as a Resource. | ||||
* @since Ant 1.7 | * @since Ant 1.7 | ||||
*/ | */ | ||||
public class URLResource extends Resource { | |||||
public class URLResource extends Resource implements URLProvider { | |||||
private static final FileUtils FILE_UTILS = FileUtils.getFileUtils(); | private static final FileUtils FILE_UTILS = FileUtils.getFileUtils(); | ||||
private static final int NULL_URL | private static final int NULL_URL | ||||
= Resource.getMagicNumber("null URL".getBytes()); | = Resource.getMagicNumber("null URL".getBytes()); | ||||
@@ -61,6 +61,14 @@ public class URLResource extends Resource { | |||||
setURL(u); | setURL(u); | ||||
} | } | ||||
/** | |||||
* Convenience constructor. | |||||
* @param u holds the URL to expose. | |||||
*/ | |||||
public URLResource(URLProvider u) { | |||||
setURL(u.getURL()); | |||||
} | |||||
/** | /** | ||||
* Convenience constructor. | * Convenience constructor. | ||||
* @param f the File to set as a URL. | * @param f the File to set as a URL. | ||||