The version here adds a unit test, and patches URLResolver per prior
feedback (which had failed to make it into the public version of the
patch's r2).
Index: src/java/org/apache/ivy/plugins/repository/url/URLRepository.java
===================================================================
--- src/java/org/apache/ivy/plugins/repository/url/URLRepository.java   
(revision 1543060)
+++ src/java/org/apache/ivy/plugins/repository/url/URLRepository.java   
(working copy)
@@ -41,10 +41,12 @@
 
     private Map resourcesCache = new HashMap();
 
+    private boolean localIfFileUrl = true;
+
     public Resource getResource(String source) throws IOException {
         Resource res = (Resource) resourcesCache.get(source);
         if (res == null) {
-            res = new URLResource(new URL(source));
+            res = new URLResource(new URL(source), localIfFileUrl);
             resourcesCache.put(source, res);
         }
         return res;
@@ -138,4 +140,12 @@
         return null;
     }
 
+    public void setLocalIfFileUrl(boolean value) {
+        localIfFileUrl = value;
+    }
+
+    public boolean getLocalIfFileUrl() {
+        return localIfFileUrl;
+    }
+
 }
Index: src/java/org/apache/ivy/plugins/repository/url/URLResource.java
===================================================================
--- src/java/org/apache/ivy/plugins/repository/url/URLResource.java     
(revision 1543060)
+++ src/java/org/apache/ivy/plugins/repository/url/URLResource.java     
(working copy)
@@ -17,20 +17,26 @@
  */
 package org.apache.ivy.plugins.repository.url;
 
+import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.MalformedURLException;
+import java.net.URISyntaxException;
 import java.net.URL;
 
 import org.apache.ivy.plugins.repository.Resource;
+import org.apache.ivy.util.Message;
 import org.apache.ivy.util.url.URLHandlerRegistry;
 import org.apache.ivy.util.url.URLHandler.URLInfo;
 
 public class URLResource implements Resource {
     private URL url;
 
     private boolean init = false;
 
+    /** whether file:// URLs are local */
+    private boolean localIfFileUrl = true;
+
     private long lastModified;
 
     private long contentLength;
@@ -41,10 +47,27 @@
         this.url = url;
     }
 
+    public URLResource(URL url, boolean localIfFileUrl) {
+        this(url);
+        this.localIfFileUrl = localIfFileUrl;
+    }
+
     public String getName() {
         return url.toExternalForm();
     }
 
+    public String getLocalName() {
+        if(isLocal()) {
+            try {
+                return new File(url.toURI()).getPath();
+            } catch (URISyntaxException e) {
+                Message.warn("Unable to parse URI for local name " + 
getName(), e);
+                return null;
+            }
+        }
+        return null;
+    }
+
     public Resource clone(String cloneName) {
         try {
             return new URLResource(new URL(cloneName));
@@ -91,8 +114,16 @@
         return getName();
     }
 
+    public void setLocalIfFileUrl(boolean value) {
+        localIfFileUrl = value;
+    }
+
+    public boolean getLocalIfFileUrl() {
+        return localIfFileUrl;
+    }
+
     public boolean isLocal() {
-        return false;
+        return localIfFileUrl && "file".equals(url.getProtocol());
     }
 
     public InputStream openStream() throws IOException {
Index: src/java/org/apache/ivy/plugins/repository/LazyResource.java
===================================================================
--- src/java/org/apache/ivy/plugins/repository/LazyResource.java        
(revision 1543060)
+++ src/java/org/apache/ivy/plugins/repository/LazyResource.java        
(working copy)
@@ -62,6 +62,10 @@
         return name;
     }
 
+    public String getLocalName() {
+        return null;
+    }
+
     public boolean isLocal() {
         checkInit();
         return local;
Index: src/java/org/apache/ivy/plugins/repository/BasicResource.java
===================================================================
--- src/java/org/apache/ivy/plugins/repository/BasicResource.java       
(revision 1543060)
+++ src/java/org/apache/ivy/plugins/repository/BasicResource.java       
(working copy)
@@ -60,6 +60,10 @@
         return this.name;
     }
 
+    public String getLocalName() {
+        return null;
+    }
+
     public boolean isLocal() {
         return this.local;
     }
Index: src/java/org/apache/ivy/plugins/repository/sftp/SFTPResource.java
===================================================================
--- src/java/org/apache/ivy/plugins/repository/sftp/SFTPResource.java   
(revision 1543060)
+++ src/java/org/apache/ivy/plugins/repository/sftp/SFTPResource.java   
(working copy)
@@ -44,6 +44,10 @@
         return path;
     }
 
