You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ivy-commits@incubator.apache.org by xa...@apache.org on 2007/06/05 12:02:43 UTC

svn commit: r544459 [22/36] - in /incubator/ivy/core/trunk: src/java/org/apache/ivy/ src/java/org/apache/ivy/ant/ src/java/org/apache/ivy/core/ src/java/org/apache/ivy/core/cache/ src/java/org/apache/ivy/core/check/ src/java/org/apache/ivy/core/deliver...

Modified: incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/BasicResolver.java
URL: http://svn.apache.org/viewvc/incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/BasicResolver.java?view=diff&rev=544459&r1=544458&r2=544459
==============================================================================
--- incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/BasicResolver.java (original)
+++ incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/BasicResolver.java Tue Jun  5 05:02:27 2007
@@ -74,7 +74,6 @@
 import org.apache.ivy.util.HostUtil;
 import org.apache.ivy.util.Message;
 
-
 /**
  *
  */
@@ -82,12 +81,16 @@
     public static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyyMMddHHmmss");
 
     protected String _workspaceName;
+
     /**
-     * True if the files resolved are dependent of the environment from which they have been resolved, false otherwise. In general, relative paths are dependent of the environment, and absolute paths including machine reference are not. 
+     * True if the files resolved are dependent of the environment from which they have been
+     * resolved, false otherwise. In general, relative paths are dependent of the environment, and
+     * absolute paths including machine reference are not.
      */
     private boolean _envDependent = true;
 
     private List _ivyattempts = new ArrayList();
+
     private Map _artattempts = new HashMap();
 
     private Boolean _checkmodified = null;
@@ -95,10 +98,12 @@
     private boolean _checkconsistency = true;
 
     private boolean _allownomd = true;
-    
+
     private String _checksums = null;
 
-	private URLRepository _extartifactrep = new URLRepository(); // used only to download external artifacts
+    private URLRepository _extartifactrep = new URLRepository(); // used only to download
+
+    // external artifacts
 
     public BasicResolver() {
         _workspaceName = HostUtil.getLocalHostName();
@@ -122,6 +127,7 @@
 
     /**
      * True if this resolver should check lastmodified date to know if ivy files are up to date.
+     * 
      * @return
      */
     public boolean isCheckmodified() {
@@ -136,253 +142,281 @@
             return _checkmodified.booleanValue();
         }
     }
-    
 
     public void setCheckmodified(boolean check) {
         _checkmodified = Boolean.valueOf(check);
     }
