Author: maartenc
Date: Tue Aug 18 10:14:50 2009
New Revision: 805346

URL: http://svn.apache.org/viewvc?rev=805346&view=rev
Log:
FIX: Fixed name snapshots are not updated even if they are marked as changing 
and the publication date is changed in repo (IVY-938)

Modified:
    ant/ivy/core/trunk/CHANGES.txt
    
ant/ivy/core/trunk/src/java/org/apache/ivy/core/cache/DefaultRepositoryCacheManager.java
    
ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/BasicResolver.java

Modified: ant/ivy/core/trunk/CHANGES.txt
URL: 
http://svn.apache.org/viewvc/ant/ivy/core/trunk/CHANGES.txt?rev=805346&r1=805345&r2=805346&view=diff
==============================================================================
--- ant/ivy/core/trunk/CHANGES.txt (original)
+++ ant/ivy/core/trunk/CHANGES.txt Tue Aug 18 10:14:50 2009
@@ -95,6 +95,7 @@
 - FIX: Excessive hits to missing URLs uses up all ports on Windows (IVY-1105)
 - FIX: ivy parse exception when using <publications defaultconf> (IVY-1102)
 - FIX: Change org.apache to commons-cli at jdbc-example (IVY-1109)
+- FIX: Fixed name snapshots are not updated even if they are marked as 
changing and the publication date is changed in repo (IVY-938)
 
    2.1.0-rc2
 =====================================

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=805346&r1=805345&r2=805346&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
 Tue Aug 18 10:14:50 2009
@@ -874,52 +874,75 @@
             DependencyResolver resolver, final ResolvedResource mdRef, 
DependencyDescriptor dd, 
             Artifact moduleArtifact, ResourceDownloader downloader, 