+    public String getLocalName() {
+        return null;
+    }
+
     public Resource clone(String cloneName) {
         return new SFTPResource(repository, cloneName);
     }
Index: src/java/org/apache/ivy/plugins/repository/jar/JarResource.java
===================================================================
--- src/java/org/apache/ivy/plugins/repository/jar/JarResource.java     
(revision 1543060)
+++ src/java/org/apache/ivy/plugins/repository/jar/JarResource.java     
(working copy)
@@ -42,6 +42,10 @@
         return path;
     }
 
+    public String getLocalName() {
+        return null;
+    }
+
     public long getLastModified() {
         return entry.getTime();
     }
Index: src/java/org/apache/ivy/plugins/repository/file/FileResource.java
===================================================================
--- src/java/org/apache/ivy/plugins/repository/file/FileResource.java   
(revision 1543060)
+++ src/java/org/apache/ivy/plugins/repository/file/FileResource.java   
(working copy)
@@ -38,6 +38,10 @@
         return file.getPath();
     }
 
+    public String getLocalName() {
+        return file.getPath();
+    }
+
     public Resource clone(String cloneName) {
         return new FileResource(repository, repository.getFile(cloneName));
     }
Index: src/java/org/apache/ivy/plugins/repository/ssh/SshResource.java
===================================================================
--- src/java/org/apache/ivy/plugins/repository/ssh/SshResource.java     
(revision 1543060)
+++ src/java/org/apache/ivy/plugins/repository/ssh/SshResource.java     
(working copy)
@@ -115,6 +115,10 @@
         return uri;
     }
 