-    
-    public ResolvedModuleRevision getDependency(DependencyDescriptor dd, ResolveData data) throws ParseException {
-    	IvyContext.getContext().pushResolver(this);
-    	try {
-    		DependencyDescriptor systemDd = dd;
-    		dd = fromSystem(dd);
-
-    		clearIvyAttempts();
-    		clearArtifactAttempts();
-    		boolean downloaded = false;
-    		boolean searched = false;
-    		ModuleRevisionId mrid = dd.getDependencyRevisionId();
-    		// check revision
-    		int index = mrid.getRevision().indexOf("@");
-    		if (index != -1 && !mrid.getRevision().substring(index+1).equals(_workspaceName)) {
-    			Message.verbose("\t"+getName()+": unhandled revision => "+mrid.getRevision());
-    			return null;
-    		}
-
-    		boolean isDynamic = getSettings().getVersionMatcher().isDynamic(mrid);
-    		if (isDynamic && !acceptLatest()) {
-    			Message.error("dynamic revisions not handled by "+getClass().getName()+". impossible to resolve "+mrid);
-    			return null;
-    		}
-
-    		boolean isChangingRevision = getChangingMatcher().matches(mrid.getRevision());        
-    		boolean isChangingDependency = isChangingRevision || dd.isChanging();
-
-    		// if we do not have to check modified and if the revision is exact and not changing,  
-    		// we first search for it in cache
-    		ResolvedModuleRevision cachedRmr = null;
-    		boolean checkedCache = false;
-    		if (!isDynamic && !isCheckmodified() && !isChangingDependency) {
-    			cachedRmr = findModuleInCache(data, mrid);
-    			checkedCache = true;
-    			if (cachedRmr != null) {
-    				if (cachedRmr.getDescriptor().isDefault() && cachedRmr.getResolver() != this) {
-    					Message.verbose("\t"+getName()+": found revision in cache: "+mrid+" (resolved by "+cachedRmr.getResolver().getName()+"): but it's a default one, maybe we can find a better one");
-    				} else {
-    					Message.verbose("\t"+getName()+": revision in cache: "+mrid);
-    					return toSystem(cachedRmr);
-    				}
-    			}
-    		}
-    		checkInterrupted();
-    		URL cachedIvyURL = null;
-    		ResolvedResource ivyRef = findIvyFileRef(dd, data);
-    		checkInterrupted();
-    		searched = true;
-
-    		// get module descriptor
-    		ModuleDescriptorParser parser;
-    		ModuleDescriptor md;
-    		ModuleDescriptor systemMd = null;
-    		if (ivyRef == null) {
-    			if (!isAllownomd()) {
-    				Message.verbose("\t"+getName()+": no ivy file found for "+mrid);
-    				return null;
-    			}
-    			parser = XmlModuleDescriptorParser.getInstance();
-    			md = DefaultModuleDescriptor.newDefaultInstance(mrid, dd.getAllDependencyArtifacts());
-    			ResolvedResource artifactRef = findFirstArtifactRef(md, dd, data);
-    			checkInterrupted();
-    			if (artifactRef == null) {
-    				Message.verbose("\t"+getName()+": no ivy file nor artifact found for "+mrid);
-    				String[] conf = md.getConfigurationsNames();
-    				for (int i = 0; i < conf.length; i++) {
-    					Artifact[] artifacts = md.getArtifacts(conf[i]);
-    					for (int j = 0; j < artifacts.length; j++) {
-    					}
-    				}
-    				if (!checkedCache) {
-    					cachedRmr = findModuleInCache(data, mrid);
-    				}
-    				if (cachedRmr != null) {
-    					Message.verbose("\t"+getName()+": revision in cache: "+mrid);
-    					return toSystem(cachedRmr);                    
-    				}
-    				return null;
-    			} else {
-    				long lastModified = artifactRef.getLastModified();
-    				if (lastModified != 0 && md instanceof DefaultModuleDescriptor) {
-    					((DefaultModuleDescriptor) md).setLastModified(lastModified);
-    				}
-    				Message.verbose("\t"+getName()+": no ivy file found for "+mrid+": using default data");            
-    				if (isDynamic) {
-    					md.setResolvedModuleRevisionId(ModuleRevisionId.newInstance(mrid, artifactRef.getRevision()));
-    				}
-    			}
-    		} else {
-    			ResolvedModuleRevision rmr = null;
-    			if (ivyRef instanceof MDResolvedResource) {
-    				rmr = ((MDResolvedResource)ivyRef).getResolvedModuleRevision();
-    			}
-    			if (rmr == null) {
-    				rmr = parse(ivyRef, dd, data);
-    				if (rmr == null) {
-    					return null;
-    				}
-    			}
-    			if (!rmr.isDownloaded()) {
-    				return toSystem(rmr);
-    			} else {
-    				md = rmr.getDescriptor();
-    				parser = ModuleDescriptorParserRegistry.getInstance().getParser(ivyRef.getResource());
-    				cachedIvyURL = rmr.getLocalMDUrl();
-
-    				// check descriptor data is in sync with resource revision and names
-    				systemMd = toSystem(md);
-    				if (_checkconsistency) {
-    					checkDescriptorConsistency(mrid, md, ivyRef);
-    					checkDescriptorConsistency(systemDd.getDependencyRevisionId(), systemMd, ivyRef);
-    				} else {
-    					if (md instanceof DefaultModuleDescriptor) {
-    						String revision = getRevision(ivyRef, mrid, md);
-    						((DefaultModuleDescriptor)md).setModuleRevisionId(ModuleRevisionId.newInstance(mrid, revision));
-    					} else {
-    						Message.warn("consistency disabled with instance of non DefaultModuleDescriptor... module info can't be updated, so consistency check will be done");
-    						checkDescriptorConsistency(mrid, md, ivyRef);
-    						checkDescriptorConsistency(systemDd.getDependencyRevisionId(), systemMd, ivyRef);
-    					}
-    				}
-    			}
-    		}
-
-    		if (systemMd == null) {
-    			systemMd = toSystem(md);
-    		}
-
-    		// resolve revision
-    		ModuleRevisionId resolvedMrid = mrid;
-    		if (isDynamic) {
-    			resolvedMrid = md.getResolvedModuleRevisionId();
-    			if (resolvedMrid.getRevision() == null || resolvedMrid.getRevision().length() == 0) {
-    				if (ivyRef.getRevision() == null || ivyRef.getRevision().length() == 0) {
-    					resolvedMrid = ModuleRevisionId.newInstance(resolvedMrid, "working@"+getName());
-    				} else {
-    					resolvedMrid = ModuleRevisionId.newInstance(resolvedMrid, ivyRef.getRevision());
-    				}
-    			}
-    			Message.verbose("\t\t["+resolvedMrid.getRevision()+"] "+mrid.getModuleId());
-    		}
-    		md.setResolvedModuleRevisionId(resolvedMrid);
-    		systemMd.setResolvedModuleRevisionId(toSystem(resolvedMrid)); // keep system md in sync with md
-
-    		// check module descriptor revision
-    		if (!getSettings().getVersionMatcher().accept(mrid, md)) {
-    			Message.info("\t"+getName()+": unacceptable revision => was="+md.getModuleRevisionId().getRevision()+" required="+mrid.getRevision());
-    			return null;
-    		}
-
-
-    		// resolve and check publication date
-    		if (data.getDate() != null) {
-    			long pubDate = getPublicationDate(md, dd, data);
-    			if (pubDate > data.getDate().getTime()) {
-    				Message.info("\t"+getName()+": unacceptable publication date => was="+new Date(pubDate)+" required="+data.getDate());
-    				return null;
-    			} else if (pubDate == -1) {
-    				Message.info("\t"+getName()+": impossible to guess publication date: artifact missing for "+mrid);
-    				return null;
-    			}
-    			md.setResolvedPublicationDate(new Date(pubDate));
-    			systemMd.setResolvedPublicationDate(new Date(pubDate)); // keep system md in sync with md
-    		}
-
-    		try {
-    			File ivyFile = data.getCacheManager().getIvyFileInCache(systemMd.getResolvedModuleRevisionId());
-    			if (ivyRef == null) {
-    				// a basic ivy file is written containing default data
-    				XmlModuleDescriptorWriter.write(systemMd, ivyFile);
-    			} else {
-    				if (md instanceof DefaultModuleDescriptor) {
-    					DefaultModuleDescriptor dmd = (DefaultModuleDescriptor)md;
-    					if (data.getSettings().logNotConvertedExclusionRule() && dmd.isNamespaceUseful()) {
-    						Message.warn("the module descriptor "+ivyRef.getResource()+" has information which can't be converted into the system namespace. It will require the availability of the namespace '"+getNamespace().getName()+"' to be fully usable.");
-    					}
-    				}
-    				// copy and update ivy file from source to cache
-    				parser.toIvyFile(cachedIvyURL.openStream(), ivyRef.getResource(), ivyFile, systemMd);
-    				long repLastModified = ivyRef.getLastModified();
-    				if (repLastModified > 0) {
-    					ivyFile.setLastModified(repLastModified);
-    				}
-    			}
-    		} catch (Exception e) {
-    			if (ivyRef == null) {
-    				Message.warn("impossible to create ivy file in cache for module : " + resolvedMrid);
-    			} else {
-    				e.printStackTrace();
-    				Message.warn("impossible to copy ivy file to cache : "+ivyRef.getResource());
-    			}
-    		}
-
-    		data.getCacheManager().saveResolver(systemMd, getName());
-    		data.getCacheManager().saveArtResolver(systemMd, getName());
-    		return new DefaultModuleRevision(this, this, systemMd, searched, downloaded, cachedIvyURL);
-    	} finally {
-    		IvyContext.getContext().popResolver();
-    	}
+
+    public ResolvedModuleRevision getDependency(DependencyDescriptor dd, ResolveData data)
+            throws ParseException {
+        IvyContext.getContext().pushResolver(this);
+        try {
+            DependencyDescriptor systemDd = dd;
+            dd = fromSystem(dd);
+
+            clearIvyAttempts();
+            clearArtifactAttempts();
+            boolean downloaded = false;
+            boolean searched = false;
+            ModuleRevisionId mrid = dd.getDependencyRevisionId();
+            // check revision
+            int index = mrid.getRevision().indexOf("@");
+            if (index != -1 && !mrid.getRevision().substring(index + 1).equals(_workspaceName)) {
+                Message.verbose("\t" + getName() + ": unhandled revision => " + mrid.getRevision());
+                return null;
+            }
+
+            boolean isDynamic = getSettings().getVersionMatcher().isDynamic(mrid);
+            if (isDynamic && !acceptLatest()) {
+                Message.error("dynamic revisions not handled by " + getClass().getName()
+                        + ". impossible to resolve " + mrid);
+                return null;
+            }
+
+            boolean isChangingRevision = getChangingMatcher().matches(mrid.getRevision());
+            boolean isChangingDependency = isChangingRevision || dd.isChanging();
+
+            // if we do not have to check modified and if the revision is exact and not changing,
+            // we first search for it in cache
+            ResolvedModuleRevision cachedRmr = null;
+            boolean checkedCache = false;
+            if (!isDynamic && !isCheckmodified() && !isChangingDependency) {
+                cachedRmr = findModuleInCache(data, mrid);
+                checkedCache = true;
+                if (cachedRmr != null) {
+                    if (cachedRmr.getDescriptor().isDefault() && cachedRmr.getResolver() != this) {
+                        Message.verbose("\t" + getName() + ": found revision in cache: " + mrid
+                                + " (resolved by " + cachedRmr.getResolver().getName()
+                                + "): but it's a default one, maybe we can find a better one");
+                    } else {
+                        Message.verbose("\t" + getName() + ": revision in cache: " + mrid);
+                        return toSystem(cachedRmr);
+                    }
+                }
+            }
+            checkInterrupted();
+            URL cachedIvyURL = null;
+            ResolvedResource ivyRef = findIvyFileRef(dd, data);
+            checkInterrupted();
+            searched = true;
+
+            // get module descriptor
+            ModuleDescriptorParser parser;
+            ModuleDescriptor md;
+            ModuleDescriptor systemMd = null;
+            if (ivyRef == null) {
+                if (!isAllownomd()) {
+                    Message.verbose("\t" + getName() + ": no ivy file found for " + mrid);
+                    return null;
+                }
+                parser = XmlModuleDescriptorParser.getInstance();
+                md = DefaultModuleDescriptor.newDefaultInstance(mrid, dd
+                        .getAllDependencyArtifacts());
+                ResolvedResource artifactRef = findFirstArtifactRef(md, dd, data);
+                checkInterrupted();
+                if (artifactRef == null) {
+                    Message.verbose("\t" + getName() + ": no ivy file nor artifact found for "
+                            + mrid);
+                    String[] conf = md.getConfigurationsNames();
+                    for (int i = 0; i < conf.length; i++) {
+                        Artifact[] artifacts = md.getArtifacts(conf[i]);
+                        for (int j = 0; j < artifacts.length; j++) {
+                        }
+                    }
+                    if (!checkedCache) {
+                        cachedRmr = findModuleInCache(data, mrid);
+                    }
+                    if (cachedRmr != null) {
+                        Message.verbose("\t" + getName() + ": revision in cache: " + mrid);
+                        return toSystem(cachedRmr);
+                    }
+                    return null;
+                } else {
+                    long lastModified = artifactRef.getLastModified();
+                    if (lastModified != 0 && md instanceof DefaultModuleDescriptor) {
+                        ((DefaultModuleDescriptor) md).setLastModified(lastModified);
+                    }
+                    Message.verbose("\t" + getName() + ": no ivy file found for " + mrid
+                            + ": using default data");
+                    if (isDynamic) {
+                        md.setResolvedModuleRevisionId(ModuleRevisionId.newInstance(mrid,
+                            artifactRef.getRevision()));
+                    }
+                }
+            } else {
+                ResolvedModuleRevision rmr = null;
+                if (ivyRef instanceof MDResolvedResource) {
+                    rmr = ((MDResolvedResource) ivyRef).getResolvedModuleRevision();
+                }
+                if (rmr == null) {
+                    rmr = parse(ivyRef, dd, data);
+                    if (rmr == null) {
+                        return null;
+                    }
+                }
+                if (!rmr.isDownloaded()) {
+                    return toSystem(rmr);
+                } else {
+                    md = rmr.getDescriptor();
+                    parser = ModuleDescriptorParserRegistry.getInstance().getParser(
+                        ivyRef.getResource());
+                    cachedIvyURL = rmr.getLocalMDUrl();
+
+                    // check descriptor data is in sync with resource revision and names
+                    systemMd = toSystem(md);
+                    if (_checkconsistency) {
+                        checkDescriptorConsistency(mrid, md, ivyRef);
+                        checkDescriptorConsistency(systemDd.getDependencyRevisionId(), systemMd,
+                            ivyRef);
+                    } else {
+                        if (md instanceof DefaultModuleDescriptor) {
+                            String revision = getRevision(ivyRef, mrid, md);
+                            ((DefaultModuleDescriptor) md).setModuleRevisionId(ModuleRevisionId
+                                    .newInstance(mrid, revision));
+                        } else {
+                            Message
+                                    .warn("consistency disabled with instance of non DefaultModuleDescriptor... module info can't be updated, so consistency check will be done");
+                            checkDescriptorConsistency(mrid, md, ivyRef);
+                            checkDescriptorConsistency(systemDd.getDependencyRevisionId(),
+                                systemMd, ivyRef);
+                        }
+                    }
+                }
+            }
+
+            if (systemMd == null) {
+                systemMd = toSystem(md);
+            }
+
+            // resolve revision
+            ModuleRevisionId resolvedMrid = mrid;
+            if (isDynamic) {
+                resolvedMrid = md.getResolvedModuleRevisionId();
+                if (resolvedMrid.getRevision() == null || resolvedMrid.getRevision().length() == 0) {
+                    if (ivyRef.getRevision() == null || ivyRef.getRevision().length() == 0) {
+                        resolvedMrid = ModuleRevisionId.newInstance(resolvedMrid, "working@"
+                                + getName());
+                    } else {
+                        resolvedMrid = ModuleRevisionId.newInstance(resolvedMrid, ivyRef
+                                .getRevision());
+                    }
+                }
+                Message.verbose("\t\t[" + resolvedMrid.getRevision() + "] " + mrid.getModuleId());
+            }
+            md.setResolvedModuleRevisionId(resolvedMrid);
+            systemMd.setResolvedModuleRevisionId(toSystem(resolvedMrid)); // keep system md in
+            // sync with md
+
+            // check module descriptor revision
+            if (!getSettings().getVersionMatcher().accept(mrid, md)) {
+                Message.info("\t" + getName() + ": unacceptable revision => was="
+                        + md.getModuleRevisionId().getRevision() + " required="
+                        + mrid.getRevision());
+                return null;
+            }
+
+            // resolve and check publication date
+            if (data.getDate() != null) {
+                long pubDate = getPublicationDate(md, dd, data);
+                if (pubDate > data.getDate().getTime()) {
+                    Message.info("\t" + getName() + ": unacceptable publication date => was="
+                            + new Date(pubDate) + " required=" + data.getDate());
+                    return null;
+                } else if (pubDate == -1) {
+                    Message.info("\t" + getName()
+                            + ": impossible to guess publication date: artifact missing for "
+                            + mrid);
+                    return null;
+                }
+                md.setResolvedPublicationDate(new Date(pubDate));
+                systemMd.setResolvedPublicationDate(new Date(pubDate)); // keep system md in sync
+                // with md
+            }
+
+            try {
+                File ivyFile = data.getCacheManager().getIvyFileInCache(
+                    systemMd.getResolvedModuleRevisionId());
+                if (ivyRef == null) {
+                    // a basic ivy file is written containing default data
+                    XmlModuleDescriptorWriter.write(systemMd, ivyFile);
+                } else {
+                    if (md instanceof DefaultModuleDescriptor) {
+                        DefaultModuleDescriptor dmd = (DefaultModuleDescriptor) md;
+                        if (data.getSettings().logNotConvertedExclusionRule()
+                                && dmd.isNamespaceUseful()) {
+                            Message
+                                    .warn("the module descriptor "
+                                            + ivyRef.getResource()
+                                            + " has information which can't be converted into the system namespace. It will require the availability of the namespace '"
+                                            + getNamespace().getName() + "' to be fully usable.");
+                        }
+                    }
+                    // copy and update ivy file from source to cache
+                    parser.toIvyFile(cachedIvyURL.openStream(), ivyRef.getResource(), ivyFile,
+                        systemMd);
+                    long repLastModified = ivyRef.getLastModified();
+                    if (repLastModified > 0) {
+                        ivyFile.setLastModified(repLastModified);
+                    }
+                }
+            } catch (Exception e) {
+                if (ivyRef == null) {
+                    Message.warn("impossible to create ivy file in cache for module : "
+                            + resolvedMrid);
+                } else {
+                    e.printStackTrace();
+                    Message.warn("impossible to copy ivy file to cache : " + ivyRef.getResource());
+                }
+            }
+
+            data.getCacheManager().saveResolver(systemMd, getName());
+            data.getCacheManager().saveArtResolver(systemMd, getName());
+            return new DefaultModuleRevision(this, this, systemMd, searched, downloaded,
+                    cachedIvyURL);
+        } finally {
+            IvyContext.getContext().popResolver();
+        }
     }
 
-    private String getRevision(ResolvedResource ivyRef, ModuleRevisionId askedMrid, ModuleDescriptor md) throws ParseException {
+    private String getRevision(ResolvedResource ivyRef, ModuleRevisionId askedMrid,
+            ModuleDescriptor md) throws ParseException {
         String revision = ivyRef.getRevision();
         if (revision == null) {
-            Message.debug("no revision found in reference for "+askedMrid);
+            Message.debug("no revision found in reference for " + askedMrid);
             if (getSettings().getVersionMatcher().isDynamic(askedMrid)) {
                 if (md.getModuleRevisionId().getRevision() == null) {
-                    return "working@"+getName();
+                    return "working@" + getName();
                 } else {
-                    Message.debug("using  "+askedMrid);
+                    Message.debug("using  " + askedMrid);
                     revision = md.getModuleRevisionId().getRevision();
                 }
             } else {
-                Message.debug("using  "+askedMrid);
+                Message.debug("using  " + askedMrid);
                 revision = askedMrid.getRevision();
             }
         }
         return revision;
     }
-    
-    public ResolvedModuleRevision parse(
-    		ResolvedResource ivyRef, 
-    		DependencyDescriptor dd, 
-    		ResolveData data
-    		) throws ParseException {
-    	
-    	ModuleRevisionId mrid = dd.getDependencyRevisionId();
-    	ModuleDescriptorParser parser = ModuleDescriptorParserRegistry.getInstance().getParser(ivyRef.getResource());
+
+    public ResolvedModuleRevision parse(ResolvedResource ivyRef, DependencyDescriptor dd,
+            ResolveData data) throws ParseException {
+
+        ModuleRevisionId mrid = dd.getDependencyRevisionId();
+        ModuleDescriptorParser parser = ModuleDescriptorParserRegistry.getInstance().getParser(
+            ivyRef.getResource());
         if (parser == null) {
-            Message.warn("no module descriptor parser available for "+ivyRef.getResource());
+            Message.warn("no module descriptor parser available for " + ivyRef.getResource());
             return null;
         }
-        Message.verbose("\t"+getName()+": found md file for "+mrid);
-        Message.verbose("\t\t=> "+ivyRef);
-        Message.debug("\tparser = "+parser);
+        Message.verbose("\t" + getName() + ": found md file for " + mrid);
+        Message.verbose("\t\t=> " + ivyRef);
+        Message.debug("\tparser = " + parser);
 
-        boolean isChangingRevision = getChangingMatcher().matches(mrid.getRevision());        
+        boolean isChangingRevision = getChangingMatcher().matches(mrid.getRevision());
         boolean isChangingDependency = isChangingRevision || dd.isChanging();
-    	Date cachedPublicationDate = null;
+        Date cachedPublicationDate = null;
         ModuleRevisionId resolvedMrid = mrid;
-        
+
         // first check if this dependency has not yet been resolved
         if (getSettings().getVersionMatcher().isDynamic(mrid)) {
             resolvedMrid = ModuleRevisionId.newInstance(mrid, ivyRef.getRevision());
@@ -390,76 +424,90 @@
             if (node != null && node.getModuleRevision() != null) {
                 // this revision has already be resolved : return it
                 if (node.getDescriptor() != null && node.getDescriptor().isDefault()) {
-                    Message.verbose("\t"+getName()+": found already resolved revision: "+resolvedMrid+": but it's a default one, maybe we can find a better one");
+                    Message.verbose("\t" + getName() + ": found already resolved revision: "
+                            + resolvedMrid
+                            + ": but it's a default one, maybe we can find a better one");
                 } else {
-                    Message.verbose("\t"+getName()+": revision already resolved: "+resolvedMrid);
+                    Message.verbose("\t" + getName() + ": revision already resolved: "
+                            + resolvedMrid);
                     return searchedRmr(node.getModuleRevision());
                 }
             }
         }
-        
+
         // now let's see if we can find it in cache and if it is up to date
         ResolvedModuleRevision rmr = findModuleInCache(data, resolvedMrid);
         if (rmr != null) {
             if (rmr.getDescriptor().isDefault() && rmr.getResolver() != this) {
-                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");
+                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() && !isChangingDependency) {
-                    Message.verbose("\t"+getName()+": revision in cache: "+mrid);
+                    Message.verbose("\t" + getName() + ": revision in cache: " + mrid);
                     return searchedRmr(rmr);
                 }
                 long repLastModified = ivyRef.getLastModified();
-                long cacheLastModified = rmr.getDescriptor().getLastModified(); 
+                long cacheLastModified = rmr.getDescriptor().getLastModified();
                 if (!rmr.getDescriptor().isDefault() && repLastModified <= cacheLastModified) {
-                    Message.verbose("\t"+getName()+": revision in cache (not updated): "+resolvedMrid);
+                    Message.verbose("\t" + getName() + ": revision in cache (not updated): "
+                            + resolvedMrid);
                     return searchedRmr(rmr);
                 } else {
-                    Message.verbose("\t"+getName()+": revision in cache is not up to date: "+resolvedMrid);
+                    Message.verbose("\t" + getName() + ": revision in cache is not up to date: "
+                            + resolvedMrid);
                     if (isChangingDependency) {
                         // 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)
+                        // to see if a new download is required (in case the dependency is a
+                        // changing one)
                         cachedPublicationDate = rmr.getDescriptor().getResolvedPublicationDate();
                     }
                 }
             }
         }
-        
+
         // now download ivy file and parse it
         URL cachedIvyURL = null;
         File ivyTempFile = null;
         try {
             // first check if source file is not cache file itself
-            if (ResourceHelper.equals(ivyRef.getResource(), 
-                    data.getCacheManager().getIvyFileInCache(toSystem(resolvedMrid)))) {
-                Message.error("invalid configuration for resolver '"+getName()+"': pointing ivy files to ivy cache is forbidden !");
+            if (ResourceHelper.equals(ivyRef.getResource(), data.getCacheManager()
+                    .getIvyFileInCache(toSystem(resolvedMrid)))) {
+                Message.error("invalid configuration for resolver '" + getName()
+                        + "': pointing ivy files to ivy cache is forbidden !");
                 return null;
             }
-            
+
             // temp file is used to prevent downloading twice
-            ivyTempFile = File.createTempFile("ivy", "xml"); 
+            ivyTempFile = File.createTempFile("ivy", "xml");
             ivyTempFile.deleteOnExit();
-            Message.debug("\t"+getName()+": downloading "+ivyRef.getResource()+" to "+ivyTempFile);
+            Message.debug("\t" + getName() + ": downloading " + ivyRef.getResource() + " to "
+                    + ivyTempFile);
             getAndCheck(ivyRef.getResource(), ivyTempFile);
             try {
                 cachedIvyURL = ivyTempFile.toURL();
             } catch (MalformedURLException ex) {
-                Message.warn("malformed url exception for temp file: "+ivyTempFile+": "+ex.getMessage());
+                Message.warn("malformed url exception for temp file: " + ivyTempFile + ": "
+                        + ex.getMessage());
                 return null;
             }
         } catch (IOException ex) {
-            Message.warn("problem while downloading ivy file: "+ivyRef.getResource()+" to "+ivyTempFile+": "+ex.getMessage());
+            Message.warn("problem while downloading ivy file: " + ivyRef.getResource() + " to "
+                    + ivyTempFile + ": " + ex.getMessage());
             return null;
         }
         try {
-            ModuleDescriptor md = parser.parseDescriptor(data.getSettings(), cachedIvyURL, ivyRef.getResource(), doValidate(data));
-            Message.debug("\t"+getName()+": parsed downloaded md file for "+mrid+" parsed="+md.getModuleRevisionId());
-            
-            
+            ModuleDescriptor md = parser.parseDescriptor(data.getSettings(), cachedIvyURL, ivyRef
+                    .getResource(), doValidate(data));
+            Message.debug("\t" + getName() + ": parsed downloaded md file for " + mrid + " parsed="
+                    + md.getModuleRevisionId());
+
             // check if we should delete old artifacts
             boolean deleteOldArtifacts = false;
-            if (cachedPublicationDate != null && !cachedPublicationDate.equals(md.getResolvedPublicationDate())) {
+            if (cachedPublicationDate != null
+                    && !cachedPublicationDate.equals(md.getResolvedPublicationDate())) {
                 // artifacts have changed, they should be downloaded again
-                Message.verbose(dd+" has changed: deleting old artifacts");
+                Message.verbose(dd + " has changed: deleting old artifacts");
                 deleteOldArtifacts = true;
             }
             if (deleteOldArtifacts) {
@@ -468,86 +516,106 @@
                     Artifact[] arts = rmr.getDescriptor().getArtifacts(confs[i]);
                     for (int j = 0; j < arts.length; j++) {
                         Artifact transformedArtifact = toSystem(arts[j]);
-                        ArtifactOrigin origin = data.getCacheManager().getSavedArtifactOrigin(transformedArtifact);
-						File artFile = data.getCacheManager().getArchiveFileInCache(transformedArtifact, origin, false);
+                        ArtifactOrigin origin = data.getCacheManager().getSavedArtifactOrigin(
+                            transformedArtifact);
+                        File artFile = data.getCacheManager().getArchiveFileInCache(
+                            transformedArtifact, origin, false);
                         if (artFile.exists()) {
-                            Message.debug("deleting "+artFile);
+                            Message.debug("deleting " + artFile);
                             artFile.delete();
                         }
                         data.getCacheManager().removeSavedArtifactOrigin(transformedArtifact);
                     }
                 }
-            } else if (isChangingDependency){
-                Message.verbose(dd+" is changing, but has not changed: will trust cached artifacts if any");
-            } 
+            } else if (isChangingDependency) {
+                Message.verbose(dd
+                        + " is changing, but has not changed: will trust cached artifacts if any");
+            }
             return new DefaultModuleRevision(this, this, md, true, true, cachedIvyURL);
         } catch (IOException ex) {
-            Message.warn("io problem while parsing ivy file: "+ivyRef.getResource()+": "+ex.getMessage());
+            Message.warn("io problem while parsing ivy file: " + ivyRef.getResource() + ": "
+                    + ex.getMessage());
             return null;
         }
-    	
+
     }
 
     protected ResourceMDParser getRMDParser(final DependencyDescriptor dd, final ResolveData data) {
-		return new ResourceMDParser() {
-			public MDResolvedResource parse(Resource resource, String rev) {
-				try {
-					ResolvedModuleRevision rmr = BasicResolver.this.parse(new ResolvedResource(resource, rev), dd, data);
-					if (rmr == null) {
-						return null;
-					} else {
-						return new MDResolvedResource(resource, rev, rmr);
-					}
-				} catch (ParseException e) {
-					return null;
-				}
-			}
-			
-		};
-	}
+        return new ResourceMDParser() {
+            public MDResolvedResource parse(Resource resource, String rev) {
+                try {
+                    ResolvedModuleRevision rmr = BasicResolver.this.parse(new ResolvedResource(
+                            resource, rev), dd, data);
+                    if (rmr == null) {
+                        return null;
+                    } else {
+                        return new MDResolvedResource(resource, rev, rmr);
+                    }
+                } catch (ParseException e) {
+                    return null;
+                }
+            }
 
-    protected ResourceMDParser getDefaultRMDParser(final ModuleId mid) {
-    	return new ResourceMDParser() {
-			public MDResolvedResource parse(Resource resource, String rev) {
-				return new MDResolvedResource(resource, rev, new DefaultModuleRevision(BasicResolver.this, BasicResolver.this, DefaultModuleDescriptor.newDefaultInstance(new ModuleRevisionId(mid, rev)), false, false, null));
-			}
-    	};
-	}
+        };
+    }
 
+    protected ResourceMDParser getDefaultRMDParser(final ModuleId mid) {
+        return new ResourceMDParser() {
+            public MDResolvedResource parse(Resource resource, String rev) {
+                return new MDResolvedResource(resource, rev, new DefaultModuleRevision(
+                        BasicResolver.this, BasicResolver.this, DefaultModuleDescriptor
+                                .newDefaultInstance(new ModuleRevisionId(mid, rev)), false, false,
+                        null));
+            }
+        };
+    }
 
-//    private boolean isResolved(ResolveData data, ModuleRevisionId mrid) {
-//        IvyNode node = getSystemNode(data, mrid);
-//        return node != null && node.getModuleRevision() != null;
-//    }
-//
-    private void checkDescriptorConsistency(ModuleRevisionId mrid, ModuleDescriptor md, ResolvedResource ivyRef) throws ParseException {
+    // private boolean isResolved(ResolveData data, ModuleRevisionId mrid) {
+    // IvyNode node = getSystemNode(data, mrid);
+    // return node != null && node.getModuleRevision() != null;
+    // }
+    //
+    private void checkDescriptorConsistency(ModuleRevisionId mrid, ModuleDescriptor md,
+            ResolvedResource ivyRef) throws ParseException {
         boolean ok = true;
         StringBuffer errors = new StringBuffer();
         if (!mrid.getOrganisation().equals(md.getModuleRevisionId().getOrganisation())) {
-            Message.error("\t"+getName()+": bad organisation found in "+ivyRef.getResource()+": expected='"+mrid.getOrganisation()+"' found='"+md.getModuleRevisionId().getOrganisation()+"'");
-            errors.append("bad organisation: expected='"+mrid.getOrganisation()+"' found='"+md.getModuleRevisionId().getOrganisation()+"'; ");
+            Message.error("\t" + getName() + ": bad organisation found in " + ivyRef.getResource()
+                    + ": expected='" + mrid.getOrganisation() + "' found='"
+                    + md.getModuleRevisionId().getOrganisation() + "'");
+            errors.append("bad organisation: expected='" + mrid.getOrganisation() + "' found='"
+                    + md.getModuleRevisionId().getOrganisation() + "'; ");
             ok = false;
         }
         if (!mrid.getName().equals(md.getModuleRevisionId().getName())) {
-            Message.error("\t"+getName()+": bad module name found in "+ivyRef.getResource()+": expected='"+mrid.getName()+" found='"+md.getModuleRevisionId().getName()+"'");
-            errors.append("bad module name: expected='"+mrid.getName()+"' found='"+md.getModuleRevisionId().getName()+"'; ");
+            Message.error("\t" + getName() + ": bad module name found in " + ivyRef.getResource()
+                    + ": expected='" + mrid.getName() + " found='"
+                    + md.getModuleRevisionId().getName() + "'");
+            errors.append("bad module name: expected='" + mrid.getName() + "' found='"
+                    + md.getModuleRevisionId().getName() + "'; ");
             ok = false;
         }
         if (ivyRef.getRevision() != null && !ivyRef.getRevision().startsWith("working@")) {
-            ModuleRevisionId expectedMrid = ModuleRevisionId.newInstance(mrid, ivyRef.getRevision());
+            ModuleRevisionId expectedMrid = ModuleRevisionId
+                    .newInstance(mrid, ivyRef.getRevision());
             if (!getSettings().getVersionMatcher().accept(expectedMrid, md)) {
-                Message.error("\t"+getName()+": bad revision found in "+ivyRef.getResource()+": expected='"+ivyRef.getRevision()+" found='"+md.getModuleRevisionId().getRevision()+"'");
-                errors.append("bad revision: expected='"+ivyRef.getRevision()+"' found='"+md.getModuleRevisionId().getRevision()+"'; ");
+                Message.error("\t" + getName() + ": bad revision found in " + ivyRef.getResource()
+                        + ": expected='" + ivyRef.getRevision() + " found='"
+                        + md.getModuleRevisionId().getRevision() + "'");
+                errors.append("bad revision: expected='" + ivyRef.getRevision() + "' found='"
+                        + md.getModuleRevisionId().getRevision() + "'; ");
                 ok = false;
             }
         }
         if (!getSettings().getStatusManager().isStatus(md.getStatus())) {
-            Message.error("\t"+getName()+": bad status found in "+ivyRef.getResource()+": '"+md.getStatus()+"'");
-            errors.append("bad status: '"+md.getStatus()+"'; ");
+            Message.error("\t" + getName() + ": bad status found in " + ivyRef.getResource()
+                    + ": '" + md.getStatus() + "'");
+            errors.append("bad status: '" + md.getStatus() + "'; ");
             ok = false;
         }
         if (!ok) {
-            throw new ParseException("inconsistent module descriptor file found in '"+ivyRef.getResource()+"': "+errors, 0);
+            throw new ParseException("inconsistent module descriptor file found in '"
+                    + ivyRef.getResource() + "': " + errors, 0);
         }
     }
 
@@ -558,27 +626,27 @@
 
     protected ResolvedModuleRevision searchedRmr(final ResolvedModuleRevision rmr) {
         // delegate all to previously found except isSearched
-        return new ResolvedModuleRevision() {                    
+        return new ResolvedModuleRevision() {
             public boolean isSearched() {
                 return true;
             }
-        
+
             public boolean isDownloaded() {
                 return rmr.isDownloaded();
             }
-        
+
             public ModuleDescriptor getDescriptor() {
                 return rmr.getDescriptor();
             }
-        
+
             public Date getPublicationDate() {
                 return rmr.getPublicationDate();
             }
-        
+
             public ModuleRevisionId getId() {
                 return rmr.getId();
             }
-        
+
             public DependencyResolver getResolver() {
                 return rmr.getResolver();
             }
@@ -586,65 +654,67 @@
             public DependencyResolver getArtifactResolver() {
                 return rmr.getArtifactResolver();
             }
+
             public URL getLocalMDUrl() {
-            	return rmr.getLocalMDUrl();
+                return rmr.getLocalMDUrl();
             }
         };
     }
-    
+
     protected void logIvyAttempt(String attempt) {
         _ivyattempts.add(attempt);
-        Message.verbose("\t\ttried "+attempt);
+        Message.verbose("\t\ttried " + attempt);
     }
-    
+
     protected void logArtifactAttempt(Artifact art, String attempt) {
-        List attempts = (List)_artattempts.get(art);
+        List attempts = (List) _artattempts.get(art);
         if (attempts == null) {
             attempts = new ArrayList();
             _artattempts.put(art, attempts);
         }
         attempts.add(attempt);
-        Message.verbose("\t\ttried "+attempt);
+        Message.verbose("\t\ttried " + attempt);
     }
-    
+
     protected static void logAttempt(String attempt) {
-    	DependencyResolver resolver = IvyContext.getContext().getResolver();
-    	if (resolver instanceof BasicResolver) {
-    		Artifact currentArtifact = (Artifact) IvyContext.getContext().get(resolver.getName()+".artifact");
-    		if (currentArtifact != null) {
-    			((BasicResolver) resolver).logArtifactAttempt(currentArtifact, attempt);
-    		} else {
-    			((BasicResolver) resolver).logIvyAttempt(attempt);
-    		}
-    	}
+        DependencyResolver resolver = IvyContext.getContext().getResolver();
+        if (resolver instanceof BasicResolver) {
+            Artifact currentArtifact = (Artifact) IvyContext.getContext().get(
+                resolver.getName() + ".artifact");
+            if (currentArtifact != null) {
+                ((BasicResolver) resolver).logArtifactAttempt(currentArtifact, attempt);
+            } else {
+                ((BasicResolver) resolver).logIvyAttempt(attempt);
+            }
+        }
     }
-    
+
     public void reportFailure() {
-        Message.warn("==== "+getName()+": tried");
+        Message.warn("==== " + getName() + ": tried");
         for (ListIterator iter = _ivyattempts.listIterator(); iter.hasNext();) {
-            String m = (String)iter.next();
-            Message.warn("  "+m);
+            String m = (String) iter.next();
+            Message.warn("  " + m);
         }
         for (Iterator iter = _artattempts.keySet().iterator(); iter.hasNext();) {
-            Artifact art = (Artifact)iter.next();
-            List attempts = (List)_artattempts.get(art);
+            Artifact art = (Artifact) iter.next();
+            List attempts = (List) _artattempts.get(art);
             if (attempts != null) {
-                Message.warn("  -- artifact "+art+":");
+                Message.warn("  -- artifact " + art + ":");
                 for (ListIterator iterator = attempts.listIterator(); iterator.hasNext();) {
-                    String m = (String)iterator.next();
-                    Message.warn("  "+m);
+                    String m = (String) iterator.next();
+                    Message.warn("  " + m);
                 }
             }
         }
     }
 
     public void reportFailure(Artifact art) {
-        Message.warn("==== "+getName()+": tried");
-        List attempts = (List)_artattempts.get(art);
+        Message.warn("==== " + getName() + ": tried");
+        List attempts = (List) _artattempts.get(art);
         if (attempts != null) {
             for (ListIterator iter = attempts.listIterator(); iter.hasNext();) {
-                String m = (String)iter.next();
-                Message.warn("  "+m);
+                String m = (String) iter.next();
+                Message.warn("  " + m);
             }
         }
     }
@@ -654,117 +724,129 @@
     }
 
     public DownloadReport download(Artifact[] artifacts, DownloadOptions options) {
-    	IvyContext.getContext().pushResolver(this);
-    	try {
-    		CacheManager cacheManager = options.getCacheManager();
-    		EventManager eventManager = options.getEventManager();
-
-    		boolean useOrigin = options.isUseOrigin();
-
-    		clearArtifactAttempts();
-    		DownloadReport dr = new DownloadReport();
-    		for (int i = 0; i < artifacts.length; i++) {
-    			final ArtifactDownloadReport adr = new ArtifactDownloadReport(artifacts[i]);
-    			dr.addArtifactReport(adr);
-    			if (eventManager != null) {
-    				eventManager.fireIvyEvent(new NeedArtifactEvent(this, artifacts[i]));
-    			}
-    			ArtifactOrigin origin = cacheManager.getSavedArtifactOrigin(artifacts[i]);
-    			// if we can use origin file, we just ask ivy for the file in cache, and it will return 
-    			// the original one if possible. If we are not in useOrigin mode, we use the getArchivePath
-    			// method which always return a path in the actual cache
-    			File archiveFile = cacheManager.getArchiveFileInCache(artifacts[i], origin, options.isUseOrigin());
-
-    			if (archiveFile.exists()) {
-    				Message.verbose("\t[NOT REQUIRED] "+artifacts[i]);
-    				adr.setDownloadStatus(DownloadStatus.NO);  
-    				adr.setSize(archiveFile.length());
-    				adr.setArtifactOrigin(origin);
-    			} else {
-    				Artifact artifact = fromSystem(artifacts[i]);
-    				if (!artifact.equals(artifacts[i])) {
-    					Message.verbose("\t"+getName()+"looking for artifact "+artifact+ " (is "+artifacts[i]+" in system namespace)");
-    				}
-    				long start = System.currentTimeMillis();
-    				try {
-    					ResolvedResource artifactRef = getArtifactRef(artifact, null);
-    					if (artifactRef != null) {
-    						origin = new ArtifactOrigin(artifactRef.getResource().isLocal(), artifactRef.getResource().getName());
-    						if (useOrigin && artifactRef.getResource().isLocal()) {
-    							Message.verbose("\t[NOT REQUIRED] "+artifacts[i]);
-    							cacheManager.saveArtifactOrigin(artifacts[i], origin);
-    							archiveFile = cacheManager.getArchiveFileInCache(artifacts[i], origin);
-    							adr.setDownloadStatus(DownloadStatus.NO);  
-    							adr.setSize(archiveFile.length());
-    							adr.setArtifactOrigin(origin);
-    						} else {
-    							// refresh archive file now that we better now its origin
-    							archiveFile = cacheManager.getArchiveFileInCache(artifacts[i], origin, useOrigin);
-    							if (ResourceHelper.equals(artifactRef.getResource(), 
-    									archiveFile)) {
-    								Message.error("invalid configuration for resolver '"+getName()+"': pointing artifacts to ivy cache is forbidden !");
-    								return null;
-    							}
-    							Message.info("downloading "+artifactRef.getResource()+" ...");
-    							if (eventManager != null) {
-    								eventManager.fireIvyEvent(new StartArtifactDownloadEvent(this, artifacts[i], origin));
-    							}
-
-    							File tmp = cacheManager.getArchiveFileInCache( 
-    									new DefaultArtifact(
-    											artifacts[i].getModuleRevisionId(), 
-    											artifacts[i].getPublicationDate(), 
-    											artifacts[i].getName(), 
-    											artifacts[i].getType(), 
-    											artifacts[i].getExt()+".part",
-    											artifacts[i].getExtraAttributes()),
-    											origin, useOrigin);
-
-    							// deal with artifact with url special case
-    							if (artifactRef.getResource().getName().equals(String.valueOf(artifacts[i].getUrl()))) {
-    								Message.verbose("\t"+getName()+": downloading "+artifactRef.getResource().getName());
-    								Message.debug("\t\tto "+tmp);
-    								if (tmp.getParentFile() != null) {
-    									tmp.getParentFile().mkdirs();
-    								}
-    								_extartifactrep.get(artifactRef.getResource().getName(), tmp);
-    								adr.setSize(tmp.length());
-    							} else {
-    								adr.setSize(getAndCheck(artifactRef.getResource(), tmp));
-    							}
-    							if (!tmp.renameTo(archiveFile)) {
-    								Message.warn("\t[FAILED     ] "+artifacts[i]+" impossible to move temp file to definitive one ("+(System.currentTimeMillis()-start)+"ms)");
-    								adr.setDownloadStatus(DownloadStatus.FAILED);
-    							} else {
-    								cacheManager.saveArtifactOrigin(artifacts[i], origin);
-    								Message.info("\t[SUCCESSFUL ] "+artifacts[i]+" ("+(System.currentTimeMillis()-start)+"ms)");
-    								adr.setDownloadStatus(DownloadStatus.SUCCESSFUL);
-    								adr.setArtifactOrigin(origin);
-    							}
-    						}
-    					} else {
-    						adr.setDownloadStatus(DownloadStatus.FAILED);                
-    					}
-    				} catch (Exception ex) {
-    					Message.warn("\t[FAILED     ] "+artifacts[i]+" : "+ex.getMessage()+" ("+(System.currentTimeMillis()-start)+"ms)");
-    					adr.setDownloadStatus(DownloadStatus.FAILED);
-    				}
-    				checkInterrupted();
-    			}
-    			if (eventManager != null) {
-    				eventManager.fireIvyEvent(new EndArtifactDownloadEvent(this, artifacts[i], adr, archiveFile));
-    			}
-    		}
-    		return dr;
-    	} finally {
-    		IvyContext.getContext().popResolver();
-    	}
+        IvyContext.getContext().pushResolver(this);
+        try {
+            CacheManager cacheManager = options.getCacheManager();
+            EventManager eventManager = options.getEventManager();
+
+            boolean useOrigin = options.isUseOrigin();
+
+            clearArtifactAttempts();
+            DownloadReport dr = new DownloadReport();
+            for (int i = 0; i < artifacts.length; i++) {
+                final ArtifactDownloadReport adr = new ArtifactDownloadReport(artifacts[i]);
+                dr.addArtifactReport(adr);
+                if (eventManager != null) {
+                    eventManager.fireIvyEvent(new NeedArtifactEvent(this, artifacts[i]));
+                }
+                ArtifactOrigin origin = cacheManager.getSavedArtifactOrigin(artifacts[i]);
+                // if we can use origin file, we just ask ivy for the file in cache, and it will
+                // return
+                // the original one if possible. If we are not in useOrigin mode, we use the
+                // getArchivePath
+                // method which always return a path in the actual cache
+                File archiveFile = cacheManager.getArchiveFileInCache(artifacts[i], origin, options
+                        .isUseOrigin());
+
+                if (archiveFile.exists()) {
+                    Message.verbose("\t[NOT REQUIRED] " + artifacts[i]);
+                    adr.setDownloadStatus(DownloadStatus.NO);
+                    adr.setSize(archiveFile.length());
+                    adr.setArtifactOrigin(origin);
+                } else {
+                    Artifact artifact = fromSystem(artifacts[i]);
+                    if (!artifact.equals(artifacts[i])) {
+                        Message.verbose("\t" + getName() + "looking for artifact " + artifact
+                                + " (is " + artifacts[i] + " in system namespace)");
+                    }
+                    long start = System.currentTimeMillis();
+                    try {
+                        ResolvedResource artifactRef = getArtifactRef(artifact, null);
+                        if (artifactRef != null) {
+                            origin = new ArtifactOrigin(artifactRef.getResource().isLocal(),
+                                    artifactRef.getResource().getName());
+                            if (useOrigin && artifactRef.getResource().isLocal()) {
+                                Message.verbose("\t[NOT REQUIRED] " + artifacts[i]);
+                                cacheManager.saveArtifactOrigin(artifacts[i], origin);
+                                archiveFile = cacheManager.getArchiveFileInCache(artifacts[i],
+                                    origin);
+                                adr.setDownloadStatus(DownloadStatus.NO);
+                                adr.setSize(archiveFile.length());
+                                adr.setArtifactOrigin(origin);
+                            } else {
+                                // refresh archive file now that we better now its origin
+                                archiveFile = cacheManager.getArchiveFileInCache(artifacts[i],
+                                    origin, useOrigin);
+                                if (ResourceHelper.equals(artifactRef.getResource(), archiveFile)) {
+                                    Message.error("invalid configuration for resolver '"
+                                            + getName()
+                                            + "': pointing artifacts to ivy cache is forbidden !");
+                                    return null;
+                                }
+                                Message.info("downloading " + artifactRef.getResource() + " ...");
+                                if (eventManager != null) {
+                                    eventManager.fireIvyEvent(new StartArtifactDownloadEvent(this,
+                                            artifacts[i], origin));
+                                }
+
+                                File tmp = cacheManager.getArchiveFileInCache(new DefaultArtifact(
+                                        artifacts[i].getModuleRevisionId(), artifacts[i]
+                                                .getPublicationDate(), artifacts[i].getName(),
+                                        artifacts[i].getType(), artifacts[i].getExt() + ".part",
+                                        artifacts[i].getExtraAttributes()), origin, useOrigin);
+
+                                // deal with artifact with url special case
+                                if (artifactRef.getResource().getName().equals(
+                                    String.valueOf(artifacts[i].getUrl()))) {
+                                    Message.verbose("\t" + getName() + ": downloading "
+                                            + artifactRef.getResource().getName());
+                                    Message.debug("\t\tto " + tmp);
+                                    if (tmp.getParentFile() != null) {
+                                        tmp.getParentFile().mkdirs();
+                                    }
+                                    _extartifactrep.get(artifactRef.getResource().getName(), tmp);
+                                    adr.setSize(tmp.length());
+                                } else {
+                                    adr.setSize(getAndCheck(artifactRef.getResource(), tmp));
+                                }
+                                if (!tmp.renameTo(archiveFile)) {
+                                    Message.warn("\t[FAILED     ] " + artifacts[i]
+                                            + " impossible to move temp file to definitive one ("
+                                            + (System.currentTimeMillis() - start) + "ms)");
+                                    adr.setDownloadStatus(DownloadStatus.FAILED);
+                                } else {
+                                    cacheManager.saveArtifactOrigin(artifacts[i], origin);
+                                    Message.info("\t[SUCCESSFUL ] " + artifacts[i] + " ("
+                                            + (System.currentTimeMillis() - start) + "ms)");
+                                    adr.setDownloadStatus(DownloadStatus.SUCCESSFUL);
+                                    adr.setArtifactOrigin(origin);
+                                }
+                            }
+                        } else {
+                            adr.setDownloadStatus(DownloadStatus.FAILED);
+                        }
+                    } catch (Exception ex) {
+                        Message.warn("\t[FAILED     ] " + artifacts[i] + " : " + ex.getMessage()
+                                + " (" + (System.currentTimeMillis() - start) + "ms)");
+                        adr.setDownloadStatus(DownloadStatus.FAILED);
+                    }
+                    checkInterrupted();
+                }
+                if (eventManager != null) {
+                    eventManager.fireIvyEvent(new EndArtifactDownloadEvent(this, artifacts[i], adr,
+                            archiveFile));
+                }
+            }
+            return dr;
+        } finally {
+            IvyContext.getContext().popResolver();
+        }
     }
 
-	protected void clearArtifactAttempts() {
-    	_artattempts.clear();
+    protected void clearArtifactAttempts() {
+        _artattempts.clear();
     }
-    
+
     public boolean exists(Artifact artifact) {
         ResolvedResource artifactRef = getArtifactRef(artifact, null);
         if (artifactRef != null) {
@@ -787,18 +869,18 @@
     public String toString() {
         return getName();
     }
-    
+
     public String[] listTokenValues(String token, Map otherTokenValues) {
         Collection ret = findNames(otherTokenValues, token);
-    	return (String[]) ret.toArray(new String[ret.size()]);
+        return (String[]) ret.toArray(new String[ret.size()]);
     }
 
     public OrganisationEntry[] listOrganisations() {
         Collection names = findNames(Collections.EMPTY_MAP, IvyPatternHelper.ORGANISATION_KEY);
         OrganisationEntry[] ret = new OrganisationEntry[names.size()];
-        int i =0;
+        int i = 0;
         for (Iterator iter = names.iterator(); iter.hasNext(); i++) {
-            String org = (String)iter.next();
+            String org = (String) iter.next();
             ret[i] = new OrganisationEntry(this, org);
         }
         return ret;
@@ -809,9 +891,9 @@
         tokenValues.put(IvyPatternHelper.ORGANISATION_KEY, org.getOrganisation());
         Collection names = findNames(tokenValues, IvyPatternHelper.MODULE_KEY);
         ModuleEntry[] ret = new ModuleEntry[names.size()];
-        int i =0;
+        int i = 0;
         for (Iterator iter = names.iterator(); iter.hasNext(); i++) {
-            String name = (String)iter.next();
+            String name = (String) iter.next();
             ret[i] = new ModuleEntry(org, name);
         }
         return ret;
@@ -823,9 +905,9 @@
         tokenValues.put(IvyPatternHelper.MODULE_KEY, mod.getModule());
         Collection names = findNames(tokenValues, IvyPatternHelper.REVISION_KEY);
         RevisionEntry[] ret = new RevisionEntry[names.size()];
-        int i =0;
+        int i = 0;
         for (Iterator iter = names.iterator(); iter.hasNext(); i++) {
-            String name = (String)iter.next();
+            String name = (String) iter.next();
             ret[i] = new RevisionEntry(mod, name);
         }
         return ret;
@@ -835,7 +917,8 @@
 
     protected abstract ResolvedResource findIvyFileRef(DependencyDescriptor dd, ResolveData data);
 
-    protected ResolvedResource findFirstArtifactRef(ModuleDescriptor md, DependencyDescriptor dd, ResolveData data) {
+    protected ResolvedResource findFirstArtifactRef(ModuleDescriptor md, DependencyDescriptor dd,
+            ResolveData data) {
         ResolvedResource ret = null;
         String[] conf = md.getConfigurationsNames();
         for (int i = 0; i < conf.length; i++) {
@@ -843,7 +926,7 @@
             for (int j = 0; j < artifacts.length; j++) {
                 ret = getArtifactRef(artifacts[j], data.getDate());
                 if (ret != null) {
-                	return ret;
+                    return ret;
                 }
             }
         }
@@ -851,67 +934,72 @@
     }
 
     protected long getAndCheck(Resource resource, File dest) throws IOException {
-		long size = get(resource, dest);
-		String[] checksums = getChecksumAlgorithms();
-		boolean checked = false;
-		for (int i = 0; i < checksums.length && !checked; i++) {
-			checked = check(resource, dest, checksums[i]);
-		}
-		return size;
-	}
+        long size = get(resource, dest);
+        String[] checksums = getChecksumAlgorithms();
+        boolean checked = false;
+        for (int i = 0; i < checksums.length && !checked; i++) {
+            checked = check(resource, dest, checksums[i]);
+        }
+        return size;
+    }
 
     /**
      * Checks the given resource checksum if a checksum resource exists.
      * 
-     * @param resource the resource to check
-     * @param dest the file where the resource has been downloaded
-     * @param algorithm the checksum algorithm to use
-     * @return true if the checksum has been successfully checked, false if the checksum wasn't available
-     * @throws IOException if a checksum exist but do not match the downloaded file checksum
+     * @param resource
+     *            the resource to check
+     * @param dest
+     *            the file where the resource has been downloaded
+     * @param algorithm
+     *            the checksum algorithm to use
+     * @return true if the checksum has been successfully checked, false if the checksum wasn't
+     *         available
+     * @throws IOException
+     *             if a checksum exist but do not match the downloaded file checksum
      */
-	private boolean check(Resource resource, File dest, String algorithm) throws IOException {
-		Resource csRes = resource.clone(resource.getName()+"."+algorithm);
-		if (csRes.exists()) {
-			Message.debug(algorithm + " file found for "+resource+": checking...");
-			File csFile = File.createTempFile("ivytmp", algorithm);
-			try {
-				get(csRes, csFile);
-				try {
-					ChecksumHelper.check(dest, csFile, algorithm);
-					Message.verbose(algorithm + " OK for "+resource);
-					return true;
-				} catch (IOException ex) {
-					dest.delete();
-					throw ex;
-				}
-			} finally {
-				csFile.delete();
-			}
-		} else {
-			return false;
-		}
-	}
-
+    private boolean check(Resource resource, File dest, String algorithm) throws IOException {
+        Resource csRes = resource.clone(resource.getName() + "." + algorithm);
+        if (csRes.exists()) {
+            Message.debug(algorithm + " file found for " + resource + ": checking...");
+            File csFile = File.createTempFile("ivytmp", algorithm);
+            try {
+                get(csRes, csFile);
+                try {
+                    ChecksumHelper.check(dest, csFile, algorithm);
+                    Message.verbose(algorithm + " OK for " + resource);
+                    return true;
+                } catch (IOException ex) {
+                    dest.delete();
+                    throw ex;
+                }
+            } finally {
+                csFile.delete();
+            }
+        } else {
+            return false;
+        }
+    }
 
     protected ResolvedResource getArtifactRef(Artifact artifact, Date date) {
-    	IvyContext.getContext().set(getName()+".artifact", artifact);
-    	try {
-    		ResolvedResource ret = findArtifactRef(artifact, date);
-    		if (ret == null && artifact.getUrl() != null) {
-    			URL url = artifact.getUrl();
-    			Message.verbose("\tusing url for "+artifact+": "+url);
-    			logArtifactAttempt(artifact, url.toExternalForm());
-    			ret =  new ResolvedResource(new URLResource(url), artifact.getModuleRevisionId().getRevision());
-    		}
-    		return ret;
-    	} finally {
-        	IvyContext.getContext().set(getName()+".artifact", null);
-    	}
+        IvyContext.getContext().set(getName() + ".artifact", artifact);
+        try {
+            ResolvedResource ret = findArtifactRef(artifact, date);
+            if (ret == null && artifact.getUrl() != null) {
+                URL url = artifact.getUrl();
+                Message.verbose("\tusing url for " + artifact + ": " + url);
+                logArtifactAttempt(artifact, url.toExternalForm());
+                ret = new ResolvedResource(new URLResource(url), artifact.getModuleRevisionId()
+                        .getRevision());
+            }
+            return ret;
+        } finally {
+            IvyContext.getContext().set(getName() + ".artifact", null);
+        }
     }
 
     protected abstract ResolvedResource findArtifactRef(Artifact artifact, Date date);
 
-	protected abstract long get(Resource resource, File dest) throws IOException;    
+    protected abstract long get(Resource resource, File dest) throws IOException;
 
     public boolean isCheckconsistency() {
         return _checkconsistency;
@@ -924,30 +1012,31 @@
     public boolean isAllownomd() {
         return _allownomd;
     }
+
     public void setAllownomd(boolean b) {
         _allownomd = b;
     }
 
-	public String[] getChecksumAlgorithms() {
-		String csDef = _checksums == null ? getSettings().getVariable("ivy.checksums") : _checksums;
-		if (csDef == null) {
-			return new String[0];
-		}
-		// csDef is a comma separated list of checksum algorithms to use with this resolver
-		// we parse and return it as a String[]
-		String[] checksums = csDef.split(",");
-		List algos = new ArrayList();
-		for (int i = 0; i < checksums.length; i++) {
-			String cs = checksums[i].trim();
-			if (!"".equals(cs) && !"none".equals(cs)) {
-				algos.add(cs);
-			}
-		}
-		return (String[]) algos.toArray(new String[algos.size()]);
-	}
-
-	public void setChecksums(String checksums) {
-		_checksums = checksums;
-	}
+    public String[] getChecksumAlgorithms() {
+        String csDef = _checksums == null ? getSettings().getVariable("ivy.checksums") : _checksums;
+        if (csDef == null) {
+            return new String[0];
+        }
+        // csDef is a comma separated list of checksum algorithms to use with this resolver
+        // we parse and return it as a String[]
+        String[] checksums = csDef.split(",");
+        List algos = new ArrayList();
+        for (int i = 0; i < checksums.length; i++) {
+            String cs = checksums[i].trim();
+            if (!"".equals(cs) && !"none".equals(cs)) {
+                algos.add(cs);
+            }
+        }
+        return (String[]) algos.toArray(new String[algos.size()]);
+    }
+
+    public void setChecksums(String checksums) {
+        _checksums = checksums;
+    }
 
 }

Modified: incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/CacheResolver.java
URL: http://svn.apache.org/viewvc/incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/CacheResolver.java?view=diff&rev=544459&r1=544458&r2=544459
==============================================================================
--- incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/CacheResolver.java (original)
+++ incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/CacheResolver.java Tue Jun  5 05:02:27 2007
@@ -41,66 +41,71 @@
 import org.apache.ivy.plugins.resolver.util.ResolvedResource;
 import org.apache.ivy.util.Message;
 
-
-
 public class CacheResolver extends FileSystemResolver {
     private File _configured = null;
-    
+
     public CacheResolver() {
     }
-    
+
     public CacheResolver(IvySettings settings) {
         setSettings(settings);
         setName("cache");
     }
 
-    public ResolvedModuleRevision getDependency(DependencyDescriptor dd, ResolveData data) throws ParseException {
+    public ResolvedModuleRevision getDependency(DependencyDescriptor dd, ResolveData data)
+            throws ParseException {
         clearIvyAttempts();
 
         ModuleRevisionId mrid = dd.getDependencyRevisionId();
         // check revision
-        
-        // if we do not have to check modified and if the revision is exact and not changing,  
+
+        // if we do not have to check modified and if the revision is exact and not changing,
         // we first search for it in cache
         if (!getSettings().getVersionMatcher().isDynamic(mrid)) {
-            ResolvedModuleRevision rmr = data.getCacheManager().findModuleInCache(mrid, doValidate(data));
+            ResolvedModuleRevision rmr = data.getCacheManager().findModuleInCache(mrid,
+                doValidate(data));
             if (rmr != null) {
-                Message.verbose("\t"+getName()+": revision in cache: "+mrid);
+                Message.verbose("\t" + getName() + ": revision in cache: " + mrid);
                 return rmr;
             } else {
-            	logIvyAttempt(data.getCacheManager().getArchiveFileInCache(DefaultArtifact.newIvyArtifact(mrid, new Date())).getAbsolutePath());
-                Message.verbose("\t"+getName()+": no ivy file in cache found for "+mrid);
+                logIvyAttempt(data.getCacheManager().getArchiveFileInCache(
+                    DefaultArtifact.newIvyArtifact(mrid, new Date())).getAbsolutePath());
+                Message.verbose("\t" + getName() + ": no ivy file in cache found for " + mrid);
                 return null;
             }
         } else {
             ensureConfigured(data.getSettings(), data.getCacheManager().getCache());
             ResolvedResource ivyRef = findIvyFileRef(dd, data);
             if (ivyRef != null) {
-                Message.verbose("\t"+getName()+": found ivy file in cache for "+mrid);
-                Message.verbose("\t\t=> "+ivyRef);
+                Message.verbose("\t" + getName() + ": found ivy file in cache for " + mrid);
+                Message.verbose("\t\t=> " + ivyRef);
 
-                ModuleRevisionId resolvedMrid = ModuleRevisionId.newInstance(mrid, ivyRef.getRevision());
+                ModuleRevisionId resolvedMrid = ModuleRevisionId.newInstance(mrid, ivyRef
+                        .getRevision());
                 IvyNode node = data.getNode(resolvedMrid);
                 if (node != null && node.getModuleRevision() != null) {
                     // this revision has already be resolved : return it
-                    Message.verbose("\t"+getName()+": revision already resolved: "+resolvedMrid);
+                    Message.verbose("\t" + getName() + ": revision already resolved: "
+                            + resolvedMrid);
                     return searchedRmr(node.getModuleRevision());
                 }
-                ResolvedModuleRevision rmr = data.getCacheManager().findModuleInCache(resolvedMrid, doValidate(data));
+                ResolvedModuleRevision rmr = data.getCacheManager().findModuleInCache(resolvedMrid,
+                    doValidate(data));
                 if (rmr != null) {
-                    Message.verbose("\t"+getName()+": revision in cache: "+resolvedMrid);
+                    Message.verbose("\t" + getName() + ": revision in cache: " + resolvedMrid);
                     return searchedRmr(rmr);
                 } else {
-                    Message.error("\t"+getName()+": inconsistent cache: clean it and resolve again");
+                    Message.error("\t" + getName()
+                            + ": inconsistent cache: clean it and resolve again");
                     return null;
                 }
             } else {
-                Message.verbose("\t"+getName()+": no ivy file in cache found for "+mrid);
+                Message.verbose("\t" + getName() + ": no ivy file in cache found for " + mrid);
                 return null;
             }
         }
     }
-    
+
     public DownloadReport download(Artifact[] artifacts, DownloadOptions options) {
         clearArtifactAttempts();
         DownloadReport dr = new DownloadReport();
@@ -109,40 +114,44 @@
             dr.addArtifactReport(adr);
             File archiveFile = options.getCacheManager().getArchiveFileInCache(artifacts[i]);
             if (archiveFile.exists()) {
-                Message.verbose("\t[NOT REQUIRED] "+artifacts[i]);
-                adr.setDownloadStatus(DownloadStatus.NO);  
+                Message.verbose("\t[NOT REQUIRED] " + artifacts[i]);
+                adr.setDownloadStatus(DownloadStatus.NO);
                 adr.setSize(archiveFile.length());
             } else {
-            		logArtifactAttempt(artifacts[i], archiveFile.getAbsolutePath());
-                    adr.setDownloadStatus(DownloadStatus.FAILED);                
+                logArtifactAttempt(artifacts[i], archiveFile.getAbsolutePath());
+                adr.setDownloadStatus(DownloadStatus.FAILED);
             }
         }
         return dr;
     }
+
     public boolean exists(Artifact artifact) {
         ensureConfigured();
         return super.exists(artifact);
     }
+
     public void publish(Artifact artifact, File src, boolean overwrite) throws IOException {
         ensureConfigured();
         super.publish(artifact, src, overwrite);
     }
-    
-    
+
     public OrganisationEntry[] listOrganisations() {
         ensureConfigured();
         return super.listOrganisations();
     }
+
     public ModuleEntry[] listModules(OrganisationEntry org) {
         ensureConfigured();
-        return super.listModules(org);        
+        return super.listModules(org);
     }
+
     public RevisionEntry[] listRevisions(ModuleEntry module) {
         ensureConfigured();
-        return super.listRevisions(module);        
+        return super.listRevisions(module);
     }
+
     public void dumpSettings() {
-        Message.verbose("\t"+getName()+" [cache]");
+        Message.verbose("\t" + getName() + " [cache]");
     }
 
     private void ensureConfigured() {
@@ -150,13 +159,17 @@
             ensureConfigured(getSettings(), getSettings().getDefaultCache());
         }
     }
+
     private void ensureConfigured(IvySettings settings, File cache) {
         if (settings == null || cache == null || (_configured != null && _configured.equals(cache))) {
             return;
         }
-        setIvyPatterns(Collections.singletonList(cache.getAbsolutePath()+"/"+settings.getCacheIvyPattern()));
-        setArtifactPatterns(Collections.singletonList(cache.getAbsolutePath()+"/"+settings.getCacheArtifactPattern()));
+        setIvyPatterns(Collections.singletonList(cache.getAbsolutePath() + "/"
+                + settings.getCacheIvyPattern()));
+        setArtifactPatterns(Collections.singletonList(cache.getAbsolutePath() + "/"
+                + settings.getCacheArtifactPattern()));
     }
+
     public String getTypeName() {
         return "cache";
     }