You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by ma...@apache.org on 2010/05/10 22:07:08 UTC

svn commit: r942885 - in /ant/ivy/core/trunk: ./ doc/settings/ doc/use/ src/java/org/apache/ivy/ant/ src/java/org/apache/ivy/core/retrieve/ src/java/org/apache/ivy/core/settings/ test/java/org/apache/ivy/core/retrieve/

Author: maartenc
Date: Mon May 10 20:07:08 2010
New Revision: 942885

URL: http://svn.apache.org/viewvc?rev=942885&view=rev
Log:
IMPROVEMENT: retrieve doesn't retrive files if the current one is more recent (IVY-1044)

Modified:
    ant/ivy/core/trunk/CHANGES.txt
    ant/ivy/core/trunk/doc/settings/caches.html
    ant/ivy/core/trunk/doc/settings/settings.html
    ant/ivy/core/trunk/doc/use/retrieve.html
    ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyRetrieve.java
    ant/ivy/core/trunk/src/java/org/apache/ivy/core/retrieve/RetrieveEngine.java
    ant/ivy/core/trunk/src/java/org/apache/ivy/core/retrieve/RetrieveOptions.java
    ant/ivy/core/trunk/src/java/org/apache/ivy/core/settings/XmlSettingsParser.java
    ant/ivy/core/trunk/test/java/org/apache/ivy/core/retrieve/RetrieveTest.java

Modified: ant/ivy/core/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/CHANGES.txt?rev=942885&r1=942884&r2=942885&view=diff
==============================================================================
--- ant/ivy/core/trunk/CHANGES.txt (original)
+++ ant/ivy/core/trunk/CHANGES.txt Mon May 10 20:07:08 2010
@@ -115,6 +115,7 @@ for detailed view of each issue, please 
 - NEW: Support ivy.xml parent mechanism (IVY-742) (thanks to Jason Trump and Jean-Louis Boudart)
 - NEW: Make ivy.xml <conf description> available (IVY-1158)
 
+- IMPROVEMENT: retrieve doesn't retrive files if the current one is more recent (IVY-1044)
 - IMPROVEMENT: better diagnostics when reporting bad ivy file in cache (IVY-1190)
 - IMPROVEMENT: Support changing="true" for inline retrieve (IVY-1180)
 - IMPROVEMENT: Enhance <info/> task to access the 'publication', 'branch' and published artifacts as ant propeties (IVY-395) (thanks to Carl Quinn)

Modified: ant/ivy/core/trunk/doc/settings/caches.html
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/doc/settings/caches.html?rev=942885&r1=942884&r2=942885&view=diff
==============================================================================
--- ant/ivy/core/trunk/doc/settings/caches.html (original)
+++ ant/ivy/core/trunk/doc/settings/caches.html Mon May 10 20:07:08 2010
@@ -58,7 +58,8 @@ cache to another place in your filesyste
         <td>No, defaults to [organisation]/[module]/ivy-[revision].xml</td></tr>
     <tr><td>artifactPattern</td><td>default pattern used to indicate where artifact files should be put in the repository cache(s)</td>
         <td>No, defaults to [organisation]/[module]/[type]s/[artifact]-[revision].[ext]</td></tr>
-    <tr><td>checkUpToDate</td><td>Indicates if date should be checked before retrieving artifacts from cache</td>
+    <tr><td><s>checkUpToDate</s></td><td>Indicates if date should be checked before retrieving artifacts from cache.
+    	<i>Deprecated, we recommend using overwriteMode on the [[use/retrieve]] task instead</i></td>
         <td>No, defaults to true</td></tr>
     <tr><td>useOrigin</td><td>the default value to use for useOrigin for caches in which it isn't specifically defined.
     	Use true to avoid the copy of local artifacts to the cache and use directly their original location.</td>

