You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by hi...@apache.org on 2013/12/27 22:10:19 UTC

svn commit: r1553739 - in /ant/ivy/core/trunk: ./ src/java/org/apache/ivy/core/cache/ src/java/org/apache/ivy/plugins/repository/ src/java/org/apache/ivy/plugins/repository/url/ test/java/org/apache/ivy/plugins/resolver/

Author: hibou
Date: Fri Dec 27 21:10:19 2013
New Revision: 1553739

URL: http://svn.apache.org/r1553739
Log:
avoid copy with url resolvers configured with a 'file:/' URL if useOrigin=true

Added:
    ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/LocalizableResource.java   (with props)
Modified:
    ant/ivy/core/trunk/CHANGES.txt
    ant/ivy/core/trunk/src/java/org/apache/ivy/core/cache/ArtifactOrigin.java
    ant/ivy/core/trunk/src/java/org/apache/ivy/core/cache/DefaultRepositoryCacheManager.java
    ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/url/URLResource.java
    ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/resolver/URLResolverTest.java

Modified: ant/ivy/core/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/CHANGES.txt?rev=1553739&r1=1553738&r2=1553739&view=diff
==============================================================================
--- ant/ivy/core/trunk/CHANGES.txt (original)
+++ ant/ivy/core/trunk/CHANGES.txt Fri Dec 27 21:10:19 2013
@@ -154,6 +154,7 @@ for detailed view of each issue, please 
 - IMPROVEMENT: add support for source bundles from p2 repositories
 - IMPROVEMENT: add support for source URI from OBR repositories
 - IMPROVEMENT: Also copy original metadata artifact (e.g. POM) on ivy:install (IVY-1431) (Thanks to Erwin Tratar)