+    public String getLocalName() {
+        return null;
+    }
+
     public String toString() {
         StringBuffer buffer = new StringBuffer();
         buffer.append("SshResource:");
Index: src/java/org/apache/ivy/plugins/repository/ResourceHelper.java
===================================================================
--- src/java/org/apache/ivy/plugins/repository/ResourceHelper.java      
(revision 1543060)
+++ src/java/org/apache/ivy/plugins/repository/ResourceHelper.java      
(working copy)
@@ -20,7 +20,6 @@
 import java.io.File;
 import java.net.MalformedURLException;
 
-import org.apache.ivy.plugins.repository.file.FileResource;
 import org.apache.ivy.plugins.repository.url.URLResource;
 import org.apache.ivy.util.Message;
 
@@ -37,9 +36,11 @@
         if (res == null || f == null) {
             return false;
         }
-        if (res instanceof FileResource) {
-            return new File(res.getName()).equals(f);
-        } else if (res instanceof URLResource) {
+        String localName = res.getLocalName();
+        if(localName != null) {
+            return new File(localName).equals(f);
+        }
+        if (res instanceof URLResource) {
             try {
                 return 
f.toURI().toURL().toExternalForm().equals(res.getName());
             } catch (MalformedURLException e) {
Index: src/java/org/apache/ivy/plugins/repository/Resource.java
===================================================================
--- src/java/org/apache/ivy/plugins/repository/Resource.java    (revision 
1543060)
+++ src/java/org/apache/ivy/plugins/repository/Resource.java    (working copy)
@@ -53,6 +53,13 @@
     public String getName();
 
     /**
+     * Get a local filesystem name to refer to the resource. Only valid if 
isLocal() returns true.
+     *
+     * @return local filesystem name for the resource.
+     */
+    public String getLocalName();
+
+    /**
      * Get the date the resource was last modified
      * 
      * @return A <code>long</code> value representing the time the file was 
last modified,
Index: src/java/org/apache/ivy/plugins/repository/vfs/VfsResource.java
===================================================================
--- src/java/org/apache/ivy/plugins/repository/vfs/VfsResource.java     
(revision 1543060)
+++ src/java/org/apache/ivy/plugins/repository/vfs/VfsResource.java     
(working copy)
@@ -17,8 +17,11 @@
  */
 package org.apache.ivy.plugins.repository.vfs;
 
+import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
+import java.net.URI;
+import java.net.URISyntaxException;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -201,6 +204,19 @@
         return getName().startsWith("file:");
     }
 
+    public String getLocalName() {
+        String name = getName();
+        if(name.startsWith("file:")) {
+            try {
+                return new File(new URI(name)).getPath();
+            } catch (URISyntaxException e) {
+                Message.warn("Unable to parse URI for local name " + 
getName(), e);
+                return null;
+            }
+        }
+        return null;
+    }
+
     public InputStream openStream() throws IOException {
         return getContent().getInputStream();
     }
Index: src/java/org/apache/ivy/plugins/resolver/packager/BuiltFileResource.java
===================================================================
--- src/java/org/apache/ivy/plugins/resolver/packager/BuiltFileResource.java    
(revision 1543060)
+++ src/java/org/apache/ivy/plugins/resolver/packager/BuiltFileResource.java    
(working copy)
@@ -50,6 +50,10 @@
     public String getName() {
         return file.toURI().toString();
     }
+    
+    public String getLocalName() {
+        return null;
+    }
 
     public Resource clone(String name) {
         return new BuiltFileResource(new File(name));
Index: src/java/org/apache/ivy/core/cache/DefaultRepositoryCacheManager.java
===================================================================
--- src/java/org/apache/ivy/core/cache/DefaultRepositoryCacheManager.java       
(revision 1543060)
+++ src/java/org/apache/ivy/core/cache/DefaultRepositoryCacheManager.java       
(working copy)
@@ -863,10 +863,11 @@
                 try {
                     ResolvedResource artifactRef = 
resourceResolver.resolve(artifact);
                     if (artifactRef != null) {
+                        String localName = 
artifactRef.getResource().getLocalName();
                         origin = new ArtifactOrigin(
                             artifact,
                             artifactRef.getResource().isLocal(),
-                            artifactRef.getResource().getName());
+                            localName != null ? localName : 
artifactRef.getResource().getName());
                         if (useOrigin && artifactRef.getResource().isLocal()) {
                             saveArtifactOrigin(artifact, origin);
                             archiveFile = getArchiveFileInCache(artifact, 
origin);
Index: src/java/org/apache/ivy/core/cache/ArtifactOrigin.java
===================================================================
--- src/java/org/apache/ivy/core/cache/ArtifactOrigin.java      (revision 
1543060)
+++ src/java/org/apache/ivy/core/cache/ArtifactOrigin.java      (working copy)
@@ -17,6 +17,10 @@
  */
 package org.apache.ivy.core.cache;
 
+import java.io.File;
+import java.net.URI;
+import java.net.URISyntaxException;
+
 import org.apache.ivy.core.module.descriptor.Artifact;
 import org.apache.ivy.util.Checks;
 
@@ -72,6 +76,16 @@
         Checks.checkNotNull(location, "location");
         this.artifact = artifact;
         this.isLocal = isLocal;
+        if(this.isLocal) {
+            if(location.startsWith("file:")) {
+                try {
+                    location = new File(new URI(location)).getPath();
+                } catch (URISyntaxException e) {
+                    throw new IllegalArgumentException(e);
+                }
+            }
+            Checks.checkAbsolute(location, "");
+        }
         this.location = location;
     }
 
Index: test/java/org/apache/ivy/plugins/resolver/URLResolverTest.java
===================================================================
--- test/java/org/apache/ivy/plugins/resolver/URLResolverTest.java      
(revision 1543060)
+++ test/java/org/apache/ivy/plugins/resolver/URLResolverTest.java      
(working copy)
@@ -355,6 +355,55 @@
         assertNotNull(ar);
 
         assertEquals(artifact, ar.getArtifact());
-        assertEquals(DownloadStatus.SUCCESSFUL, ar.getDownloadStatus());
+        assertEquals(DownloadStatus.NO, ar.getDownloadStatus());
     }
+
+    public void testDownloadFromUrlWithSpaces() throws Exception {
+        File rootbase = new java.io.File("build/repositories");
+        rootbase.mkdirs();
+        File rootfile = new java.io.File(rootbase, "copy of 1");
+        if (rootfile.exists()) {
+            FileUtils.deleteDirectory(rootfile);
+        }
+        FileUtils.copyDirectory(
+                new java.io.File("test/repositories/1"),
+                rootfile);
+        String rootpath = rootfile.getAbsolutePath().replace(" ", "%20");
+        assertTrue(rootpath.matches(".*[%]20.*"));
+
+        URLResolver resolver = new URLResolver();
+        URLRepository repository = (URLRepository)resolver.getRepository();
+
+        resolver.setSettings(settings);
+        resolver.addIvyPattern("file:" + rootpath
+                + "/[organisation]/[module]/ivys/ivy-[revision].xml");
+        resolver.addArtifactPattern("file:" + rootpath
+                + 
"/[organisation]/[module]/[type]s/[artifact]-[revision].[type]");
+        resolver.setName("test");
+        ((DefaultRepositoryCacheManager) 
resolver.getRepositoryCacheManager()).setUseOrigin(false);
+        assertEquals("test", resolver.getName());
+
+        ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1", "mod1.1", 
"1.0");
+        ResolvedModuleRevision rmr = resolver.getDependency(new 
DefaultDependencyDescriptor(mrid,
+                true), data);
+        assertNotNull(rmr);
+
+        assertEquals(mrid, rmr.getId());
+        Date pubdate = new GregorianCalendar(2004, 10, 1, 11, 0, 0).getTime();
+        assertEquals(pubdate, rmr.getPublicationDate());
+
+        // test to ask to download
+        DefaultArtifact artifact = new DefaultArtifact(mrid, pubdate, 
"mod1.1", "jar", "jar");
+        DownloadReport report = resolver.download(new Artifact[] {artifact},
+                new DownloadOptions());
+        assertNotNull(report);
+
+        assertEquals(1, report.getArtifactsReports().length);
+
+        ArtifactDownloadReport ar = report.getArtifactReport(artifact);
+        assertNotNull(ar);
+
+        assertEquals(artifact, ar.getArtifact());
+        assertEquals(DownloadStatus.SUCCESSFUL, ar.getDownloadStatus());
+    }
 }
Index: ivy.xml
===================================================================
--- ivy.xml     (revision 1543060)
+++ ivy.xml     (working copy)
@@ -55,6 +55,7 @@
 
                <!-- Test dependencies -->
                <dependency org="junit" name="junit" rev="3.8.2" 
conf="test->default" />
+               <dependency org="commons-io" name="commons-io" rev="2.4" 
conf="test->default" />
                <dependency org="commons-lang" name="commons-lang" rev="2.6" 
conf="test->default" />
                <dependency org="org.apache.ant" name="ant-testutil" 
rev="1.7.0" conf="test->default" transitive="false" />
         <dependency org="ant" name="ant-launcher" rev="1.6.2" 
conf="test->default" transitive="false"/>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@ant.apache.org
For additional commands, e-mail: dev-h...@ant.apache.org

Reply via email to