Modified: ant/ivy/core/trunk/doc/settings/settings.html
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/doc/settings/settings.html?rev=942885&r1=942884&r2=942885&view=diff
==============================================================================
--- ant/ivy/core/trunk/doc/settings/settings.html (original)
+++ ant/ivy/core/trunk/doc/settings/settings.html Mon May 10 20:07:08 2010
@@ -65,7 +65,7 @@ So if there is a setting in the resolver
 	    <i>Deprecated, we recommend using defaultCacheDir on the [[settings/caches]] tag instead</i></td>
         <td>No, defaults to .ivy2/cache in user home</td></tr>
     <tr><td><s>checkUpToDate</s></td><td>Indicates if date should be checked before retrieving artifacts from cache.
-    	<i>Deprecated, we recommend using checkUpToDate on the [[settings/caches]] tag instead</i></td>
+    	<i>Deprecated, we recommend using overwriteMode on the [[use/retrieve]] task instead</i></td>
         <td>No, defaults to true</td></tr>
     <tr><td><s>cacheIvyPattern</s></td><td>a pattern to indicate where ivy files should be put in cache.
     	<i>Deprecated, we recommend using ivyPattern on the [[settings/caches]] tag instead</i></td>

Modified: ant/ivy/core/trunk/doc/use/retrieve.html
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/doc/use/retrieve.html?rev=942885&r1=942884&r2=942885&view=diff
==============================================================================
--- ant/ivy/core/trunk/doc/use/retrieve.html (original)
+++ ant/ivy/core/trunk/doc/use/retrieve.html Mon May 10 20:07:08 2010
@@ -54,12 +54,18 @@ root: lib
         <td>No. Defaults to false</td></tr>
     <tr><td>type</td><td>comma separated list of accepted artifact types <span class="since">since 1.4</span></td>
         <td>No. All artifact types are accepted by default.</td></tr>
+    <tr><td>overwriteMode</td><td>option to configure when the destination file should be overwritten if it exist <span class="since">(since 2.2.0)</span>. Possible values are:
+<ul><li><b>newer</b> (default)</li> overwrite the destination file if a more recent one is available (based on timestamp)
+<li><b>different</b></li> overwrite the destination file if the timestamp is different
+<li><b>always</b></li> always overwrite the destination file
+<li><b>never</b></li> never overwrite the destination file
+</ul></td><td>No. Defaults to 'newer'.</td></tr>
     <tr><td>symlink</td><td>true to create symbolic links, false to copy the artifacts. The destination of the symbolic links depends on the value of the useOrigin attribute <span class="since">(since 2.0)</span></td><td>No. Defaults to false</td></tr>
     <tr><td>settingsRef</td><td>A reference to the ivy settings that must be used by this task <span class="since">(since 2.0)</span></td><td>No, 'ivy.instance' is taken by default.</td></tr></tbody>
     <tr><td>log</td><td>the log setting to use during the resolve and retrieve process. <span class="since">(since 2.0)</span><br/>
 Available options are the same as for [[ant:resolve]] when used to trigger resolve automatically (see [[ant:postresolvetask]]), or the following for the retrieve process only:
