You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by bo...@apache.org on 2009/09/22 17:48:47 UTC

svn commit: r817702 - in /ant/core/trunk: WHATSNEW src/main/org/apache/tools/ant/taskdefs/optional/TraXLiaison.java src/main/org/apache/tools/ant/types/resources/URLProvider.java src/main/org/apache/tools/ant/types/resources/URLResource.java

Author: bodewig
Date: Tue Sep 22 15:48:46 2009
New Revision: 817702

URL: http://svn.apache.org/viewvc?rev=817702&view=rev
Log:
URLProvider interface

Added:
    ant/core/trunk/src/main/org/apache/tools/ant/types/resources/URLProvider.java   (with props)
Modified:
    ant/core/trunk/WHATSNEW
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/TraXLiaison.java
    ant/core/trunk/src/main/org/apache/tools/ant/types/resources/URLResource.java

Modified: ant/core/trunk/WHATSNEW
URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=817702&r1=817701&r2=817702&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Tue Sep 22 15:48:46 2009
@@ -513,6 +513,11 @@
    are instances or subclasses of FileResource.
    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.
    Bugzilla Report 43936
    

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/TraXLiaison.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/TraXLiaison.java?rev=817702&r1=817701&r2=817702&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/TraXLiaison.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/TraXLiaison.java Tue Sep 22 15:48:46 2009
@@ -54,7 +54,7 @@
 import org.apache.tools.ant.types.Resource;
 import org.apache.tools.ant.types.resources.FileProvider;
 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.JAXPUtils;
 import org.xml.sax.EntityResolver;
@@ -266,13 +266,13 @@
     }
 
     private String resourceToURI(Resource resource) {
-        // TODO turn URLResource into Provider
         FileProvider fp = (FileProvider) resource.as(FileProvider.class);
         if (fp != null) {
             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);
         } else {
             return resource.getName();

Added: ant/core/trunk/src/main/org/apache/tools/ant/types/resources/URLProvider.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/types/resources/URLProvider.java?rev=817702&view=auto
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/types/resources/URLProvider.java (added)
+++ ant/core/trunk/src/main/org/apache/tools/ant/types/resources/URLProvider.java Tue Sep 22 15:48:46 2009
@@ -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();
+}

Propchange: ant/core/trunk/src/main/org/apache/tools/ant/types/resources/URLProvider.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: ant/core/trunk/src/main/org/apache/tools/ant/types/resources/URLResource.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/types/resources/URLResource.java?rev=817702&r1=817701&r2=817702&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/types/resources/URLResource.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/types/resources/URLResource.java Tue Sep 22 15:48:46 2009
@@ -39,7 +39,7 @@
  * Exposes a URL as a Resource.
  * @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 int NULL_URL
         = Resource.getMagicNumber("null URL".getBytes());
@@ -63,6 +63,14 @@
 
     /**
      * Convenience constructor.
+     * @param u holds the URL to expose.
+     */
+    public URLResource(URLProvider u) {
+        setURL(u.getURL());
+    }
+
+    /**
+     * Convenience constructor.
      * @param f the File to set as a URL.
      */
     public URLResource(File f) {