CacheMetadataOptions options) 
             throws ParseException {
-        ModuleDescriptorParser parser = ModuleDescriptorParserRegistry
-            .getInstance().getParser(mdRef.getResource());
         Date cachedPublicationDate = null;
         ArtifactDownloadReport report;
         ModuleRevisionId mrid = moduleArtifact.getModuleRevisionId();
-        Artifact originalMetadataArtifact = 
getOriginalMetadataArtifact(moduleArtifact);
         if (!lockMetadataArtifact(mrid)) {
             Message.error("impossible to acquire lock for " + mrid);
             return null;
         }
-        BackupResourceDownloader backupDownloader = new 
BackupResourceDownloader(downloader);
-        try {
-            // now let's see if we can find it in cache and if it is up to date
-            ResolvedModuleRevision rmr = doFindModuleInCache(mrid, options, 
null);
-            if (rmr != null) {
-                if (rmr.getDescriptor().isDefault() && rmr.getResolver() != 
resolver) {
-                    Message.verbose("\t" + getName() + ": found revision in 
cache: " + mrid
-                        + " (resolved by " + rmr.getResolver().getName()
-                        + "): but it's a default one, maybe we can find a 
better one");
-                } else {
-                    if (!isCheckmodified(dd, mrid, options) && !isChanging(dd, 
mrid, options)) {
-                        Message.verbose("\t" + getName() + ": revision in 
cache: " + mrid);
-                        rmr.getReport().setSearched(true);
-                        return rmr;
+        
+        if (!moduleArtifact.isMetadata()) {
+            // the descriptor we are trying to cache is a default one, not 
much to do
+            // just make sure the old artifacts are deleted...
+            if (isChanging(dd, mrid, options)) {
+                long repoLastModified = mdRef.getLastModified();
+    
+                Artifact transformedArtifact = NameSpaceHelper.transform(
+                    moduleArtifact, 
options.getNamespace().getToSystemTransformer());
+                ArtifactOrigin origin = 
getSavedArtifactOrigin(transformedArtifact);
+                File artFile = getArchiveFileInCache(transformedArtifact, 
origin, false);
+                if (artFile.exists() && repoLastModified > 
artFile.lastModified()) {
+                    // artifacts have changed, they should be downloaded again
+                    Message.verbose(mrid + " has changed: deleting old 
artifacts");
+                    Message.debug("deleting " + artFile);
+                    if (!artFile.delete()) {
+                        Message.error("Couldn't delete outdated artifact from 
cache: " + artFile);
+                        return null;
                     }
-                    long repLastModified = mdRef.getLastModified();
-                    long cacheLastModified = 
rmr.getDescriptor().getLastModified();
-                    if (!rmr.getDescriptor().isDefault() && repLastModified <= 
cacheLastModified) {
-                        Message.verbose("\t" + getName() + ": revision in 
cache (not updated): "
-                            + mrid);
-                        rmr.getReport().setSearched(true);
-                        return rmr;
-                    } else {
-                        Message.verbose("\t" + getName() + ": revision in 
cache is not up to date: "
-                            + mrid);
-                        if (isChanging(dd, mrid, options)) {
-                            // ivy file has been updated, we should see if it 
has a new publication
-                            // date to see if a new download is required (in 
case the dependency is
-                            // a changing one)
-                            cachedPublicationDate = 
-                                
rmr.getDescriptor().getResolvedPublicationDate();
-                        }
+                    removeSavedArtifactOrigin(transformedArtifact);
+                }
+            }
+            return null;
+        }
+        
+        // now let's see if we can find it in cache and if it is up to date
+        ResolvedModuleRevision rmr = doFindModuleInCache(mrid, options, null);
+        if (rmr != null) {
+            if (rmr.getDescriptor().isDefault() && rmr.getResolver() != 
resolver) {
+                Message.verbose("\t" + getName() + ": found revision in cache: 
" + mrid
+                    + " (resolved by " + rmr.getResolver().getName()
+                    + "): but it's a default one, maybe we can find a better 
one");
+            } else {
+                if (!isCheckmodified(dd, mrid, options) && !isChanging(dd, 
mrid, options)) {
+                    Message.verbose("\t" + getName() + ": revision in cache: " 
+ mrid);
+                    rmr.getReport().setSearched(true);
+                    return rmr;
+                }
+                long repLastModified = mdRef.getLastModified();
+                long cacheLastModified = rmr.getDescriptor().getLastModified();
+                if (!rmr.getDescriptor().isDefault() && repLastModified <= 
cacheLastModified) {
+                    Message.verbose("\t" + getName() + ": revision in cache 
(not updated): "
+                        + mrid);
+                    rmr.getReport().setSearched(true);
+                    return rmr;
+                } else {
+                    Message.verbose("\t" + getName() + ": revision in cache is 
not up to date: "
+                        + mrid);
+                    if (isChanging(dd, mrid, options)) {
+                        // ivy file has been updated, we should see if it has 
a new publication
+                        // date to see if a new download is required (in case 
the dependency is
+                        // a changing one)
+                        cachedPublicationDate = 
+                            rmr.getDescriptor().getResolvedPublicationDate();
                     }
                 }
             }
-
+        }
+        
+        BackupResourceDownloader backupDownloader = new 
BackupResourceDownloader(downloader);
+        try {
+            Artifact originalMetadataArtifact = 
getOriginalMetadataArtifact(moduleArtifact);
             // now download module descriptor and parse it
             report = download(
                 originalMetadataArtifact, 
@@ -939,6 +962,8 @@
             }
 
             try {
+                ModuleDescriptorParser parser = ModuleDescriptorParserRegistry
+                        .getInstance().getParser(mdRef.getResource());
                 ModuleDescriptor md = getStaledMd(parser, options, 
report.getLocalFile()); 
                 if (md == null) {
                     throw new IllegalStateException(

Modified: 
ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/BasicResolver.java
URL: 
http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/BasicResolver.java?rev=805346&r1=805345&r2=805346&view=diff
==============================================================================
--- 
ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/BasicResolver.java 
(original)
+++ 
ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/BasicResolver.java 
Tue Aug 18 10:14:50 2009
@@ -254,6 +254,8 @@
                     madr.setDownloadStatus(DownloadStatus.NO);
                     madr.setSearched(true);
                     rmr = new ResolvedModuleRevision(this, this, systemMd, 
madr, isForce());
+                    getRepositoryCacheManager().cacheModuleDescriptor(this, 
artifactRef, toSystem(dd), 
+                            systemMd.getAllArtifacts()[0], null, 
getCacheOptions(data));
                 }
             } else {
                 if (ivyRef instanceof MDResolvedResource) {


Reply via email to