-<ul><li>default</li> the default log settings, where all usual messages are output to the console
-<li>quiet</li> disable all usual messages, making the whole retrieve process quiet unless errors occur
+<ul><li><b>default</b></li> the default log settings, where all usual messages are output to the console
+<li><b>quiet</b></li> disable all usual messages, making the whole retrieve process quiet unless errors occur
 </ul></td><td>No, defaults to 'default'.</td></tr>
 </table>
 <h1>Examples</h1>

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyRetrieve.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyRetrieve.java?rev=942885&r1=942884&r2=942885&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyRetrieve.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyRetrieve.java Mon May 10 20:07:08 2010
@@ -29,6 +29,12 @@ import org.apache.tools.ant.BuildExcepti
  * This task allow to retrieve dependencies from the cache to a local directory like a lib dir.
  */
 public class IvyRetrieve extends IvyPostResolveTask {
+    
+    private static final Collection OVERWRITEMODE_VALUES = Arrays.asList(new String[] {
+            RetrieveOptions.OVERWRITEMODE_ALWAYS, RetrieveOptions.OVERWRITEMODE_NEVER,
+            RetrieveOptions.OVERWRITEMODE_NEWER, RetrieveOptions.OVERWRITEMODE_DIFFERENT
+    });
+
     private String pattern;
 
     private String ivypattern = null;
@@ -36,6 +42,8 @@ public class IvyRetrieve extends IvyPost
     private boolean sync = false;
 
     private boolean symlink = false;
+    
+    private String overwriteMode = RetrieveOptions.OVERWRITEMODE_NEWER;
 
     public String getPattern() {
         return pattern;
@@ -65,6 +73,7 @@ public class IvyRetrieve extends IvyPost
                     .setDestIvyPattern(ivypattern)
                     .setArtifactFilter(artifactFilter)
                     .setSync(sync)
+                    .setOverwriteMode(getOverwriteMode())
                     .setUseOrigin(isUseOrigin())
                     .setMakeSymlinks(symlink)
                     .setResolveId(getResolveId()));
@@ -103,4 +112,16 @@ public class IvyRetrieve extends IvyPost
     public void setSymlink(boolean symlink) {
         this.symlink = symlink;
     }
+
+    public void setOverwriteMode(String overwriteMode) {
+        if (!OVERWRITEMODE_VALUES.contains(overwriteMode)) {
+            throw new IllegalArgumentException("invalid overwriteMode value '" + overwriteMode + "'. "
+                + "Valid values are " + OVERWRITEMODE_VALUES);
+        }
+        this.overwriteMode = overwriteMode;
+    }
+
+    public String getOverwriteMode() {
+        return overwriteMode;
+    }
 }

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/core/retrieve/RetrieveEngine.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/core/retrieve/RetrieveEngine.java?rev=942885&r1=942884&r2=942885&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/core/retrieve/RetrieveEngine.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/core/retrieve/RetrieveEngine.java Mon May 10 20:07:08 2010
@@ -128,7 +128,7 @@ public class RetrieveEngine {
                 for (Iterator it2 = dest.iterator(); it2.hasNext();) {
                     IvyContext.getContext().checkInterrupted();
                     File destFile = settings.resolveFile((String) it2.next());
-                    if (!settings.isCheckUpToDate() || !upToDate(archive, destFile)) {
+                    if (!settings.isCheckUpToDate() || !upToDate(archive, destFile, options)) {
                         Message.verbose("\t\tto " + destFile);
                         if (this.eventManager != null) {
                             this.eventManager.fireIvyEvent(
@@ -389,11 +389,30 @@ public class RetrieveEngine {
         return artifactsToCopy;
     }
 
-    private boolean upToDate(File source, File target) {
+    private boolean upToDate(File source, File target, RetrieveOptions options) {
         if (!target.exists()) {
             return false;
         }
-        return source.lastModified() <= target.lastModified();
+        
+        String overwriteMode = options.getOverwriteMode();
+        if (RetrieveOptions.OVERWRITEMODE_ALWAYS.equals(overwriteMode)) {
+            return false;
+        }
+        
+        if (RetrieveOptions.OVERWRITEMODE_NEVER.equals(overwriteMode)) {
+            return true;
+        }
+        
+        if (RetrieveOptions.OVERWRITEMODE_NEWER.equals(overwriteMode)) {
+            return source.lastModified() <= target.lastModified();
+        }
+        
+        if (RetrieveOptions.OVERWRITEMODE_NEWER.equals(overwriteMode)) {
+            return source.lastModified() != target.lastModified();
+        }
+
+        // unknown, so just to be sure
+        return false;
     }
 
     /**

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/core/retrieve/RetrieveOptions.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/core/retrieve/RetrieveOptions.java?rev=942885&r1=942884&r2=942885&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/core/retrieve/RetrieveOptions.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/core/retrieve/RetrieveOptions.java Mon May 10 20:07:08 2010
@@ -27,6 +27,11 @@ import org.apache.ivy.util.filter.Filter
  * @see RetrieveEngine
  */
 public class RetrieveOptions extends LogOptions {
+    public static String OVERWRITEMODE_NEVER = "never";
+    public static String OVERWRITEMODE_ALWAYS = "always";
+    public static String OVERWRITEMODE_NEWER = "newer";
+    public static String OVERWRITEMODE_DIFFERENT = "different";
+    
     /**
      * The names of configurations to retrieve. If the array consists only of '*', then all
      * configurations of the module will be retrieved.
@@ -50,6 +55,8 @@ public class RetrieveOptions extends Log
      * will be present in the destination directory, which means that some files may be deleted.
      */
     private boolean sync = false;
+    
+    private String overwriteMode = OVERWRITEMODE_NEWER;
 
     /**
      * True if the original files should be used insteaad of their cache copy.
@@ -84,6 +91,15 @@ public class RetrieveOptions extends Log
         this.confs = confs;
         return this;
     }
+    
+    public String getOverwriteMode() {
+        return overwriteMode == null ? OVERWRITEMODE_NEWER : overwriteMode;
+    }
+    
+    public RetrieveOptions setOverwriteMode(String overwriteMode) {
+        this.overwriteMode = overwriteMode;
+        return this;
+    }
 
     public String getDestIvyPattern() {
         return destIvyPattern;

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/core/settings/XmlSettingsParser.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/core/settings/XmlSettingsParser.java?rev=942885&r1=942884&r2=942885&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/core/settings/XmlSettingsParser.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/core/settings/XmlSettingsParser.java Mon May 10 20:07:08 2010
@@ -299,6 +299,8 @@ public class XmlSettingsParser extends D
         }
         String up2d = (String) attributes.get("checkUpToDate");
         if (up2d != null) {
+            Message.deprecated("'checkUpToDate' is deprecated, "
+                + "use the 'overwriteMode' on the 'ivy:retrieve' task instead (" + settings + ")");
             ivy.setCheckUpToDate(Boolean.valueOf(up2d).booleanValue());
         }
         String resolutionDir = (String) attributes.get("resolutionCacheDir");
@@ -349,7 +351,7 @@ public class XmlSettingsParser extends D
         String up2d = (String) attributes.get("checkUpToDate");
         if (up2d != null) {
             Message.deprecated("'checkUpToDate' is deprecated, "
-                + "use 'caches[@checkUpToDate]' instead (" + settings + ")");
+                + "use the 'overwriteMode' on the 'ivy:retrieve' task instead (" + settings + ")");
             ivy.setCheckUpToDate(Boolean.valueOf(up2d).booleanValue());
         }
         String useRemoteConfig = (String) attributes.get("useRemoteConfig");

Modified: ant/ivy/core/trunk/test/java/org/apache/ivy/core/retrieve/RetrieveTest.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/test/java/org/apache/ivy/core/retrieve/RetrieveTest.java?rev=942885&r1=942884&r2=942885&view=diff
==============================================================================
--- ant/ivy/core/trunk/test/java/org/apache/ivy/core/retrieve/RetrieveTest.java (original)
+++ ant/ivy/core/trunk/test/java/org/apache/ivy/core/retrieve/RetrieveTest.java Mon May 10 20:07:08 2010
@@ -180,8 +180,7 @@ public class RetrieveTest extends TestCa
             "mod1.2", "jar", "jar", "default")).getCanonicalFile();
         file.getParentFile().mkdirs();
         file.createNewFile();
-        ivy.getSettings().setCheckUpToDate(false);
-        ivy.retrieve(md.getModuleRevisionId(), pattern, getRetrieveOptions());
+        ivy.retrieve(md.getModuleRevisionId(), pattern, getRetrieveOptions().setOverwriteMode("always"));
         assertEquals(
             new File("test/repositories/1/org1/mod1.2/jars/mod1.2-2.0.jar").lastModified(), 
             file.lastModified());