This isn't actually so important for URLResolver itself, which can be
replaced with the FileSystem resolver at will -- but without this patch,
one can't get the unique behavior of the IBiblio resolver combined with
useOrigin.
Feedback appreciated.
Index: src/java/org/apache/ivy/core/cache/DefaultRepositoryCacheManager.java
===================================================================
--- src/java/org/apache/ivy/core/cache/DefaultRepositoryCacheManager.java
(revision 1540780)
+++ 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
1540780)
+++ src/java/org/apache/ivy/core/cache/ArtifactOrigin.java (working copy)
@@ -72,6 +72,12 @@
Checks.checkNotNull(location, "location");
this.artifact = artifact;
this.isLocal = isLocal;
+ if(this.isLocal) {
+ if(location.startsWith("file:")) {
+ location = location.substring("file:".length());
+ }
+ Checks.checkAbsolute(location, "");
+ }
this.location = location;
}
Index: src/java/org/apache/ivy/plugins/repository/vfs/VfsResource.java
===================================================================
--- src/java/org/apache/ivy/plugins/repository/vfs/VfsResource.java
(revision 1540780)
+++ src/java/org/apache/ivy/plugins/repository/vfs/VfsResource.java
(working copy)
@@ -201,6 +201,14 @@
return getName().startsWith("file:");
}
+ public String getLocalName() {
+ String name = getName();
+ if(name.startsWith("file:")) {
+ return name.substring("file:".length());
+ }
+ return null;
+ }
+
public InputStream openStream() throws IOException {
return getContent().getInputStream();
}
Index: src/java/org/apache/ivy/plugins/repository/url/URLResource.java
===================================================================
--- src/java/org/apache/ivy/plugins/repository/url/URLResource.java
(revision 1540780)
+++ src/java/org/apache/ivy/plugins/repository/url/URLResource.java
(working copy)
@@ -17,20 +17,23 @@
*/
package org.apache.ivy.plugins.repository.url;
+import org.apache.ivy.plugins.repository.Resource;
+import org.apache.ivy.util.url.URLHandler.URLInfo;
+import org.apache.ivy.util.url.URLHandlerRegistry;
+
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
-import org.apache.ivy.plugins.repository.Resource;
-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 +44,22 @@
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()) {
+ return url.getPath();
+ }
+ return null;
+ }
+
public Resource clone(String cloneName) {
try {
return new URLResource(new URL(cloneName));
@@ -91,8 +106,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/url/URLRepository.java
===================================================================
--- src/java/org/apache/ivy/plugins/repository/url/URLRepository.java
(revision 1540780)
+++ src/java/org/apache/ivy/plugins/repository/url/URLRepository.java
(working copy)
@@ -17,18 +17,6 @@
*/
package org.apache.ivy.plugins.repository.url;
-import java.io.File;
-import java.io.IOException;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.ListIterator;
-import java.util.Map;
-
import org.apache.ivy.plugins.repository.AbstractRepository;
import org.apache.ivy.plugins.repository.RepositoryCopyProgressListener;
import org.apache.ivy.plugins.repository.Resource;
@@ -36,20 +24,29 @@
import org.apache.ivy.util.FileUtil;
import org.apache.ivy.util.url.ApacheURLLister;
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.*;
+
public class URLRepository extends AbstractRepository {
private RepositoryCopyProgressListener progress = new
RepositoryCopyProgressListener(this);
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;
}
-
+
public void get(String source, File destination) throws IOException {
fireTransferInitiated(getResource(source), TransferEvent.REQUEST_GET);
try {
@@ -138,4 +135,12 @@
return null;
}
+ public void setLocalIfFileUrl(boolean value) {
+ localIfFileUrl = value;
+ }
+
+ public boolean getLocalIfFileUrl() {
+ return localIfFileUrl;
+ }
+
}
Index: src/java/org/apache/ivy/plugins/repository/LazyResource.java
===================================================================
--- src/java/org/apache/ivy/plugins/repository/LazyResource.java
(revision 1540780)
+++ 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 1540780)
+++ 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 1540780)
+++ 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 1540780)
+++ 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 1540780)
+++ 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 1540780)
+++ 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 1540780)
+++ src/java/org/apache/ivy/plugins/repository/ResourceHelper.java
(working copy)
@@ -17,13 +17,12 @@
*/
package org.apache.ivy.plugins.repository;
+import org.apache.ivy.plugins.repository.url.URLResource;
+import org.apache.ivy.util.Message;
+
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;
-
public final class ResourceHelper {
private ResourceHelper() {
@@ -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
1540780)
+++ 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/resolver/packager/BuiltFileResource.java
===================================================================
--- src/java/org/apache/ivy/plugins/resolver/packager/BuiltFileResource.java
(revision 1540780)
+++ 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));
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]