+- IMPROVEMENT: useOrigin will do avoid copy with url resolvers configured with a 'file:/' URL
 
 - FIX: In IvyDE, Ivy fails to parse ivy-settings.xml file if it contains <pgp> element (thanks to Gregory Amerson) (IVY-1441)
 - FIX: ParseException when "Bundle-Description" is present in OSGi MANIFEST.MF (IVY-1438)

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/core/cache/ArtifactOrigin.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/core/cache/ArtifactOrigin.java?rev=1553739&r1=1553738&r2=1553739&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/core/cache/ArtifactOrigin.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/core/cache/ArtifactOrigin.java Fri Dec 27 21:10:19 2013
@@ -92,7 +92,11 @@ public class ArtifactOrigin {
     public String getLocation() {
         return location;
     }
-    
+
+    public void setLocation(String location) {
+        this.location = location;
+    }
+
     /**
      * Return the artifact that this location is pointing at.
      * 

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/core/cache/DefaultRepositoryCacheManager.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/core/cache/DefaultRepositoryCacheManager.java?rev=1553739&r1=1553738&r2=1553739&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/core/cache/DefaultRepositoryCacheManager.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/core/cache/DefaultRepositoryCacheManager.java Fri Dec 27 21:10:19 2013
@@ -63,10 +63,12 @@ import org.apache.ivy.plugins.parser.Mod
 import org.apache.ivy.plugins.parser.ParserSettings;
 import org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorParser;
 import org.apache.ivy.plugins.repository.ArtifactResourceResolver;
+import org.apache.ivy.plugins.repository.LocalizableResource;
 import org.apache.ivy.plugins.repository.Repository;
 import org.apache.ivy.plugins.repository.Resource;
 import org.apache.ivy.plugins.repository.ResourceDownloader;
 import org.apache.ivy.plugins.repository.ResourceHelper;
+import org.apache.ivy.plugins.repository.url.URLResource;
 import org.apache.ivy.plugins.resolver.AbstractResolver;
 import org.apache.ivy.plugins.resolver.DependencyResolver;
 import org.apache.ivy.plugins.resolver.util.ResolvedResource;
@@ -962,11 +964,13 @@ public class DefaultRepositoryCacheManag
                 try {
                     ResolvedResource artifactRef = resourceResolver.resolve(artifact);
                     if (artifactRef != null) {
-                        origin = new ArtifactOrigin(
-                            artifact,
-                            artifactRef.getResource().isLocal(),
-                            artifactRef.getResource().getName());
-                        if (useOrigin && artifactRef.getResource().isLocal()) {
+                        Resource artifactRes = artifactRef.getResource();
+                        origin = new ArtifactOrigin(artifact, artifactRes.isLocal(),
+                                artifactRes.getName());
+                        if (useOrigin && artifactRes.isLocal()) {
+                            if (artifactRes instanceof LocalizableResource) {
+                                origin.setLocation(((LocalizableResource) artifactRes).getFile().getAbsolutePath());
+                            }
                             saveArtifactOrigin(artifact, origin);
                             archiveFile = getArchiveFileInCache(artifact, origin);
                             adr.setDownloadStatus(DownloadStatus.NO);
@@ -976,7 +980,7 @@ public class DefaultRepositoryCacheManag
                         } else {
                             // refresh archive file now that we better now its origin
                             archiveFile = getArchiveFileInCache(artifact, origin, useOrigin);
-                            if (ResourceHelper.equals(artifactRef.getResource(), archiveFile)) {
+                            if (ResourceHelper.equals(artifactRes, archiveFile)) {
                                 throw new IllegalStateException("invalid settings for '"
                                     + resourceResolver
                                     + "': pointing repository to ivy cache is forbidden !");
@@ -985,8 +989,7 @@ public class DefaultRepositoryCacheManag
                                 listener.startArtifactDownload(this, artifactRef, artifact, origin);
                             }
 
-                            resourceDownloader.download(
-                                artifact, artifactRef.getResource(), archiveFile);
+                            resourceDownloader.download(artifact, artifactRes, archiveFile);
                             adr.setSize(archiveFile.length());
                             saveArtifactOrigin(artifact, origin);
                             adr.setDownloadTimeMillis(System.currentTimeMillis() - start);

Added: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/LocalizableResource.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/LocalizableResource.java?rev=1553739&view=auto
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/LocalizableResource.java (added)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/LocalizableResource.java Fri Dec 27 21:10:19 2013
@@ -0,0 +1,38 @@
+/*
+ *  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.ivy.plugins.repository;
+
+import java.io.File;
+
+/**
+ * Resource which can be located locally
+ * <p>
+ * If local (checked via {@link #isLocal()}), {@link #getFile()} will return its local location,
+ * without any download or copy involved
+ * </p>
+ */
+public interface LocalizableResource extends Resource {
+
+    /**
+     * @return the local file of this resource.
+     * @throws IllegalStateException
+     *             when {@link #isLocal()} returns <code>false</code>
+     */
+    public File getFile();
+
+}

Propchange: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/LocalizableResource.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/LocalizableResource.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Propchange: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/LocalizableResource.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/url/URLResource.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/url/URLResource.java?rev=1553739&r1=1553738&r2=1553739&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/url/URLResource.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/url/URLResource.java Fri Dec 27 21:10:19 2013
@@ -17,16 +17,19 @@
  */
 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.LocalizableResource;
 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 {
+public class URLResource implements LocalizableResource {
     private URL url;
 
     private boolean init = false;
@@ -92,10 +95,21 @@ public class URLResource implements Reso
     }
 
     public boolean isLocal() {
-        return false;
+        return url.getProtocol().equals("file");
     }
 
     public InputStream openStream() throws IOException {
         return URLHandlerRegistry.getDefault().openStream(url);
     }
+
+    public File getFile() {
+        if (!isLocal()) {
+            throw new IllegalStateException("Cannot get the local file for the not local resource " + url);
+        }
+        try {
+            return new File(url.toURI());
+        } catch (URISyntaxException e) {
+            return new File(url.getPath());            
+        }
+    }
 }

Modified: ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/resolver/URLResolverTest.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/resolver/URLResolverTest.java?rev=1553739&r1=1553738&r2=1553739&view=diff
==============================================================================
--- ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/resolver/URLResolverTest.java (original)
+++ ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/resolver/URLResolverTest.java Fri Dec 27 21:10:19 2013
@@ -355,6 +355,6 @@ public class URLResolverTest extends Abs
         assertNotNull(ar);
 
         assertEquals(artifact, ar.getArtifact());
-        assertEquals(DownloadStatus.SUCCESSFUL, ar.getDownloadStatus());
+        assertEquals(DownloadStatus.NO, ar.getDownloadStatus());
     }
 }