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 [12/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/core/resolve/VisitNode.java
URL: http://svn.apache.org/viewvc/incubator/ivy/core/trunk/src/java/org/apache/ivy/core/resolve/VisitNode.java?view=diff&rev=544459&r1=544458&r2=544459
==============================================================================
--- incubator/ivy/core/trunk/src/java/org/apache/ivy/core/resolve/VisitNode.java (original)
+++ incubator/ivy/core/trunk/src/java/org/apache/ivy/core/resolve/VisitNode.java Tue Jun  5 05:02:27 2007
@@ -34,92 +34,86 @@
 import org.apache.ivy.plugins.conflict.ConflictManager;
 
 /**
- * A visit node is an object used to represent one visit from one parent on 
- * an {@link IvyNode} of the dependency graph.
- * 
- * During dependency resolution, the {@link ResolveEngine} visits nodes of the 
- * depency graph following the dependencies, thus the same node can be visited
- * several times, if it is requested from several module.
- * 
- * In this case you will have one VisitNode per parent and per root module 
- * configuration.
- * 
- * Thus VisitNode stores data specific to the visit:
+ * A visit node is an object used to represent one visit from one parent on an {@link IvyNode} of
+ * the dependency graph. During dependency resolution, the {@link ResolveEngine} visits nodes of the
+ * depency graph following the dependencies, thus the same node can be visited several times, if it
+ * is requested from several module. In this case you will have one VisitNode per parent and per
+ * root module configuration. Thus VisitNode stores data specific to the visit:
  * <ul>
- * <li>parent</li> the node from which the visit is occuring
- * <li>parentConf</li> the configuration of the parent in which this node is visited
- * <li>rootModuleConf</li> the configuration of the root module which is currently resolved
+ * <li>parent</li>
+ * the node from which the visit is occuring
+ * <li>parentConf</li>
+ * the configuration of the parent in which this node is visited
+ * <li>rootModuleConf</li>
+ * the configuration of the root module which is currently resolved
  * </ul>
- * 
  */
 public class VisitNode {
-	/**
-	 * The node which is currently visited 
-	 */
-	private IvyNode node;
-    /** 
-     * Represents the current parent of the node during ivy visit
-     * of dependency graph.
+    /**
+     * The node which is currently visited
+     */
+    private IvyNode node;
+
+    /**
+     * Represents the current parent of the node during ivy visit of dependency graph.
      */
     private VisitNode parent = null;
+
     /**
-     * The root node of the current visit
-     * It is null until it is required, see getRoot
+     * The root node of the current visit It is null until it is required, see getRoot
      */
     private VisitNode root = null;
+
     /**
-     * Direct path from root to this node. 
-     * Note that the colleciton is ordered but is not a list implementation 
-     * This collection is null until it is required, see getPath
+     * Direct path from root to this node. Note that the colleciton is ordered but is not a list
+     * implementation This collection is null until it is required, see getPath
      */
     private Collection path = null; // Collection(VisitNode)
-    
-    
+
     /**
-     * The configuration of the parent module in the current visit 
+     * The configuration of the parent module in the current visit
      */
     private String parentConf = null;
+
     /**
-     * The configuration requested by the parent
-     * Note that this is the actual conf requested by the parent, not 
-     * a configuration extended by the requested conf which actually 
-     * trigger the node visit
+     * The configuration requested by the parent Note that this is the actual conf requested by the
+     * parent, not a configuration extended by the requested conf which actually trigger the node
+     * visit
      */
     private String requestedConf;
+
     /**
      * The root configuration which is currently visited
      */
     private String rootModuleConf;
-    
+
     /**
-     * Shared ResolveData instance, which can be used
-     * to get info on the current resolve process
+     * Shared ResolveData instance, which can be used to get info on the current resolve process
      */
     private ResolveData data;
+
     /**
-     * Boolean.TRUE if a node with a same module id as the one visited 
-     * has already been visited in the current path.
-     * null if not computed yet
-     * Boolean.FALSE otherwise
-     */
-	private Boolean isCircular;
-
-    
-    public VisitNode(ResolveData data, IvyNode node, VisitNode parent, String rootModuleConf, String parentConf) {
-    	if (data == null) {
-    		throw new NullPointerException("data must not be null");
-    	}
-    	if (node == null) {
-    		throw new NullPointerException("node must not be null");
-    	}
-    	if (rootModuleConf == null) {
-    		throw new NullPointerException("rootModuleConf must not be null");
-    	}
-    	this.data = data;
-    	this.node = node;
-    	this.parent = parent;
-    	this.rootModuleConf = rootModuleConf;
-    	this.parentConf = parentConf;
+     * Boolean.TRUE if a node with a same module id as the one visited has already been visited in
+     * the current path. null if not computed yet Boolean.FALSE otherwise
+     */
+    private Boolean isCircular;
+
+    public VisitNode(ResolveData data, IvyNode node, VisitNode parent, String rootModuleConf,
+            String parentConf) {
+        if (data == null) {
+            throw new NullPointerException("data must not be null");
+        }
+        if (node == null) {
+            throw new NullPointerException("node must not be null");
+        }
+        if (rootModuleConf == null) {
+            throw new NullPointerException("rootModuleConf must not be null");
+        }
+        this.data = data;
+        this.node = node;
+        this.parent = parent;
+        this.rootModuleConf = rootModuleConf;
+        this.parentConf = parentConf;
 
         // we do not register if this is a root module (root == no parent)
         init(data, this.parent != null);
@@ -131,27 +125,25 @@
             this.data.register(this);
         }
     }
-    
-    
-	public IvyNode getNode() {
-		return node;
-	}
 
-	/**
+    public IvyNode getNode() {
+        return node;
+    }
+
+    /**
      * @return Returns the configuration requested by the parent
      */
     public String getRequestedConf() {
         return requestedConf;
     }
-    
+
     public void setRequestedConf(String requestedConf) {
         this.requestedConf = requestedConf;
     }
-    
 
     public VisitNode getParent() {
         return parent;
-    }    
+    }
 
     public VisitNode getRoot() {
         if (root == null) {
@@ -200,7 +192,7 @@
     }
 
     public static VisitNode getRoot(VisitNode parent) {
-    	VisitNode root = parent;
+        VisitNode root = parent;
         Collection path = new HashSet();
         path.add(root);
         while (root.getParent() != null && !root.getNode().isRoot()) {
@@ -212,29 +204,29 @@
         }
         return root;
     }
-    
 
     /**
-     * Returns true if the current dependency descriptor is transitive
-     * and the parent configuration is transitive.  Otherwise returns false.
-     * @param node curent node
-     * @return true if current node is transitive and the parent configuration is
-     * transitive.
+     * Returns true if the current dependency descriptor is transitive and the parent configuration
+     * is transitive. Otherwise returns false.
+     * 
+     * @param node
+     *            curent node
+     * @return true if current node is transitive and the parent configuration is transitive.
      */
     public boolean isTransitive() {
-        return (data.isTransitive() &&
-        		node.getDependencyDescriptor(getParentNode()).isTransitive() &&
-                isParentConfTransitive() );
+        return (data.isTransitive() && node.getDependencyDescriptor(getParentNode()).isTransitive() && isParentConfTransitive());
     }
 
     /**
      * Checks if the current node's parent configuration is transitive.
-     * @param node current node
+     * 
+     * @param node
+     *            current node
      * @return true if the node's parent configuration is transitive
      */
     protected boolean isParentConfTransitive() {
         String conf = getParent().getRequestedConf();
-        if (conf==null) {
+        if (conf == null) {
             return true;
         }
         Configuration parentConf = getParentNode().getConfiguration(conf);
@@ -243,12 +235,12 @@
     }
 
     /**
-     * Returns the 'real' node currently visited.
-     * 'Real' means that if we are visiting a node created originally with only a version
-     * constraint, and if this version constraint has been resolved to an existing node
-     * in the graph, we will return the existing node, and not the one originally used
-     * which is about to be discarded, since it's not possible to have in the graph
+     * Returns the 'real' node currently visited. 'Real' means that if we are visiting a node
+     * created originally with only a version constraint, and if this version constraint has been
+     * resolved to an existing node in the graph, we will return the existing node, and not the one
+     * originally used which is about to be discarded, since it's not possible to have in the graph
      * two nodes for the same ModuleRevisionId
+     * 
      * @return the 'real' node currently visited.
      */
     public IvyNode getRealNode() {
@@ -261,223 +253,231 @@
     }
 
     /**
-     * Ask to the current visited node to use a real node only, if one exist. 
-     * See getRealNode for details about what a 'real' node is.
+     * Ask to the current visited node to use a real node only, if one exist. See getRealNode for
+     * details about what a 'real' node is.
      */
     public void useRealNode() {
-    	if (parent != null) { // use real node make sense only for non root module
-	        IvyNode node = data.getNode(this.node.getId());
-	        if (node != null && node != this.node) {
-	        	this.node = node;
-	        }
-    	}
+        if (parent != null) { // use real node make sense only for non root module
+            IvyNode node = data.getNode(this.node.getId());
+            if (node != null && node != this.node) {
+                this.node = node;
+            }
+        }
     }
 
     public boolean loadData(String conf, boolean shouldBePublic) {
-        boolean loaded = node.loadData(rootModuleConf, getParentNode(), parentConf, conf, shouldBePublic);
+        boolean loaded = node.loadData(rootModuleConf, getParentNode(), parentConf, conf,
+            shouldBePublic);
         if (loaded) {
-	        useRealNode();
-	
-	        // if the revision was a dynamic one (which has now be resolved)
-	        // we now register this node on the resolved id
-	        if (data.getSettings().getVersionMatcher().isDynamic(getId())) {
-	            data.register(node.getResolvedId(), this);
-	        }
+            useRealNode();
+
+            // if the revision was a dynamic one (which has now be resolved)
+            // we now register this node on the resolved id
+            if (data.getSettings().getVersionMatcher().isDynamic(getId())) {
+                data.register(node.getResolvedId(), this);
+            }
         }
 
         return loaded;
     }
 
     public Collection getDependencies(String conf) {
-    	Collection deps = node.getDependencies(rootModuleConf, conf, requestedConf);
-    	Collection ret = new ArrayList(deps.size());
-    	for (Iterator iter = deps.iterator(); iter.hasNext();) {
-			IvyNode depNode = (IvyNode) iter.next();
-			ret.add(traverseChild(conf, depNode));
-		}
-    	return ret;
-    }
-    
-    /**
-     * Returns a VisitNode for the given node.
-     * The given node must be a representation of the same module 
-     * (usually in another revision) as the one visited by this node.
-     * 
-     * The given node must also have been already visited.
+        Collection deps = node.getDependencies(rootModuleConf, conf, requestedConf);
+        Collection ret = new ArrayList(deps.size());
+        for (Iterator iter = deps.iterator(); iter.hasNext();) {
+            IvyNode depNode = (IvyNode) iter.next();
+            ret.add(traverseChild(conf, depNode));
+        }
+        return ret;
+    }
+
+    /**
+     * Returns a VisitNode for the given node. The given node must be a representation of the same
+     * module (usually in another revision) as the one visited by this node. The given node must
+     * also have been already visited.
      * 
-     * @param node the node to visit
+     * @param node
+     *            the node to visit
      * @return a VisitNode for the given node
      */
-	VisitNode gotoNode(IvyNode node) {
-		if (!getModuleId().equals(node.getModuleId())) {
-			throw new IllegalArgumentException("you can't use gotoNode for a node which does not represent the same Module as the one represented by this node.\nCurrent node module id="+getModuleId()+" Given node module id="+node.getModuleId());
-		}
-		VisitData visitData = data.getVisitData(node.getId());
-		if (visitData == null) {
-			throw new IllegalArgumentException("you can't use gotoNode with a node which has not been visited yet.\nGiven node id="+node.getId());
-		}
-		for (Iterator iter = visitData.getVisitNodes(rootModuleConf).iterator(); iter.hasNext();) {
-			VisitNode vnode = (VisitNode) iter.next();
-			if ((parent == null && vnode.getParent() == null) ||
-					(parent != null && parent.getId().equals(vnode.getParent().getId()))) {
-				return vnode;
-			}
-		}
-		// the node has not yet been visited from the current parent, we create a new visit node
-		return traverse(parent, parentConf, node);
-	}
-
-	private VisitNode traverseChild(String parentConf, IvyNode child) {
-		VisitNode parent = this;
-		return traverse(parent, parentConf, child);
-	}
-
-	private VisitNode traverse(VisitNode parent, String parentConf, IvyNode node) {
-		if (getPath().contains(node)) {
-			IvyContext.getContext().getCircularDependencyStrategy()
-				.handleCircularDependency(toMrids(getPath(), node.getId()));
-			// we do not use the new parent, but the first one, to always be able to go up to the root
-//			parent = getVisitNode(depNode).getParent(); 
-		}
-		return new VisitNode(data, node, parent, rootModuleConf, parentConf);
-	}
-
-	private ModuleRevisionId[] toMrids(Collection path, ModuleRevisionId last) {
-    	ModuleRevisionId[] ret = new ModuleRevisionId[path.size()+1];
-    	int i=0;
-    	for (Iterator iter = path.iterator(); iter.hasNext(); i++) {
-    		VisitNode node = (VisitNode) iter.next();
-			ret[i] = node.getNode().getId();
-		}
-    	ret[ret.length-1] = last;
-		return ret;
-	}
-
-	public ModuleRevisionId getResolvedId() {
-		return node.getResolvedId();
-	}
-
-	public void updateConfsToFetch(Collection confs) {
-		node.updateConfsToFetch(confs);
-	}
-
-	public ModuleRevisionId getId() {
-		return node.getId();
-	}
-
-	public boolean isEvicted() {
-		return node.isEvicted(rootModuleConf);
-	}
-
-	public String[] getRealConfs(String conf) {
-		return node.getRealConfs(conf);
-	}
-
-	public boolean hasProblem() {
-		return node.hasProblem();
-	}
-
-	public Configuration getConfiguration(String conf) {
-		return node.getConfiguration(conf);
-	}
-
-	public EvictionData getEvictedData() {
-		return node.getEvictedData(rootModuleConf);
-	}
-
-	public DependencyDescriptor getDependencyDescriptor() {
-		return node.getDependencyDescriptor(getParentNode());
-	}
-
-	private IvyNode getParentNode() {
-		return parent ==null?null: parent.getNode();
-	}
+    VisitNode gotoNode(IvyNode node) {
+        if (!getModuleId().equals(node.getModuleId())) {
+            throw new IllegalArgumentException(
+                    "you can't use gotoNode for a node which does not represent the same Module as the one represented by this node.\nCurrent node module id="
+                            + getModuleId() + " Given node module id=" + node.getModuleId());
+        }
+        VisitData visitData = data.getVisitData(node.getId());
+        if (visitData == null) {
+            throw new IllegalArgumentException(
+                    "you can't use gotoNode with a node which has not been visited yet.\nGiven node id="
+                            + node.getId());
+        }
+        for (Iterator iter = visitData.getVisitNodes(rootModuleConf).iterator(); iter.hasNext();) {
+            VisitNode vnode = (VisitNode) iter.next();
+            if ((parent == null && vnode.getParent() == null)
+                    || (parent != null && parent.getId().equals(vnode.getParent().getId()))) {
+                return vnode;
+            }
+        }
+        // the node has not yet been visited from the current parent, we create a new visit node
+        return traverse(parent, parentConf, node);
+    }
+
+    private VisitNode traverseChild(String parentConf, IvyNode child) {
+        VisitNode parent = this;
+        return traverse(parent, parentConf, child);
+    }
+
+    private VisitNode traverse(VisitNode parent, String parentConf, IvyNode node) {
+        if (getPath().contains(node)) {
+            IvyContext.getContext().getCircularDependencyStrategy().handleCircularDependency(
+                toMrids(getPath(), node.getId()));
+            // we do not use the new parent, but the first one, to always be able to go up to the
+            // root
+            // parent = getVisitNode(depNode).getParent();
+        }
+        return new VisitNode(data, node, parent, rootModuleConf, parentConf);
+    }
+
+    private ModuleRevisionId[] toMrids(Collection path, ModuleRevisionId last) {
+        ModuleRevisionId[] ret = new ModuleRevisionId[path.size() + 1];
+        int i = 0;
+        for (Iterator iter = path.iterator(); iter.hasNext(); i++) {
+            VisitNode node = (VisitNode) iter.next();
+            ret[i] = node.getNode().getId();
+        }
+        ret[ret.length - 1] = last;
+        return ret;
+    }
 
+    public ModuleRevisionId getResolvedId() {
+        return node.getResolvedId();
+    }
+
+    public void updateConfsToFetch(Collection confs) {
+        node.updateConfsToFetch(confs);
+    }
+
+    public ModuleRevisionId getId() {
+        return node.getId();
+    }
+
+    public boolean isEvicted() {
+        return node.isEvicted(rootModuleConf);
+    }
+
+    public String[] getRealConfs(String conf) {
+        return node.getRealConfs(conf);
+    }
+
+    public boolean hasProblem() {
+        return node.hasProblem();
+    }
+
+    public Configuration getConfiguration(String conf) {
+        return node.getConfiguration(conf);
+    }
+
+    public EvictionData getEvictedData() {
+        return node.getEvictedData(rootModuleConf);
+    }
+
+    public DependencyDescriptor getDependencyDescriptor() {
+        return node.getDependencyDescriptor(getParentNode());
+    }
+
+    private IvyNode getParentNode() {
+        return parent == null ? null : parent.getNode();
+    }
 
     /**
      * Returns true if this node can already be found in the path
+     * 
      * @return
      */
     public boolean isCircular() {
-    	if (isCircular == null) {
+        if (isCircular == null) {
             if (parent != null) {
-            	isCircular = Boolean.FALSE; // asumme it's false, and see if it isn't by checking the parent path
+                isCircular = Boolean.FALSE; // asumme it's false, and see if it isn't by checking
+                // the parent path
                 for (Iterator iter = parent.getPath().iterator(); iter.hasNext();) {
-    				VisitNode ancestor = (VisitNode) iter.next();
-    				if (getId().getModuleId().equals(ancestor.getId().getModuleId())) {
-    					isCircular = Boolean.TRUE;
-    					break;
-    				}
-    			}
+                    VisitNode ancestor = (VisitNode) iter.next();
+                    if (getId().getModuleId().equals(ancestor.getId().getModuleId())) {
+                        isCircular = Boolean.TRUE;
+                        break;
+                    }
+                }
             } else {
-				isCircular = Boolean.FALSE;
+                isCircular = Boolean.FALSE;
             }
-    	}
-    	return isCircular.booleanValue();
+        }
+        return isCircular.booleanValue();
+    }
+
+    public String[] getConfsToFetch() {
+        return node.getConfsToFetch();
     }
 
-	public String[] getConfsToFetch() {
-		return node.getConfsToFetch();
-	}
-
-	public String[] getRequiredConfigurations(VisitNode in, String inConf) {
-		return node.getRequiredConfigurations(in.getNode(), inConf);
-	}
-
-	public ModuleId getModuleId() {
-		return node.getModuleId();
-	}
-
-	public Collection getResolvedRevisions(ModuleId mid) {
-		return node.getResolvedRevisions(mid, rootModuleConf);
-	}
-
-	public void markEvicted(EvictionData evictionData) {
-		node.markEvicted(evictionData);
-	}
-
-	public String[] getRequiredConfigurations() {
-		return node.getRequiredConfigurations();
-	}
-
-	/**
-	 * Marks the current node as evicted by the the given selected IvyNodes, 
-	 * in the given parent and root module configuration, with the given
-	 * {@link ConflictManager}
-	 * 
-	 * @param parent the VisitNode in which eviction has been made
-	 * @param conflictManager the conflict manager responsible for the eviction
-	 * @param selected a Collection of {@link IvyNode} which have been selected 
-	 */
-	public void markEvicted(VisitNode parent, ConflictManager conflictManager, Collection selected) {
-		node.markEvicted(rootModuleConf, parent.getNode(), conflictManager, selected);
-	}
-
-	public ModuleDescriptor getDescriptor() {
-		return node.getDescriptor();
-	}
-
-	public EvictionData getEvictionDataInRoot(String rootModuleConf, VisitNode ancestor) {
-		return node.getEvictionDataInRoot(rootModuleConf, ancestor.getNode());
-	}
-
-	public Collection getEvictedRevisions(ModuleId moduleId) {
-		return node.getEvictedRevisions(moduleId, rootModuleConf);
-	}
-
-
-//    public void setRootModuleConf(String rootModuleConf) {
-//        if (rootModuleConf != null && !rootModuleConf.equals(rootModuleConf)) {
-//            _confsToFetch.clear(); // we change of root module conf => we discard all confs to fetch
-//        }
-//        if (rootModuleConf != null && rootModuleConf.equals(rootModuleConf)) {
-//            _selectedDeps.put(new ModuleIdConf(_id.getModuleId(), rootModuleConf), Collections.singleton(this));
-//        }
-//        rootModuleConf = rootModuleConf;
-//    }
-
-	public String toString() {
-		return node.toString();
-	}
+    public String[] getRequiredConfigurations(VisitNode in, String inConf) {
+        return node.getRequiredConfigurations(in.getNode(), inConf);
+    }
+
+    public ModuleId getModuleId() {
+        return node.getModuleId();
+    }
+
+    public Collection getResolvedRevisions(ModuleId mid) {
+        return node.getResolvedRevisions(mid, rootModuleConf);
+    }
+
+    public void markEvicted(EvictionData evictionData) {
+        node.markEvicted(evictionData);
+    }
+
+    public String[] getRequiredConfigurations() {
+        return node.getRequiredConfigurations();
+    }
+
+    /**
+     * Marks the current node as evicted by the the given selected IvyNodes, in the given parent and
+     * root module configuration, with the given {@link ConflictManager}
+     * 
+     * @param parent
+     *            the VisitNode in which eviction has been made
+     * @param conflictManager
+     *            the conflict manager responsible for the eviction
+     * @param selected
+     *            a Collection of {@link IvyNode} which have been selected
+     */
+    public void markEvicted(VisitNode parent, ConflictManager conflictManager, Collection selected) {
+        node.markEvicted(rootModuleConf, parent.getNode(), conflictManager, selected);
+    }
+
+    public ModuleDescriptor getDescriptor() {
+        return node.getDescriptor();
+    }
+
+    public EvictionData getEvictionDataInRoot(String rootModuleConf, VisitNode ancestor) {
+        return node.getEvictionDataInRoot(rootModuleConf, ancestor.getNode());
+    }
+
+    public Collection getEvictedRevisions(ModuleId moduleId) {
+        return node.getEvictedRevisions(moduleId, rootModuleConf);
+    }
+
+    // public void setRootModuleConf(String rootModuleConf) {
+    // if (rootModuleConf != null && !rootModuleConf.equals(rootModuleConf)) {
+    // _confsToFetch.clear(); // we change of root module conf => we discard all confs to fetch
+    // }
+    // if (rootModuleConf != null && rootModuleConf.equals(rootModuleConf)) {
+    // _selectedDeps.put(new ModuleIdConf(_id.getModuleId(), rootModuleConf),
+    // Collections.singleton(this));
+    // }
+    // rootModuleConf = rootModuleConf;
+    // }
+
+    public String toString() {
+        return node.toString();
+    }
 
 }

Modified: incubator/ivy/core/trunk/src/java/org/apache/ivy/core/retrieve/RetrieveEngine.java
URL: http://svn.apache.org/viewvc/incubator/ivy/core/trunk/src/java/org/apache/ivy/core/retrieve/RetrieveEngine.java?view=diff&rev=544459&r1=544458&r2=544459
==============================================================================
--- incubator/ivy/core/trunk/src/java/org/apache/ivy/core/retrieve/RetrieveEngine.java (original)
+++ incubator/ivy/core/trunk/src/java/org/apache/ivy/core/retrieve/RetrieveEngine.java Tue Jun  5 05:02:27 2007
@@ -51,66 +51,72 @@
 import org.apache.ivy.util.Message;
 
 public class RetrieveEngine {
-	private IvySettings settings;
-	
-	public RetrieveEngine(IvySettings settings) {
-		this.settings = settings;
-	}
-	
-	/**
-     * example of destFilePattern :
-     * - lib/[organisation]/[module]/[artifact]-[revision].[type]
-     * - lib/[artifact].[type] : flatten with no revision
-     * moduleId is used with confs and localCacheDirectory to determine
-     * an ivy report file, used as input for the copy
-     * If such a file does not exist for any conf (resolve has not been called before ?)
-     * then an IllegalStateException is thrown and nothing is copied.
-     * 
+    private IvySettings settings;
+
+    public RetrieveEngine(IvySettings settings) {
+        this.settings = settings;
+    }
+
+    /**
+     * example of destFilePattern : - lib/[organisation]/[module]/[artifact]-[revision].[type] -
+     * lib/[artifact].[type] : flatten with no revision moduleId is used with confs and
+     * localCacheDirectory to determine an ivy report file, used as input for the copy If such a
+     * file does not exist for any conf (resolve has not been called before ?) then an
+     * IllegalStateException is thrown and nothing is copied.
      */
-    public int retrieve(ModuleRevisionId mrid, String destFilePattern, RetrieveOptions options) throws IOException {
-    	ModuleId moduleId = mrid.getModuleId();
-        Message.info(":: retrieving :: "+moduleId+(options.isSync()?" [sync]":""));
-        Message.verbose("\tcheckUpToDate="+ settings.isCheckUpToDate());
+    public int retrieve(ModuleRevisionId mrid, String destFilePattern, RetrieveOptions options)
+            throws IOException {
+        ModuleId moduleId = mrid.getModuleId();
+        Message.info(":: retrieving :: " + moduleId + (options.isSync() ? " [sync]" : ""));
+        Message.verbose("\tcheckUpToDate=" + settings.isCheckUpToDate());
         long start = System.currentTimeMillis();
-        
-        destFilePattern = IvyPatternHelper.substituteVariables(destFilePattern, settings.getVariables());
-        String destIvyPattern = IvyPatternHelper.substituteVariables(options.getDestIvyPattern(), settings.getVariables());
-        
+
+        destFilePattern = IvyPatternHelper.substituteVariables(destFilePattern, settings
+                .getVariables());
+        String destIvyPattern = IvyPatternHelper.substituteVariables(options.getDestIvyPattern(),
+            settings.getVariables());
+
         CacheManager cacheManager = getCacheManager(options);
         String[] confs = getConfs(mrid, options);
-        Message.info("\tconfs: "+Arrays.asList(confs));
+        Message.info("\tconfs: " + Arrays.asList(confs));
 
         try {
             Map artifactsToCopy = determineArtifactsToCopy(mrid, destFilePattern, options);
             File fileRetrieveRoot = new File(IvyPatternHelper.getTokenRoot(destFilePattern));
-            File ivyRetrieveRoot = destIvyPattern == null ? null : new File(IvyPatternHelper.getTokenRoot(destIvyPattern));
-            Collection targetArtifactsStructure = new HashSet(); // Set(File) set of all paths which should be present at then end of retrieve (useful for sync) 
+            File ivyRetrieveRoot = destIvyPattern == null ? null : new File(IvyPatternHelper
+                    .getTokenRoot(destIvyPattern));
+            Collection targetArtifactsStructure = new HashSet(); // Set(File) set of all paths
+            // which should be present at
+            // then end of retrieve (useful
+            // for sync)
             Collection targetIvysStructure = new HashSet(); // same for ivy files
-            
+
             // do retrieve
             int targetsCopied = 0;
             int targetsUpToDate = 0;
             for (Iterator iter = artifactsToCopy.keySet().iterator(); iter.hasNext();) {
-                Artifact artifact = (Artifact)iter.next();
+                Artifact artifact = (Artifact) iter.next();
                 File archive;
-				if ("ivy".equals(artifact.getType())) {
-					archive = cacheManager.getIvyFileInCache(artifact.getModuleRevisionId());
-				} else {
-					archive = cacheManager.getArchiveFileInCache(artifact, 
-							cacheManager.getSavedArtifactOrigin(artifact), options.isUseOrigin());
-					if (!options.isUseOrigin() && !archive.exists()) {
-						// file is not available in cache, maybe the last resolve was performed with useOrigin=true.
-						// we try to use the best we can
-						archive = cacheManager.getArchiveFileInCache(artifact, cacheManager.getSavedArtifactOrigin(artifact));
-					}
-				}
-                Set dest = (Set)artifactsToCopy.get(artifact);
-                Message.verbose("\tretrieving "+archive);
+                if ("ivy".equals(artifact.getType())) {
+                    archive = cacheManager.getIvyFileInCache(artifact.getModuleRevisionId());
+                } else {
+                    archive = cacheManager.getArchiveFileInCache(artifact, cacheManager
+                            .getSavedArtifactOrigin(artifact), options.isUseOrigin());
+                    if (!options.isUseOrigin() && !archive.exists()) {
+                        // file is not available in cache, maybe the last resolve was performed with
+                        // useOrigin=true.
+                        // we try to use the best we can
+                        archive = cacheManager.getArchiveFileInCache(artifact, cacheManager
+                                .getSavedArtifactOrigin(artifact));
+                    }
+                }
+                Set dest = (Set) artifactsToCopy.get(artifact);
+                Message.verbose("\tretrieving " + archive);
                 for (Iterator it2 = dest.iterator(); it2.hasNext();) {
-                	IvyContext.getContext().checkInterrupted();
-                    File destFile = new File((String)it2.next());
+                    IvyContext.getContext().checkInterrupted();
+                    File destFile = new File((String) it2.next());
                     if (!settings.isCheckUpToDate() || !upToDate(archive, destFile)) {
-                        Message.verbose("\t\tto "+destFile);
+                        Message.verbose("\t\tto " + destFile);
                         if (options.isMakeSymlinks()) {
                             FileUtil.symlink(archive, destFile, null, true);
                         } else {
@@ -118,120 +124,134 @@
                         }
                         targetsCopied++;
                     } else {
-                        Message.verbose("\t\tto "+destFile+" [NOT REQUIRED]");
+                        Message.verbose("\t\tto " + destFile + " [NOT REQUIRED]");
                         targetsUpToDate++;
                     }
                     if ("ivy".equals(artifact.getType())) {
-                    	targetIvysStructure.addAll(FileUtil.getPathFiles(ivyRetrieveRoot, destFile));
+                        targetIvysStructure
+                                .addAll(FileUtil.getPathFiles(ivyRetrieveRoot, destFile));
                     } else {
-                    	targetArtifactsStructure.addAll(FileUtil.getPathFiles(fileRetrieveRoot, destFile));
+                        targetArtifactsStructure.addAll(FileUtil.getPathFiles(fileRetrieveRoot,
+                            destFile));
                     }
                 }
             }
-            
+
             if (options.isSync()) {
-				Message.verbose("\tsyncing...");
+                Message.verbose("\tsyncing...");
                 Collection existingArtifacts = FileUtil.listAll(fileRetrieveRoot);
-                Collection existingIvys = ivyRetrieveRoot == null ? null : FileUtil.listAll(ivyRetrieveRoot);
+                Collection existingIvys = ivyRetrieveRoot == null ? null : FileUtil
+                        .listAll(ivyRetrieveRoot);
 
                 if (fileRetrieveRoot.equals(ivyRetrieveRoot)) {
-                	Collection target = targetArtifactsStructure;
-                	target.addAll(targetIvysStructure);
-                	Collection existing = existingArtifacts;
-                	existing.addAll(existingIvys);
-                	sync(target, existing);
+                    Collection target = targetArtifactsStructure;
+                    target.addAll(targetIvysStructure);
+                    Collection existing = existingArtifacts;
+                    existing.addAll(existingIvys);
+                    sync(target, existing);
                 } else {
-                	sync(targetArtifactsStructure, existingArtifacts);
-                	if (existingIvys != null) {
-                		sync(targetIvysStructure, existingIvys);
-                	}
+                    sync(targetArtifactsStructure, existingArtifacts);
+                    if (existingIvys != null) {
+                        sync(targetIvysStructure, existingIvys);
+                    }
                 }
             }
-            Message.info("\t"+targetsCopied+" artifacts copied"+(settings.isCheckUpToDate()?(", "+targetsUpToDate+" already retrieved"):""));
-            Message.verbose("\tretrieve done ("+(System.currentTimeMillis()-start)+"ms)");
-            
+            Message.info("\t"
+                    + targetsCopied
+                    + " artifacts copied"
+                    + (settings.isCheckUpToDate() ? (", " + targetsUpToDate + " already retrieved")
+                            : ""));
+            Message.verbose("\tretrieve done (" + (System.currentTimeMillis() - start) + "ms)");
+
             return targetsCopied;
         } catch (Exception ex) {
-            throw new RuntimeException("problem during retrieve of "+moduleId+": "+ex, ex);
+            throw new RuntimeException("problem during retrieve of " + moduleId + ": " + ex, ex);
         }
     }
 
-	private String[] getConfs(ModuleRevisionId mrid, RetrieveOptions options) throws IOException {
-		String[] confs = options.getConfs();
+    private String[] getConfs(ModuleRevisionId mrid, RetrieveOptions options) throws IOException {
+        String[] confs = options.getConfs();
         if (confs == null || (confs.length == 1 && "*".equals(confs[0]))) {
-        	try {
-        		File ivyFile = options.getCache().getResolvedIvyFileInCache(mrid);
-        		Message.verbose("no explicit confs given for retrieve, using ivy file: "+ivyFile);
-        		URL ivySource = ivyFile.toURL();
-        		URLResource res = new URLResource(ivySource);
-        		ModuleDescriptorParser parser = ModuleDescriptorParserRegistry.getInstance().getParser(res);
-        		Message.debug("using "+parser+" to parse "+ivyFile);
-        		ModuleDescriptor md = parser.parseDescriptor(settings, ivySource, false);
-        		confs = md.getConfigurationsNames();
-        		options.setConfs(confs);
-        	} catch (IOException e) {
-        		throw e;
-        	} catch (Exception e) {
-        		IOException ioex = new IOException(e.getMessage());
-        		ioex.initCause(e);
-				throw ioex;
-        	}        
+            try {
+                File ivyFile = options.getCache().getResolvedIvyFileInCache(mrid);
+                Message.verbose("no explicit confs given for retrieve, using ivy file: " + ivyFile);
+                URL ivySource = ivyFile.toURL();
+                URLResource res = new URLResource(ivySource);
+                ModuleDescriptorParser parser = ModuleDescriptorParserRegistry.getInstance()
+                        .getParser(res);
+                Message.debug("using " + parser + " to parse " + ivyFile);
+                ModuleDescriptor md = parser.parseDescriptor(settings, ivySource, false);
+                confs = md.getConfigurationsNames();
+                options.setConfs(confs);
+            } catch (IOException e) {
+                throw e;
+            } catch (Exception e) {
+                IOException ioex = new IOException(e.getMessage());
+                ioex.initCause(e);
+                throw ioex;
+            }
         }
-		return confs;
-	}
+        return confs;
+    }
 
-	private CacheManager getCacheManager(RetrieveOptions options) {
-		CacheManager cacheManager = options.getCache();
-        if (cacheManager == null) {  // ensure that a cache is configured
-        	cacheManager = IvyContext.getContext().getCacheManager();
-        	options.setCache(cacheManager);
+    private CacheManager getCacheManager(RetrieveOptions options) {
+        CacheManager cacheManager = options.getCache();
+        if (cacheManager == null) { // ensure that a cache is configured
+            cacheManager = IvyContext.getContext().getCacheManager();
+            options.setCache(cacheManager);
         } else {
-        	IvyContext.getContext().setCache(cacheManager.getCache());
+            IvyContext.getContext().setCache(cacheManager.getCache());
+        }
+        return cacheManager;
+    }
+
+    private void sync(Collection target, Collection existing) {
+        Collection toRemove = new HashSet();
+        for (Iterator iter = existing.iterator(); iter.hasNext();) {
+            File file = (File) iter.next();
+            toRemove.add(file.getAbsoluteFile());
+        }
+        for (Iterator iter = target.iterator(); iter.hasNext();) {
+            File file = (File) iter.next();
+            toRemove.remove(file.getAbsoluteFile());
+        }
+        for (Iterator iter = toRemove.iterator(); iter.hasNext();) {
+            File file = (File) iter.next();
+            if (file.exists()) {
+                Message.verbose("\t\tdeleting " + file);
+                FileUtil.forceDelete(file);
+            }
+        }
+    }
+
+    public Map determineArtifactsToCopy(ModuleRevisionId mrid, String destFilePattern,
+            RetrieveOptions options) throws ParseException, IOException {
+        ModuleId moduleId = mrid.getModuleId();
+
+        if (options.getResolveId() == null) {
+            options.setResolveId(ResolveOptions.getDefaultResolveId(moduleId));
         }
-		return cacheManager;
-	}
 
-	private void sync(Collection target, Collection existing) {
-		Collection toRemove = new HashSet();
-		for (Iterator iter = existing.iterator(); iter.hasNext();) {
-			File file = (File) iter.next();
-			toRemove.add(file.getAbsoluteFile());
-		}
-		for (Iterator iter = target.iterator(); iter.hasNext();) {
-			File file = (File) iter.next();
-			toRemove.remove(file.getAbsoluteFile());
-		}
-		for (Iterator iter = toRemove.iterator(); iter.hasNext();) {
-			File file = (File) iter.next();
-			if (file.exists()) {
-				Message.verbose("\t\tdeleting "+file);
-				FileUtil.forceDelete(file);
-			}
-		}
-	}
-
-	public Map determineArtifactsToCopy(ModuleRevisionId mrid, String destFilePattern, RetrieveOptions options) throws ParseException, IOException {
-		ModuleId moduleId = mrid.getModuleId();
-		
-		if (options.getResolveId() == null) {
-			options.setResolveId(ResolveOptions.getDefaultResolveId(moduleId));
-		}
-		
         CacheManager cacheManager = getCacheManager(options);
         String[] confs = getConfs(mrid, options);
-        String destIvyPattern = IvyPatternHelper.substituteVariables(options.getDestIvyPattern(), settings.getVariables());
-        
+        String destIvyPattern = IvyPatternHelper.substituteVariables(options.getDestIvyPattern(),
+            settings.getVariables());
+
         // find what we must retrieve where
-        final Map artifactsToCopy = new HashMap(); // Artifact source -> Set (String copyDestAbsolutePath)
-        final Map conflictsMap = new HashMap(); // String copyDestAbsolutePath -> Set (Artifact source)
-        final Map conflictsConfMap = new HashMap(); // String copyDestAbsolutePath -> Set (String conf)
+        final Map artifactsToCopy = new HashMap(); // Artifact source -> Set (String
+        // copyDestAbsolutePath)
+        final Map conflictsMap = new HashMap(); // String copyDestAbsolutePath -> Set (Artifact
+        // source)
+        final Map conflictsConfMap = new HashMap(); // String copyDestAbsolutePath -> Set (String
+        // conf)
         XmlReportParser parser = new XmlReportParser();
         for (int i = 0; i < confs.length; i++) {
             final String conf = confs[i];
 
-            File report = cacheManager.getConfigurationResolveReportInCache(options.getResolveId(), conf);
+            File report = cacheManager.getConfigurationResolveReportInCache(options.getResolveId(),
+                conf);
             parser.parse(report);
-        	
+
             Collection artifacts = new ArrayList(Arrays.asList(parser.getArtifacts()));
             if (destIvyPattern != null) {
                 ModuleRevisionId[] mrids = parser.getRealDependencyRevisionIds();
@@ -240,25 +260,27 @@
                 }
             }
             for (Iterator iter = artifacts.iterator(); iter.hasNext();) {
-                Artifact artifact = (Artifact)iter.next();
-                String destPattern = "ivy".equals(artifact.getType()) ? destIvyPattern: destFilePattern;
-                
-                if (!"ivy".equals(artifact.getType()) && !options.getArtifactFilter().accept(artifact)) {
-                	continue;	// skip this artifact, the filter didn't accept it!
+                Artifact artifact = (Artifact) iter.next();
+                String destPattern = "ivy".equals(artifact.getType()) ? destIvyPattern
+                        : destFilePattern;
+
+                if (!"ivy".equals(artifact.getType())
+                        && !options.getArtifactFilter().accept(artifact)) {
+                    continue; // skip this artifact, the filter didn't accept it!
                 }
-                
+
                 String destFileName = IvyPatternHelper.substitute(destPattern, artifact, conf);
-                
-                Set dest = (Set)artifactsToCopy.get(artifact);
+
+                Set dest = (Set) artifactsToCopy.get(artifact);
                 if (dest == null) {
                     dest = new HashSet();
                     artifactsToCopy.put(artifact, dest);
                 }
                 String copyDest = new File(destFileName).getAbsolutePath();
                 dest.add(copyDest);
-                
-                Set conflicts = (Set)conflictsMap.get(copyDest);
-                Set conflictsConf = (Set)conflictsConfMap.get(copyDest);
+
+                Set conflicts = (Set) conflictsMap.get(copyDest);
+                Set conflictsConf = (Set) conflictsConfMap.get(copyDest);
                 if (conflicts == null) {
                     conflicts = new HashSet();
                     conflictsMap.put(copyDest, conflicts);
@@ -271,27 +293,35 @@
                 conflictsConf.add(conf);
             }
         }
-        
+
         // resolve conflicts if any
         for (Iterator iter = conflictsMap.keySet().iterator(); iter.hasNext();) {
-            String copyDest = (String)iter.next();
-            Set artifacts = (Set)conflictsMap.get(copyDest);
-            Set conflictsConfs = (Set)conflictsConfMap.get(copyDest);
+            String copyDest = (String) iter.next();
+            Set artifacts = (Set) conflictsMap.get(copyDest);
+            Set conflictsConfs = (Set) conflictsConfMap.get(copyDest);
             if (artifacts.size() > 1) {
                 List artifactsList = new ArrayList(artifacts);
-                // conflicts battle is resolved by a sort using a conflict resolving policy comparator
+                // conflicts battle is resolved by a sort using a conflict resolving policy
+                // comparator
                 // which consider as greater a winning artifact
                 Collections.sort(artifactsList, getConflictResolvingPolicy());
                 // after the sort, the winning artifact is the greatest one, i.e. the last one
-                Message.info("\tconflict on "+copyDest+" in "+conflictsConfs+": "+((Artifact)artifactsList.get(artifactsList.size() -1)).getModuleRevisionId().getRevision()+" won");
-                
+                Message.info("\tconflict on "
+                        + copyDest
+                        + " in "
+                        + conflictsConfs
+                        + ": "
+                        + ((Artifact) artifactsList.get(artifactsList.size() - 1))
+                                .getModuleRevisionId().getRevision() + " won");
+
                 // we now iterate over the list beginning with the artifact preceding the winner,
                 // and going backward to the least artifact
-                for (int i=artifactsList.size() - 2; i >=0; i--) {
-                    Artifact looser = (Artifact)artifactsList.get(i);
-                    Message.verbose("\t\tremoving conflict looser artifact: "+looser);
-                    // for each loser, we remove the pair (loser - copyDest) in the artifactsToCopy map
-                    Set dest = (Set)artifactsToCopy.get(looser);
+                for (int i = artifactsList.size() - 2; i >= 0; i--) {
+                    Artifact looser = (Artifact) artifactsList.get(i);
+                    Message.verbose("\t\tremoving conflict looser artifact: " + looser);
+                    // for each loser, we remove the pair (loser - copyDest) in the artifactsToCopy
+                    // map
+                    Set dest = (Set) artifactsToCopy.get(looser);
                     dest.remove(copyDest);
                     if (dest.isEmpty()) {
                         artifactsToCopy.remove(looser);
@@ -301,7 +331,7 @@
         }
         return artifactsToCopy;
     }
-    
+
     private boolean upToDate(File source, File target) {
         if (!target.exists()) {
             return false;
@@ -310,18 +340,17 @@
     }
 
     /**
-     * The returned comparator should consider greater the artifact which
-     * gains the conflict battle.
-     * This is used only during retrieve... prefer resolve conflict manager
-     * to resolve conflicts.
+     * The returned comparator should consider greater the artifact which gains the conflict battle.
+     * This is used only during retrieve... prefer resolve conflict manager to resolve conflicts.
+     * 
      * @return
      */
     private Comparator getConflictResolvingPolicy() {
         return new Comparator() {
             // younger conflict resolving policy
             public int compare(Object o1, Object o2) {
-                Artifact a1 = (Artifact)o1;
-                Artifact a2 = (Artifact)o2;
+                Artifact a1 = (Artifact) o1;
+                Artifact a2 = (Artifact) o2;
                 if (a1.getPublicationDate().after(a2.getPublicationDate())) {
                     // a1 is after a2 <=> a1 is younger than a2 <=> a1 wins the conflict battle
                     return +1;
@@ -334,6 +363,5 @@
             }
         };
     }
-
 
 }

Modified: incubator/ivy/core/trunk/src/java/org/apache/ivy/core/retrieve/RetrieveOptions.java
URL: http://svn.apache.org/viewvc/incubator/ivy/core/trunk/src/java/org/apache/ivy/core/retrieve/RetrieveOptions.java?view=diff&rev=544459&r1=544458&r2=544459
==============================================================================
--- incubator/ivy/core/trunk/src/java/org/apache/ivy/core/retrieve/RetrieveOptions.java (original)
+++ incubator/ivy/core/trunk/src/java/org/apache/ivy/core/retrieve/RetrieveOptions.java Tue Jun  5 05:02:27 2007
@@ -27,110 +27,122 @@
  * @see RetrieveEngine
  */
 public class RetrieveOptions {
-	/**
-	 * The names of configurations to retrieve.
-	 * If the array consists only of '*', then all configurations of 
-	 * the module will be retrieved.
-	 */
-	private String[] confs = new String[] {"*"};
-	
-	/**
-	 * The cache manager to retrieve files from.
-	 * If null, the default cache manager of the current Ivy instance will be used.
-	 */
-	private CacheManager cache = null;
-	
-	/**
-	 * The pattern to which ivy files should be retrieved. 
-	 * If destIvyPattern is null no ivy files will be copied.
-	 */
-	private String destIvyPattern = null;
-	
-	/**
-	 * The filter to apply before retrieving artifacts.
-	 */
-	private Filter artifactFilter = FilterHelper.NO_FILTER;
-	
-	/**
-	 * True if a synchronisation of the destination directory should be done,
-	 * false if a simple copy is enough.
-	 * Synchronisation means that after the retrieve only files which have been
-	 * retrieved will be present in the destination directory, which means 
-	 * that some files may be deleted.
-	 */
-	private boolean sync = false;
-	/**
-	 * True if the original files should be used insteaad of their cache copy.
-	 */
-	private boolean useOrigin = false;
-	
-	/**
-	 * True if symbolic links should be created instead of plain copy.
-	 * Works only on OS supporting symbolic links.
-	 */
-	private boolean makeSymlinks = false;
-	
-	/**
-	 * The id used to store the resolve information.
-	 */
-	private String resolveId;
-
-	
-	public Filter getArtifactFilter() {
-		return artifactFilter;
-	}
-	public RetrieveOptions setArtifactFilter(Filter artifactFilter) {
-		this.artifactFilter = artifactFilter;
-		return this;
-	}
-	public CacheManager getCache() {
-		return cache;
-	}
-	public RetrieveOptions setCache(CacheManager cacheManager) {
-		this.cache = cacheManager;
-		return this;
-	}
-	public String[] getConfs() {
-		return confs;
-	}
-	public RetrieveOptions setConfs(String[] confs) {
-		this.confs = confs;
-		return this;
-	}
-	public String getDestIvyPattern() {
-		return destIvyPattern;
-	}
-	public RetrieveOptions setDestIvyPattern(String destIvyPattern) {
-		this.destIvyPattern = destIvyPattern;
-		return this;
-	}
-	public boolean isMakeSymlinks() {
-		return makeSymlinks;
-	}
-	public RetrieveOptions setMakeSymlinks(boolean makeSymlinks) {
-		this.makeSymlinks = makeSymlinks;
-		return this;
-	}
-	public boolean isSync() {
-		return sync;
-	}
-	public RetrieveOptions setSync(boolean sync) {
-		this.sync = sync;
-		return this;
-	}
-	public boolean isUseOrigin() {
-		return useOrigin;
-	}
-	public RetrieveOptions setUseOrigin(boolean useOrigin) {
-		this.useOrigin = useOrigin;
-		return this;
-	}
-	public String getResolveId() {
-		return resolveId;
-	}
-	public RetrieveOptions setResolveId(String resolveId) {
-		this.resolveId = resolveId;
-		return this;
-	}
-	
+    /**
+     * The names of configurations to retrieve. If the array consists only of '*', then all
+     * configurations of the module will be retrieved.
+     */
+    private String[] confs = new String[] {"*"};
+
+    /**
+     * The cache manager to retrieve files from. If null, the default cache manager of the current
+     * Ivy instance will be used.
+     */
+    private CacheManager cache = null;
+
+    /**
+     * The pattern to which ivy files should be retrieved. If destIvyPattern is null no ivy files
+     * will be copied.
+     */
+    private String destIvyPattern = null;
+
+    /**
+     * The filter to apply before retrieving artifacts.
+     */
+    private Filter artifactFilter = FilterHelper.NO_FILTER;
+
+    /**
+     * True if a synchronisation of the destination directory should be done, false if a simple copy
+     * is enough. Synchronisation means that after the retrieve only files which have been retrieved
+     * will be present in the destination directory, which means that some files may be deleted.
+     */
+    private boolean sync = false;
+
+    /**
+     * True if the original files should be used insteaad of their cache copy.
+     */
+    private boolean useOrigin = false;
+
+    /**
+     * True if symbolic links should be created instead of plain copy. Works only on OS supporting
+     * symbolic links.
+     */
+    private boolean makeSymlinks = false;
+
+    /**
+     * The id used to store the resolve information.
+     */
+    private String resolveId;
+
+    public Filter getArtifactFilter() {
+        return artifactFilter;
+    }
+
+    public RetrieveOptions setArtifactFilter(Filter artifactFilter) {
+        this.artifactFilter = artifactFilter;
+        return this;
+    }
+
+    public CacheManager getCache() {
+        return cache;
+    }
+
+    public RetrieveOptions setCache(CacheManager cacheManager) {
+        this.cache = cacheManager;
+        return this;
+    }
+
+    public String[] getConfs() {
+        return confs;
+    }
+
+    public RetrieveOptions setConfs(String[] confs) {
+        this.confs = confs;
+        return this;
+    }
+
+    public String getDestIvyPattern() {
+        return destIvyPattern;
+    }
+
+    public RetrieveOptions setDestIvyPattern(String destIvyPattern) {
+        this.destIvyPattern = destIvyPattern;
+        return this;
+    }
+
+    public boolean isMakeSymlinks() {
+        return makeSymlinks;
+    }
+
+    public RetrieveOptions setMakeSymlinks(boolean makeSymlinks) {
+        this.makeSymlinks = makeSymlinks;
+        return this;
+    }
+
+    public boolean isSync() {
+        return sync;
+    }
+
+    public RetrieveOptions setSync(boolean sync) {
+        this.sync = sync;
+        return this;
+    }
+
+    public boolean isUseOrigin() {
+        return useOrigin;
+    }
+
+    public RetrieveOptions setUseOrigin(boolean useOrigin) {
+        this.useOrigin = useOrigin;
+        return this;
+    }
+
+    public String getResolveId() {
+        return resolveId;
+    }
+
+    public RetrieveOptions setResolveId(String resolveId) {
+        this.resolveId = resolveId;
+        return this;
+    }
+
 }

Modified: incubator/ivy/core/trunk/src/java/org/apache/ivy/core/search/ModuleEntry.java
URL: http://svn.apache.org/viewvc/incubator/ivy/core/trunk/src/java/org/apache/ivy/core/search/ModuleEntry.java?view=diff&rev=544459&r1=544458&r2=544459
==============================================================================
--- incubator/ivy/core/trunk/src/java/org/apache/ivy/core/search/ModuleEntry.java (original)
+++ incubator/ivy/core/trunk/src/java/org/apache/ivy/core/search/ModuleEntry.java Tue Jun  5 05:02:27 2007
@@ -19,10 +19,9 @@
 
 import org.apache.ivy.plugins.resolver.DependencyResolver;
 
-
-
 public class ModuleEntry {
     private OrganisationEntry organisationEntry;
+
     private String module;
 
     public ModuleEntry(OrganisationEntry org, String name) {
@@ -33,7 +32,7 @@
     public String getOrganisation() {
         return organisationEntry.getOrganisation();
     }
-    
+
     public DependencyResolver getResolver() {
         return organisationEntry.getResolver();
     }
@@ -41,10 +40,9 @@
     public String getModule() {
         return module;
     }
-    
 
     public OrganisationEntry getOrganisationEntry() {
         return organisationEntry;
     }
-    
+
 }

Modified: incubator/ivy/core/trunk/src/java/org/apache/ivy/core/search/OrganisationEntry.java
URL: http://svn.apache.org/viewvc/incubator/ivy/core/trunk/src/java/org/apache/ivy/core/search/OrganisationEntry.java?view=diff&rev=544459&r1=544458&r2=544459
==============================================================================
--- incubator/ivy/core/trunk/src/java/org/apache/ivy/core/search/OrganisationEntry.java (original)
+++ incubator/ivy/core/trunk/src/java/org/apache/ivy/core/search/OrganisationEntry.java Tue Jun  5 05:02:27 2007
@@ -19,9 +19,9 @@
 
 import org.apache.ivy.plugins.resolver.DependencyResolver;
 
-
 public class OrganisationEntry {
     private DependencyResolver resolver;
+
     private String organisation;
 
     public OrganisationEntry(DependencyResolver resolver, String organisation) {
@@ -32,9 +32,9 @@
     public String getOrganisation() {
         return organisation;
     }
-    
+
     public DependencyResolver getResolver() {
         return resolver;
     }
-    
+
 }

Modified: incubator/ivy/core/trunk/src/java/org/apache/ivy/core/search/RevisionEntry.java
URL: http://svn.apache.org/viewvc/incubator/ivy/core/trunk/src/java/org/apache/ivy/core/search/RevisionEntry.java?view=diff&rev=544459&r1=544458&r2=544459
==============================================================================
--- incubator/ivy/core/trunk/src/java/org/apache/ivy/core/search/RevisionEntry.java (original)
+++ incubator/ivy/core/trunk/src/java/org/apache/ivy/core/search/RevisionEntry.java Tue Jun  5 05:02:27 2007
@@ -19,11 +19,9 @@
 
 import org.apache.ivy.plugins.resolver.DependencyResolver;
 
-
-
-
 public class RevisionEntry {
     private ModuleEntry moduleEntry;
+
     private String revision;
 
     public RevisionEntry(ModuleEntry mod, String name) {
@@ -34,7 +32,6 @@
     public ModuleEntry getModuleEntry() {
         return moduleEntry;
     }
-    
 
     public String getRevision() {
         return revision;
@@ -55,5 +52,5 @@
     public DependencyResolver getResolver() {
         return moduleEntry.getResolver();
     }
-    
+
 }

Modified: incubator/ivy/core/trunk/src/java/org/apache/ivy/core/search/SearchEngine.java
URL: http://svn.apache.org/viewvc/incubator/ivy/core/trunk/src/java/org/apache/ivy/core/search/SearchEngine.java?view=diff&rev=544459&r1=544458&r2=544459
==============================================================================
--- incubator/ivy/core/trunk/src/java/org/apache/ivy/core/search/SearchEngine.java (original)
+++ incubator/ivy/core/trunk/src/java/org/apache/ivy/core/search/SearchEngine.java Tue Jun  5 05:02:27 2007
@@ -40,40 +40,41 @@
 import org.apache.ivy.util.Message;
 
 public class SearchEngine {
-	private IvySettings settings;
-	
+    private IvySettings settings;
+
     public SearchEngine(IvySettings settings) {
-		this.settings = settings;
-	}
+        this.settings = settings;
+    }
 
-	/**
+    /**
      * Returns an empty array when no token values are found.
-     *  
+     * 
      * @param token
      * @param otherTokenValues
      * @return
      */
-	public String[] listTokenValues(String token, Map otherTokenValues) {
+    public String[] listTokenValues(String token, Map otherTokenValues) {
         List r = new ArrayList();
         for (Iterator iter = settings.getResolvers().iterator(); iter.hasNext();) {
-            DependencyResolver resolver = (DependencyResolver)iter.next();
+            DependencyResolver resolver = (DependencyResolver) iter.next();
             r.addAll(Arrays.asList(resolver.listTokenValues(token, otherTokenValues)));
         }
-        return (String[])r.toArray(new String[r.size()]);
-	}
-    
+        return (String[]) r.toArray(new String[r.size()]);
+    }
+
     public OrganisationEntry[] listOrganisationEntries() {
         List entries = new ArrayList();
         for (Iterator iter = settings.getResolvers().iterator(); iter.hasNext();) {
-            DependencyResolver resolver = (DependencyResolver)iter.next();
+            DependencyResolver resolver = (DependencyResolver) iter.next();
             entries.addAll(Arrays.asList(resolver.listOrganisations()));
         }
-        return (OrganisationEntry[])entries.toArray(new OrganisationEntry[entries.size()]);
+        return (OrganisationEntry[]) entries.toArray(new OrganisationEntry[entries.size()]);
     }
+
     public String[] listOrganisations() {
         Collection orgs = new HashSet();
         for (Iterator iter = settings.getResolvers().iterator(); iter.hasNext();) {
-            DependencyResolver resolver = (DependencyResolver)iter.next();
+            DependencyResolver resolver = (DependencyResolver) iter.next();
             OrganisationEntry[] entries = resolver.listOrganisations();
             if (entries != null) {
                 for (int i = 0; i < entries.length; i++) {
@@ -83,20 +84,22 @@
                 }
             }
         }
-        return (String[])orgs.toArray(new String[orgs.size()]);
+        return (String[]) orgs.toArray(new String[orgs.size()]);
     }
+
     public ModuleEntry[] listModuleEntries(OrganisationEntry org) {
         List entries = new ArrayList();
         for (Iterator iter = settings.getResolvers().iterator(); iter.hasNext();) {
-            DependencyResolver resolver = (DependencyResolver)iter.next();
+            DependencyResolver resolver = (DependencyResolver) iter.next();
             entries.addAll(Arrays.asList(resolver.listModules(org)));
         }
-        return (ModuleEntry[])entries.toArray(new ModuleEntry[entries.size()]);
+        return (ModuleEntry[]) entries.toArray(new ModuleEntry[entries.size()]);
     }
+
     public String[] listModules(String org) {
         List mods = new ArrayList();
         for (Iterator iter = settings.getResolvers().iterator(); iter.hasNext();) {
-            DependencyResolver resolver = (DependencyResolver)iter.next();
+            DependencyResolver resolver = (DependencyResolver) iter.next();
             ModuleEntry[] entries = resolver.listModules(new OrganisationEntry(resolver, org));
             if (entries != null) {
                 for (int i = 0; i < entries.length; i++) {
@@ -106,21 +109,24 @@
                 }
             }
         }
-        return (String[])mods.toArray(new String[mods.size()]);
+        return (String[]) mods.toArray(new String[mods.size()]);
     }
+
     public RevisionEntry[] listRevisionEntries(ModuleEntry module) {
         List entries = new ArrayList();
         for (Iterator iter = settings.getResolvers().iterator(); iter.hasNext();) {
-            DependencyResolver resolver = (DependencyResolver)iter.next();
+            DependencyResolver resolver = (DependencyResolver) iter.next();
             entries.addAll(Arrays.asList(resolver.listRevisions(module)));
         }
-        return (RevisionEntry[])entries.toArray(new RevisionEntry[entries.size()]);
+        return (RevisionEntry[]) entries.toArray(new RevisionEntry[entries.size()]);
     }
+
     public String[] listRevisions(String org, String module) {
         List revs = new ArrayList();
         for (Iterator iter = settings.getResolvers().iterator(); iter.hasNext();) {
-            DependencyResolver resolver = (DependencyResolver)iter.next();
-            RevisionEntry[] entries = resolver.listRevisions(new ModuleEntry(new OrganisationEntry(resolver, org), module));
+            DependencyResolver resolver = (DependencyResolver) iter.next();
+            RevisionEntry[] entries = resolver.listRevisions(new ModuleEntry(new OrganisationEntry(
+                    resolver, org), module));
             if (entries != null) {
                 for (int i = 0; i < entries.length; i++) {
                     if (entries[i] != null) {
@@ -129,144 +135,156 @@
                 }
             }
         }
-        return (String[])revs.toArray(new String[revs.size()]);
+        return (String[]) revs.toArray(new String[revs.size()]);
     }
-    
-
-
 
+    /**
+     * List module ids of the module accessible through the current resolvers matching the given mid
+     * criteria according to the given matcher.
+     * 
+     * @param criteria
+     * @param matcher
+     * @return
+     */
+    public ModuleId[] listModules(ModuleId criteria, PatternMatcher matcher) {
+        List ret = new ArrayList();
+        Matcher orgMatcher = matcher.getMatcher(criteria.getOrganisation());
+        Matcher modMatcher = matcher.getMatcher(criteria.getName());
+        Map tokenValues = new HashMap();
+        String[] orgs = listTokenValues(IvyPatternHelper.ORGANISATION_KEY, tokenValues);
+        for (int i = 0; i < orgs.length; i++) {
+            if (orgMatcher.matches(orgs[i])) {
+                tokenValues.put(IvyPatternHelper.ORGANISATION_KEY, orgs[i]);
+                String[] mods = listTokenValues(IvyPatternHelper.MODULE_KEY, tokenValues);
+                for (int j = 0; j < mods.length; j++) {
+                    if (modMatcher.matches(mods[j])) {
+                        ret.add(new ModuleId(orgs[i], mods[j]));
+                    }
+                }
+            }
+        }
+        return (ModuleId[]) ret.toArray(new ModuleId[ret.size()]);
+    }
 
-	/**
-	 * List module ids of the module accessible through the current resolvers
-	 * matching the given mid criteria according to the given matcher.
-	 * 
-	 * @param criteria
-	 * @param matcher
-	 * @return
-	 */
-	public ModuleId[] listModules(ModuleId criteria, PatternMatcher matcher) {
-		List ret = new ArrayList();
-		Matcher orgMatcher = matcher.getMatcher(criteria.getOrganisation());
-		Matcher modMatcher = matcher.getMatcher(criteria.getName());
-		Map tokenValues = new HashMap();
-		String[] orgs = listTokenValues(IvyPatternHelper.ORGANISATION_KEY, tokenValues);
-		for (int i = 0; i < orgs.length; i++) {
-			if (orgMatcher.matches(orgs[i])) {
-				tokenValues.put(IvyPatternHelper.ORGANISATION_KEY, orgs[i]);
-				String[] mods = listTokenValues(IvyPatternHelper.MODULE_KEY, tokenValues);
-				for (int j = 0; j < mods.length; j++) {
-					if (modMatcher.matches(mods[j])) {
-						ret.add(new ModuleId(orgs[i], mods[j]));
-					}
-				}
-			}
-		}
-		return (ModuleId[]) ret.toArray(new ModuleId[ret.size()]);
-	}
-	
-	
-	/**
-	 * List module revision ids of the module accessible through the current resolvers
-	 * matching the given mrid criteria according to the given matcher.
-	 * 
-	 * @param criteria
-	 * @param matcher
-	 * @return
-	 */
-	public ModuleRevisionId[] listModules(ModuleRevisionId criteria, PatternMatcher matcher) {
-		List ret = new ArrayList();
-		Matcher orgMatcher = matcher.getMatcher(criteria.getOrganisation());
-		Matcher modMatcher = matcher.getMatcher(criteria.getName());
-		Matcher branchMatcher = matcher.getMatcher(criteria.getBranch());
-		Matcher revMatcher = matcher.getMatcher(criteria.getRevision());
-		Map tokenValues = new HashMap();
-		String[] orgs = listTokenValues(IvyPatternHelper.ORGANISATION_KEY, tokenValues);
-		for (int i = 0; i < orgs.length; i++) {
-			if (orgMatcher.matches(orgs[i])) {
-				tokenValues.put(IvyPatternHelper.ORGANISATION_KEY, orgs[i]);
-				String[] mods = listTokenValues(IvyPatternHelper.MODULE_KEY, tokenValues);
-				for (int j = 0; j < mods.length; j++) {
-					if (modMatcher.matches(mods[j])) {
-						tokenValues.put(IvyPatternHelper.MODULE_KEY, mods[j]);
-						String[] branches = listTokenValues(IvyPatternHelper.BRANCH_KEY, tokenValues);
-						if (branches == null || branches.length == 0) {
-							branches = new String[]  {settings.getDefaultBranch(new ModuleId(orgs[i], mods[j]))};
-						}
-						for (int k = 0; k < branches.length; k++) {
-							if (branches[k] == null || branchMatcher.matches(branches[k])) {
-								tokenValues.put(IvyPatternHelper.BRANCH_KEY, tokenValues);
-								String[] revs = listTokenValues(IvyPatternHelper.REVISION_KEY, tokenValues);
-								for (int l = 0; l < revs.length; l++) {
-									if (revMatcher.matches(revs[l])) {
-										ret.add(ModuleRevisionId.newInstance(orgs[i], mods[j], branches[k], revs[l]));
-									}
-								}
-							}
-						}
-					}
-				}
-			}
-		}
-		return (ModuleRevisionId[]) ret.toArray(new ModuleRevisionId[ret.size()]);
-	}
+    /**
+     * List module revision ids of the module accessible through the current resolvers matching the
+     * given mrid criteria according to the given matcher.
+     * 
+     * @param criteria
+     * @param matcher
+     * @return
+     */
+    public ModuleRevisionId[] listModules(ModuleRevisionId criteria, PatternMatcher matcher) {
+        List ret = new ArrayList();
+        Matcher orgMatcher = matcher.getMatcher(criteria.getOrganisation());
+        Matcher modMatcher = matcher.getMatcher(criteria.getName());
+        Matcher branchMatcher = matcher.getMatcher(criteria.getBranch());
+        Matcher revMatcher = matcher.getMatcher(criteria.getRevision());
+        Map tokenValues = new HashMap();
+        String[] orgs = listTokenValues(IvyPatternHelper.ORGANISATION_KEY, tokenValues);
+        for (int i = 0; i < orgs.length; i++) {
+            if (orgMatcher.matches(orgs[i])) {
+                tokenValues.put(IvyPatternHelper.ORGANISATION_KEY, orgs[i]);
+                String[] mods = listTokenValues(IvyPatternHelper.MODULE_KEY, tokenValues);
+                for (int j = 0; j < mods.length; j++) {
+                    if (modMatcher.matches(mods[j])) {
+                        tokenValues.put(IvyPatternHelper.MODULE_KEY, mods[j]);
+                        String[] branches = listTokenValues(IvyPatternHelper.BRANCH_KEY,
+                            tokenValues);
+                        if (branches == null || branches.length == 0) {
+                            branches = new String[] {settings.getDefaultBranch(new ModuleId(
+                                    orgs[i], mods[j]))};
+                        }
+                        for (int k = 0; k < branches.length; k++) {
+                            if (branches[k] == null || branchMatcher.matches(branches[k])) {
+                                tokenValues.put(IvyPatternHelper.BRANCH_KEY, tokenValues);
+                                String[] revs = listTokenValues(IvyPatternHelper.REVISION_KEY,
+                                    tokenValues);
+                                for (int l = 0; l < revs.length; l++) {
+                                    if (revMatcher.matches(revs[l])) {
+                                        ret.add(ModuleRevisionId.newInstance(orgs[i], mods[j],
+                                            branches[k], revs[l]));
+                                    }
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+        }
+        return (ModuleRevisionId[]) ret.toArray(new ModuleRevisionId[ret.size()]);
+    }
 
-    public Collection findModuleRevisionIds(DependencyResolver resolver, ModuleRevisionId pattern, PatternMatcher matcher) {
+    public Collection findModuleRevisionIds(DependencyResolver resolver, ModuleRevisionId pattern,
+            PatternMatcher matcher) {
         Collection mrids = new ArrayList();
         String resolverName = resolver.getName();
-        
-        Message.verbose("looking for modules matching "+pattern+" using "+matcher.getName());
-        Namespace fromNamespace = resolver instanceof AbstractResolver ? ((AbstractResolver)resolver).getNamespace() : null;
-        
+
+        Message.verbose("looking for modules matching " + pattern + " using " + matcher.getName());
+        Namespace fromNamespace = resolver instanceof AbstractResolver ? ((AbstractResolver) resolver)
+                .getNamespace()
+                : null;
+
         Collection modules = new ArrayList();
-        
+
         OrganisationEntry[] orgs = resolver.listOrganisations();
         if (orgs == null || orgs.length == 0) {
-            // hack for resolvers which are not able to list organisation, we try to see if the asked organisation is not an exact one:
+            // hack for resolvers which are not able to list organisation, we try to see if the
+            // asked organisation is not an exact one:
             String org = pattern.getOrganisation();
             if (fromNamespace != null) {
-                org = NameSpaceHelper.transform(pattern.getModuleId(), fromNamespace.getFromSystemTransformer()).getOrganisation();
+                org = NameSpaceHelper.transform(pattern.getModuleId(),
+                    fromNamespace.getFromSystemTransformer()).getOrganisation();
             }
-            modules.addAll(Arrays.asList(resolver.listModules(new OrganisationEntry(resolver, org))));                    
+            modules.addAll(Arrays
+                    .asList(resolver.listModules(new OrganisationEntry(resolver, org))));
         } else {
             Matcher orgMatcher = matcher.getMatcher(pattern.getOrganisation());
             for (int i = 0; i < orgs.length; i++) {
                 String org = orgs[i].getOrganisation();
                 String systemOrg = org;
                 if (fromNamespace != null) {
-                    systemOrg = NameSpaceHelper.transformOrganisation(org, fromNamespace.getToSystemTransformer());
+                    systemOrg = NameSpaceHelper.transformOrganisation(org, fromNamespace
+                            .getToSystemTransformer());
                 }
                 if (orgMatcher.matches(systemOrg)) {
-                    modules.addAll(Arrays.asList(resolver.listModules(new OrganisationEntry(resolver, org))));                    
+                    modules.addAll(Arrays.asList(resolver.listModules(new OrganisationEntry(
+                            resolver, org))));
                 }
             }
-        }                
-        Message.debug("found " + modules.size() + " modules for "+pattern.getOrganisation()+" on " + resolverName);
+        }
+        Message.debug("found " + modules.size() + " modules for " + pattern.getOrganisation()
+                + " on " + resolverName);
         boolean foundModule = false;
         for (Iterator iter = modules.iterator(); iter.hasNext();) {
-            ModuleEntry mEntry = (ModuleEntry)iter.next();
-            
+            ModuleEntry mEntry = (ModuleEntry) iter.next();
+
             ModuleId foundMid = new ModuleId(mEntry.getOrganisation(), mEntry.getModule());
             ModuleId systemMid = foundMid;
             if (fromNamespace != null) {
-                systemMid = NameSpaceHelper.transform(foundMid, fromNamespace.getToSystemTransformer());
+                systemMid = NameSpaceHelper.transform(foundMid, fromNamespace
+                        .getToSystemTransformer());
             }
-            
+
             if (MatcherHelper.matches(matcher, pattern.getModuleId(), systemMid)) {
                 // The module corresponds to the searched module pattern
                 foundModule = true;
                 RevisionEntry[] rEntries = resolver.listRevisions(mEntry);
-                Message.debug("found " + rEntries.length + " revisions for [" + mEntry.getOrganisation() + ", "+ mEntry.getModule() + "] on " + resolverName);
+                Message.debug("found " + rEntries.length + " revisions for ["
+                        + mEntry.getOrganisation() + ", " + mEntry.getModule() + "] on "
+                        + resolverName);
 
                 boolean foundRevision = false;
                 for (int j = 0; j < rEntries.length; j++) {
                     RevisionEntry rEntry = rEntries[j];
-                    
-                    ModuleRevisionId foundMrid = ModuleRevisionId.newInstance(mEntry.getOrganisation(), mEntry.getModule(), rEntry.getRevision());
+
+                    ModuleRevisionId foundMrid = ModuleRevisionId.newInstance(mEntry
+                            .getOrganisation(), mEntry.getModule(), rEntry.getRevision());
                     ModuleRevisionId systemMrid = foundMrid;
                     if (fromNamespace != null) {
                         systemMrid = fromNamespace.getToSystemTransformer().transform(foundMrid);
                     }
-                    
+
                     if (MatcherHelper.matches(matcher, pattern, systemMrid)) {
                         // We have a matching module revision
                         foundRevision = true;
@@ -274,12 +292,14 @@
                     }
                 }
                 if (!foundRevision) {
-                    Message.debug("no revision found matching "+pattern+" in [" + mEntry.getOrganisation() + "," + mEntry.getModule()+ "] using " + resolverName);                            
+                    Message.debug("no revision found matching " + pattern + " in ["
+                            + mEntry.getOrganisation() + "," + mEntry.getModule() + "] using "
+                            + resolverName);
                 }
             }
         }
         if (!foundModule) {
-            Message.debug("no module found matching "+pattern+" using " + resolverName);                            
+            Message.debug("no module found matching " + pattern + " using " + resolverName);
         }
         return mrids;
     }