incubator-ivy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From xav...@apache.org
Subject svn commit: r509221 - in /incubator/ivy/core/trunk: src/java/org/apache/ivy/ src/java/org/apache/ivy/ant/ src/java/org/apache/ivy/core/resolve/ src/java/org/apache/ivy/core/retrieve/ test/java/org/apache/ivy/core/retrieve/
Date Mon, 19 Feb 2007 15:37:10 GMT
Author: xavier
Date: Mon Feb 19 07:37:10 2007
New Revision: 509221

URL: http://svn.apache.org/viewvc?view=rev&rev=509221
Log:
REFACTOR: review retrieve API, introduce RetrieveOptions

Added:
    incubator/ivy/core/trunk/src/java/org/apache/ivy/core/retrieve/RetrieveOptions.java
Modified:
    incubator/ivy/core/trunk/src/java/org/apache/ivy/Ivy.java
    incubator/ivy/core/trunk/src/java/org/apache/ivy/Ivy14.java
    incubator/ivy/core/trunk/src/java/org/apache/ivy/Main.java
    incubator/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyArtifactReport.java
    incubator/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyPostResolveTask.java
    incubator/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyRetrieve.java
    incubator/ivy/core/trunk/src/java/org/apache/ivy/core/resolve/ResolveEngine.java
    incubator/ivy/core/trunk/src/java/org/apache/ivy/core/retrieve/RetrieveEngine.java
    incubator/ivy/core/trunk/test/java/org/apache/ivy/core/retrieve/RetrieveTest.java

Modified: incubator/ivy/core/trunk/src/java/org/apache/ivy/Ivy.java
URL: http://svn.apache.org/viewvc/incubator/ivy/core/trunk/src/java/org/apache/ivy/Ivy.java?view=diff&rev=509221&r1=509220&r2=509221
==============================================================================
--- incubator/ivy/core/trunk/src/java/org/apache/ivy/Ivy.java (original)
+++ incubator/ivy/core/trunk/src/java/org/apache/ivy/Ivy.java Mon Feb 19 07:37:10 2007
@@ -41,13 +41,12 @@
 import org.apache.ivy.core.module.id.ModuleId;
 import org.apache.ivy.core.module.id.ModuleRevisionId;
 import org.apache.ivy.core.publish.PublishEngine;
-import org.apache.ivy.core.report.ArtifactDownloadReport;
 import org.apache.ivy.core.report.ResolveReport;
-import org.apache.ivy.core.resolve.IvyNode;
 import org.apache.ivy.core.resolve.ResolveEngine;
 import org.apache.ivy.core.resolve.ResolveOptions;
 import org.apache.ivy.core.resolve.ResolvedModuleRevision;
 import org.apache.ivy.core.retrieve.RetrieveEngine;
+import org.apache.ivy.core.retrieve.RetrieveOptions;
 import org.apache.ivy.core.search.ModuleEntry;
 import org.apache.ivy.core.search.OrganisationEntry;
 import org.apache.ivy.core.search.RevisionEntry;
@@ -256,33 +255,10 @@
     //                         RETRIEVE
     /////////////////////////////////////////////////////////////////////////
 
-	public Map determineArtifactsToCopy(ModuleId moduleId, String[] confs, File cache, String
destFilePattern, String destIvyPattern, Filter artifactFilter) throws ParseException, IOException
{
-		return _retrieveEngine.determineArtifactsToCopy(moduleId, confs, cache, destFilePattern,
destIvyPattern, artifactFilter);
+	public int retrieve(ModuleRevisionId mrid, String destFilePattern, RetrieveOptions options)
throws IOException {
+		return _retrieveEngine.retrieve(mrid, destFilePattern, options);
 	}
 
-	public Map determineArtifactsToCopy(ModuleId moduleId, String[] confs, File cache, String
destFilePattern, String destIvyPattern) throws ParseException, IOException {
-		return _retrieveEngine.determineArtifactsToCopy(moduleId, confs, cache, destFilePattern,
destIvyPattern);
-	}
-
-	public int retrieve(ModuleId moduleId, String[] confs, File cache, String destFilePattern,
String destIvyPattern, Filter artifactFilter, boolean sync, boolean useOrigin, boolean makeSymlinks)
{
-		return _retrieveEngine.retrieve(moduleId, confs, cache, destFilePattern, destIvyPattern,
artifactFilter, sync, useOrigin, makeSymlinks);
-	}
-
-	public int retrieve(ModuleId moduleId, String[] confs, File cache, String destFilePattern,
String destIvyPattern, Filter artifactFilter, boolean sync, boolean useOrigin) {
-		return _retrieveEngine.retrieve(moduleId, confs, cache, destFilePattern, destIvyPattern,
artifactFilter, sync, useOrigin);
-	}
-
-	public int retrieve(ModuleId moduleId, String[] confs, File cache, String destFilePattern,
String destIvyPattern, Filter artifactFilter) {
-		return _retrieveEngine.retrieve(moduleId, confs, cache, destFilePattern, destIvyPattern,
artifactFilter);
-	}
-
-	public int retrieve(ModuleId moduleId, String[] confs, File cache, String destFilePattern,
String destIvyPattern) {
-		return _retrieveEngine.retrieve(moduleId, confs, cache, destFilePattern, destIvyPattern);
-	}
-
-	public int retrieve(ModuleId moduleId, String[] confs, File cache, String destFilePattern)
{
-		return _retrieveEngine.retrieve(moduleId, confs, cache, destFilePattern);
-	}
     /////////////////////////////////////////////////////////////////////////
     //                         DELIVER
     /////////////////////////////////////////////////////////////////////////

Modified: incubator/ivy/core/trunk/src/java/org/apache/ivy/Ivy14.java
URL: http://svn.apache.org/viewvc/incubator/ivy/core/trunk/src/java/org/apache/ivy/Ivy14.java?view=diff&rev=509221&r1=509220&r2=509221
==============================================================================
--- incubator/ivy/core/trunk/src/java/org/apache/ivy/Ivy14.java (original)
+++ incubator/ivy/core/trunk/src/java/org/apache/ivy/Ivy14.java Mon Feb 19 07:37:10 2007
@@ -39,6 +39,7 @@
 import org.apache.ivy.core.resolve.IvyNode;
 import org.apache.ivy.core.resolve.ResolveOptions;
 import org.apache.ivy.core.resolve.ResolvedModuleRevision;
+import org.apache.ivy.core.retrieve.RetrieveOptions;
 import org.apache.ivy.core.search.ModuleEntry;
 import org.apache.ivy.core.search.OrganisationEntry;
 import org.apache.ivy.core.search.RevisionEntry;
@@ -102,11 +103,24 @@
 	}
 
 	public Map determineArtifactsToCopy(ModuleId moduleId, String[] confs, File cache, String
destFilePattern, String destIvyPattern, Filter artifactFilter) throws ParseException, IOException
{
-		return _ivy.determineArtifactsToCopy(moduleId, confs, cache, destFilePattern, destIvyPattern,
artifactFilter);
+		return _ivy.getRetrieveEngine().determineArtifactsToCopy(
+				new ModuleRevisionId(moduleId, Ivy.getWorkingRevision()), 
+				destFilePattern, 
+				new RetrieveOptions()
+					.setConfs(confs)
+					.setCache(CacheManager.getInstance(_ivy.getSettings(), cache))
+					.setDestIvyPattern(destIvyPattern)
+					.setArtifactFilter(artifactFilter));
 	}
 
 	public Map determineArtifactsToCopy(ModuleId moduleId, String[] confs, File cache, String
destFilePattern, String destIvyPattern) throws ParseException, IOException {
-		return _ivy.determineArtifactsToCopy(moduleId, confs, cache, destFilePattern, destIvyPattern);
+		return _ivy.getRetrieveEngine().determineArtifactsToCopy(
+				new ModuleRevisionId(moduleId, Ivy.getWorkingRevision()), 
+				destFilePattern, 
+				new RetrieveOptions()
+					.setConfs(confs)
+					.setCache(CacheManager.getInstance(_ivy.getSettings(), cache))
+					.setDestIvyPattern(destIvyPattern));
 	}
 
 	public ArtifactDownloadReport download(Artifact artifact, File cache, boolean useOrigin)
{
@@ -281,23 +295,80 @@
 	}
 
 	public int retrieve(ModuleId moduleId, String[] confs, File cache, String destFilePattern,
String destIvyPattern, Filter artifactFilter, boolean sync, boolean useOrigin, boolean makeSymlinks)
{
-		return _ivy.retrieve(moduleId, confs, cache, destFilePattern, destIvyPattern, artifactFilter,
sync, useOrigin, makeSymlinks);
+		try {
+			return _ivy.retrieve(
+					new ModuleRevisionId(moduleId, Ivy.getWorkingRevision()), 
+					destFilePattern, 
+					new RetrieveOptions()
+						.setConfs(confs)
+						.setCache(CacheManager.getInstance(_ivy.getSettings(), cache))
+						.setDestIvyPattern(destIvyPattern)
+						.setArtifactFilter(artifactFilter)
+						.setSync(sync)
+						.setUseOrigin(useOrigin)
+						.setMakeSymlinks(makeSymlinks));
+		} catch (IOException e) {
+			throw new RuntimeException(e);
+		}
 	}
 
 	public int retrieve(ModuleId moduleId, String[] confs, File cache, String destFilePattern,
String destIvyPattern, Filter artifactFilter, boolean sync, boolean useOrigin) {
-		return _ivy.retrieve(moduleId, confs, cache, destFilePattern, destIvyPattern, artifactFilter,
sync, useOrigin);
+		try {
+			return _ivy.retrieve(
+					new ModuleRevisionId(moduleId, Ivy.getWorkingRevision()), 
+					destFilePattern, 
+					new RetrieveOptions()
+						.setConfs(confs)
+						.setCache(CacheManager.getInstance(_ivy.getSettings(), cache))
+						.setDestIvyPattern(destIvyPattern)
+						.setArtifactFilter(artifactFilter)
+						.setSync(sync)
+						.setUseOrigin(useOrigin));
+		} catch (IOException e) {
+			throw new RuntimeException(e);
+		}
 	}
 
 	public int retrieve(ModuleId moduleId, String[] confs, File cache, String destFilePattern,
String destIvyPattern, Filter artifactFilter) {
-		return _ivy.retrieve(moduleId, confs, cache, destFilePattern, destIvyPattern, artifactFilter);
+		try {
+			return _ivy.retrieve(
+					new ModuleRevisionId(moduleId, Ivy.getWorkingRevision()), 
+					destFilePattern, 
+					new RetrieveOptions()
+						.setConfs(confs)
+						.setCache(CacheManager.getInstance(_ivy.getSettings(), cache))
+						.setDestIvyPattern(destIvyPattern)
+						.setArtifactFilter(artifactFilter));
+		} catch (IOException e) {
+			throw new RuntimeException(e);
+		}
 	}
 
 	public int retrieve(ModuleId moduleId, String[] confs, File cache, String destFilePattern,
String destIvyPattern) {
-		return _ivy.retrieve(moduleId, confs, cache, destFilePattern, destIvyPattern);
+		try {
+			return _ivy.retrieve(
+					new ModuleRevisionId(moduleId, Ivy.getWorkingRevision()), 
+					destFilePattern, 
+					new RetrieveOptions()
+						.setConfs(confs)
+						.setCache(CacheManager.getInstance(_ivy.getSettings(), cache))
+						.setDestIvyPattern(destIvyPattern));
+		} catch (IOException e) {
+			throw new RuntimeException(e);
+		}
 	}
 
 	public int retrieve(ModuleId moduleId, String[] confs, File cache, String destFilePattern)
{
-		return _ivy.retrieve(moduleId, confs, cache, destFilePattern);
+		try {
+			return _ivy.retrieve(
+					new ModuleRevisionId(moduleId, Ivy.getWorkingRevision()), 
+					destFilePattern, 
+					new RetrieveOptions()
+						.setConfs(confs)
+						.setCache(CacheManager.getInstance(_ivy.getSettings(), cache)));
+		} catch (IOException e) {
+			throw new RuntimeException(e);
+		}
 	}
 
 	public void setVariable(String varName, String value) {

Modified: incubator/ivy/core/trunk/src/java/org/apache/ivy/Main.java
URL: http://svn.apache.org/viewvc/incubator/ivy/core/trunk/src/java/org/apache/ivy/Main.java?view=diff&rev=509221&r1=509220&r2=509221
==============================================================================
--- incubator/ivy/core/trunk/src/java/org/apache/ivy/Main.java (original)
+++ incubator/ivy/core/trunk/src/java/org/apache/ivy/Main.java Mon Feb 19 07:37:10 2007
@@ -48,6 +48,7 @@
 import org.apache.ivy.core.module.id.ModuleRevisionId;
 import org.apache.ivy.core.report.ResolveReport;
 import org.apache.ivy.core.resolve.ResolveOptions;
+import org.apache.ivy.core.retrieve.RetrieveOptions;
 import org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorWriter;
 import org.apache.ivy.plugins.report.XmlReportParser;
 import org.apache.ivy.util.DefaultMessageImpl;
@@ -275,7 +276,7 @@
 
             ResolveOptions resolveOptions = new ResolveOptions()
 	            .setConfs(confs)
-	            .setCache(CacheManager.getInstance(ivy.getSettings(), cache))
+	            .setCache(cacheManager)
 	            .setValidate(validate)
 	            .setUseOrigin(line.hasOption("useOrigin"));
             ResolveReport report = ivy.resolve(
@@ -295,7 +296,14 @@
                 if (retrievePattern.indexOf("[") == -1) {
                     retrievePattern = retrievePattern + "/lib/[conf]/[artifact].[ext]";
                 }
-                ivy.retrieve(md.getModuleRevisionId().getModuleId(), confs, cache, retrievePattern,
null, null, line.hasOption("sync"), line.hasOption("useOrigin"));
+                ivy.retrieve(
+                		md.getModuleRevisionId(), 
+                		retrievePattern, 
+                		new RetrieveOptions()
+                			.setConfs(confs)
+                			.setCache(cacheManager)
+							.setSync(line.hasOption("sync"))
+							.setUseOrigin(line.hasOption("useOrigin")));
             }
             if (line.hasOption("cachepath")) {
                 outputCachePath(ivy, cache, md, confs, line.getOptionValue("cachepath", "ivycachepath.txt"));

Modified: incubator/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyArtifactReport.java
URL: http://svn.apache.org/viewvc/incubator/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyArtifactReport.java?view=diff&rev=509221&r1=509220&r2=509221
==============================================================================
--- incubator/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyArtifactReport.java (original)
+++ incubator/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyArtifactReport.java Mon Feb 19
07:37:10 2007
@@ -39,9 +39,10 @@
 import org.apache.ivy.core.cache.CacheManager;
 import org.apache.ivy.core.module.descriptor.Artifact;
 import org.apache.ivy.core.module.descriptor.ModuleDescriptor;
-import org.apache.ivy.core.module.id.ModuleId;
+import org.apache.ivy.core.module.id.ModuleRevisionId;
 import org.apache.ivy.core.resolve.IvyNode;
 import org.apache.ivy.core.resolve.ResolveOptions;
+import org.apache.ivy.core.retrieve.RetrieveOptions;
 import org.apache.ivy.core.settings.IvySettings;
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.Project;
@@ -100,8 +101,9 @@
 
         ensureResolved(isHaltonfailure(), false, null, null);
 
-        String _organisation = getProperty(null, settings, "ivy.organisation");
-        String _module = getProperty(null, settings, "ivy.module");
+        String organisation = getProperty(null, settings, "ivy.organisation");
+        String module = getProperty(null, settings, "ivy.module");
+        String revision = getProperty(Ivy.getWorkingRevision(), settings, "ivy.revision");
 
         if (_cache == null) {
             _cache = settings.getDefaultCache();
@@ -115,10 +117,10 @@
             }
         }
 
-        if (_organisation == null) {
+        if (organisation == null) {
             throw new BuildException("no organisation provided for ivy artifact report task:
It can be set via a prior call to <resolve/>");
         }
-        if (_module == null) {
+        if (module == null) {
             throw new BuildException("no module name provided for ivy artifact report task:
It can be set via a prior call to <resolve/>");
         }
         if (_conf == null) {
@@ -126,15 +128,22 @@
         }
         try {
             String[] confs = splitConfs(_conf);
-            IvyNode[] dependencies = ivy.getResolveEngine()
+            CacheManager cacheManager = CacheManager.getInstance(settings, _cache);
+			IvyNode[] dependencies = ivy.getResolveEngine()
             	.getDependencies((ModuleDescriptor) getProject().getReference("ivy.resolved.descriptor"),

             			new ResolveOptions()
             				.setConfs(confs)
-            				.setCache(CacheManager.getInstance(settings, _cache))
+            				.setCache(cacheManager)
             				.setValidate(doValidate(settings)),
             			null);
 
-            Map artifactsToCopy = ivy.determineArtifactsToCopy(new ModuleId(_organisation,
_module), confs, _cache, _pattern, null);
+            Map artifactsToCopy = ivy.getRetrieveEngine().determineArtifactsToCopy(
+            		ModuleRevisionId.newInstance(organisation, module, revision), 
+            		_pattern, 
+            		new RetrieveOptions()
+            			.setConfs(confs)
+            			.setCache(cacheManager));
+            
             Map moduleRevToArtifactsMap = new HashMap();
             for (Iterator iter = artifactsToCopy.keySet().iterator(); iter.hasNext();) {
                 Artifact artifact = (Artifact) iter.next();

Modified: incubator/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyPostResolveTask.java
URL: http://svn.apache.org/viewvc/incubator/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyPostResolveTask.java?view=diff&rev=509221&r1=509220&r2=509221
==============================================================================
--- incubator/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyPostResolveTask.java (original)
+++ incubator/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyPostResolveTask.java Mon Feb 19
07:37:10 2007
@@ -21,6 +21,7 @@
 
 import org.apache.ivy.Ivy;
 import org.apache.ivy.core.module.id.ModuleId;
+import org.apache.ivy.core.module.id.ModuleRevisionId;
 import org.apache.ivy.core.report.ResolveReport;
 import org.apache.ivy.core.settings.IvySettings;
 import org.apache.ivy.util.Message;
@@ -130,6 +131,10 @@
         }
         
         _artifactFilter = FilterHelper.getArtifactTypeFilter(_type);
+    }
+
+    protected ModuleRevisionId getResolvedMrid() {
+    	return new ModuleRevisionId(getResolvedModuleId(), getRevision() == null ?Ivy.getWorkingRevision():getRevision());
     }
 
     protected ModuleId getResolvedModuleId() {

Modified: incubator/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyRetrieve.java
URL: http://svn.apache.org/viewvc/incubator/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyRetrieve.java?view=diff&rev=509221&r1=509220&r2=509221
==============================================================================
--- incubator/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyRetrieve.java (original)
+++ incubator/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyRetrieve.java Mon Feb 19 07:37:10
2007
@@ -17,6 +17,8 @@
  */
 package org.apache.ivy.ant;
 
+import org.apache.ivy.core.cache.CacheManager;
+import org.apache.ivy.core.retrieve.RetrieveOptions;
 import org.apache.ivy.util.filter.Filter;
 import org.apache.tools.ant.BuildException;
 
@@ -46,7 +48,17 @@
         _pattern = getProperty(_pattern, getSettings(), "ivy.retrieve.pattern");
         try {
         	Filter artifactFilter = getArtifactFilter();
-            int targetsCopied = getIvyInstance().retrieve(getResolvedModuleId(), splitConfs(getConf()),
getCache(), _pattern, _ivypattern, artifactFilter, _sync, isUseOrigin(), _symlink);
+            int targetsCopied = getIvyInstance().retrieve(
+            		getResolvedMrid(), 
+            		_pattern, 
+            		new RetrieveOptions()
+            			.setConfs(splitConfs(getConf()))
+            			.setCache(CacheManager.getInstance(getIvyInstance().getSettings(), getCache()))
+            			.setDestIvyPattern(_ivypattern)
+            			.setArtifactFilter(artifactFilter)
+            			.setSync(_sync)
+            			.setUseOrigin(isUseOrigin())
+            			.setMakeSymlinks(_symlink));
             boolean haveTargetsBeenCopied = targetsCopied > 0;
             getProject().setProperty("ivy.nb.targets.copied", String.valueOf(targetsCopied));
             getProject().setProperty("ivy.targets.copied", String.valueOf(haveTargetsBeenCopied));

Modified: incubator/ivy/core/trunk/src/java/org/apache/ivy/core/resolve/ResolveEngine.java
URL: http://svn.apache.org/viewvc/incubator/ivy/core/trunk/src/java/org/apache/ivy/core/resolve/ResolveEngine.java?view=diff&rev=509221&r1=509220&r2=509221
==============================================================================
--- incubator/ivy/core/trunk/src/java/org/apache/ivy/core/resolve/ResolveEngine.java (original)
+++ incubator/ivy/core/trunk/src/java/org/apache/ivy/core/resolve/ResolveEngine.java Mon Feb
19 07:37:10 2007
@@ -35,6 +35,7 @@
 import java.util.Properties;
 import java.util.Set;
 
+import org.apache.ivy.Ivy;
 import org.apache.ivy.core.IvyContext;
 import org.apache.ivy.core.cache.CacheManager;
 import org.apache.ivy.core.event.EventManager;
@@ -63,7 +64,6 @@
 import org.apache.ivy.plugins.repository.url.URLResource;
 import org.apache.ivy.plugins.resolver.CacheResolver;
 import org.apache.ivy.plugins.resolver.DependencyResolver;
-import org.apache.ivy.util.HostUtil;
 import org.apache.ivy.util.Message;
 import org.apache.ivy.util.filter.Filter;
 
@@ -139,7 +139,7 @@
         ModuleDescriptor md = parser.parseDescriptor(_settings, ivySource, options.isValidate());
         String revision = options.getRevision();
         if (revision == null && md.getResolvedModuleRevisionId().getRevision() ==
null) {
-            revision = "working@"+HostUtil.getLocalHostName();
+            revision = Ivy.getWorkingRevision();
         }
         if (revision != null) {
             md.setResolvedModuleRevisionId(ModuleRevisionId.newInstance(md.getModuleRevisionId(),
revision));

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=509221&r1=509220&r2=509221
==============================================================================
--- 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 Mon
Feb 19 07:37:10 2007
@@ -19,6 +19,7 @@
 
 import java.io.File;
 import java.io.IOException;
+import java.net.URL;
 import java.text.ParseException;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -37,14 +38,16 @@
 import org.apache.ivy.core.cache.CacheManager;
 import org.apache.ivy.core.module.descriptor.Artifact;
 import org.apache.ivy.core.module.descriptor.DefaultArtifact;
+import org.apache.ivy.core.module.descriptor.ModuleDescriptor;
 import org.apache.ivy.core.module.id.ModuleId;
 import org.apache.ivy.core.module.id.ModuleRevisionId;
 import org.apache.ivy.core.settings.IvySettings;
+import org.apache.ivy.plugins.parser.ModuleDescriptorParser;
+import org.apache.ivy.plugins.parser.ModuleDescriptorParserRegistry;
 import org.apache.ivy.plugins.report.XmlReportParser;
+import org.apache.ivy.plugins.repository.url.URLResource;
 import org.apache.ivy.util.FileUtil;
 import org.apache.ivy.util.Message;
-import org.apache.ivy.util.filter.Filter;
-import org.apache.ivy.util.filter.FilterHelper;
 
 public class RetrieveEngine {
 	private IvySettings _settings;
@@ -61,37 +64,22 @@
      * 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(ModuleId moduleId, String[] confs, final File cache, String destFilePattern)
{
-        return retrieve(moduleId, confs, cache, destFilePattern, null);
-    }
-    /**
-     * If destIvyPattern is null no ivy files will be copied.
-     */
-    public int retrieve(ModuleId moduleId, String[] confs, final File cache, String destFilePattern,
String destIvyPattern) {
-    	return retrieve(moduleId, confs, cache, destFilePattern, destIvyPattern, FilterHelper.NO_FILTER);
-    }
-    
-    public int retrieve(ModuleId moduleId, String[] confs, final File cache, String destFilePattern,
String destIvyPattern, Filter artifactFilter) {
-    	return retrieve(moduleId, confs, cache, destFilePattern, destIvyPattern, artifactFilter,
false, false);
-    }
-    public int retrieve(ModuleId moduleId, String[] confs, final File cache, String destFilePattern,
String destIvyPattern, Filter artifactFilter, boolean sync, boolean useOrigin) {
-    	return retrieve(moduleId, confs, cache, destFilePattern, destIvyPattern, artifactFilter,
sync, useOrigin, false);
-    }
-    public int retrieve(ModuleId moduleId, String[] confs, final File cache, String destFilePattern,
String destIvyPattern, Filter artifactFilter, boolean sync, boolean useOrigin, boolean makeSymlinks)
{
-    	if (artifactFilter == null) {
-    		artifactFilter = FilterHelper.NO_FILTER;
-    	}
-    	
-        Message.info(":: retrieving :: "+moduleId+(sync?" [sync]":""));
-        Message.info("\tconfs: "+Arrays.asList(confs));
+    public int retrieve(ModuleRevisionId mrid, String destFilePattern, RetrieveOptions options)
throws IOException {
+    	ModuleId moduleId = mrid.getModuleId();
+        Message.info(":: retrieving :: "+moduleId+(options.isSync()?" [sync]":""));
         long start = System.currentTimeMillis();
         
         destFilePattern = IvyPatternHelper.substituteVariables(destFilePattern, _settings.getVariables());
-        destIvyPattern = IvyPatternHelper.substituteVariables(destIvyPattern, _settings.getVariables());
-        CacheManager cacheManager = getCacheManager(cache);
+        String destIvyPattern = IvyPatternHelper.substituteVariables(options.getDestIvyPattern(),
_settings.getVariables());
+        
+        CacheManager cacheManager = getCacheManager(options);
+        String[] confs = getConfs(mrid, options);
+        Message.info("\tconfs: "+Arrays.asList(confs));
+
         try {
-            Map artifactsToCopy = determineArtifactsToCopy(moduleId, confs, cache, destFilePattern,
destIvyPattern, artifactFilter);
+            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) 
@@ -106,8 +94,9 @@
 				if ("ivy".equals(artifact.getType())) {
 					archive = cacheManager.getIvyFileInCache(artifact.getModuleRevisionId());
 				} else {
-					archive = cacheManager.getArchiveFileInCache(artifact, cacheManager.getSavedArtifactOrigin(artifact),
useOrigin);
-					if (!useOrigin && !archive.exists()) {
+					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));
@@ -120,7 +109,7 @@
                     File destFile = new File((String)it2.next());
                     if (!_settings.isCheckUpToDate() || !upToDate(archive, destFile)) {
                         Message.verbose("\t\tto "+destFile);
-                        if (makeSymlinks) {
+                        if (options.isMakeSymlinks()) {
                             FileUtil.symlink(archive, destFile, null, false);
                         } else {
                             FileUtil.copy(archive, destFile, null);
@@ -138,7 +127,7 @@
                 }
             }
             
-            if (sync) {
+            if (options.isSync()) {
 				Message.verbose("\tsyncing...");
                 Collection existingArtifacts = FileUtil.listAll(fileRetrieveRoot);
                 Collection existingIvys = ivyRetrieveRoot == null ? null : FileUtil.listAll(ivyRetrieveRoot);
@@ -165,9 +154,39 @@
         }
     }
 
-    public CacheManager getCacheManager(File cache) {
-    	// TODO reuse instance
-		return new CacheManager(_settings, cache);
+	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;
+        	}        
+        }
+		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);
+        } else {
+        	IvyContext.getContext().setCache(cacheManager.getCache());
+        }
+		return cacheManager;
 	}
 
 	private void sync(Collection target, Collection existing) {
@@ -189,14 +208,12 @@
 		}
 	}
 
-	public Map determineArtifactsToCopy(ModuleId moduleId, String[] confs, final File cache,
String destFilePattern, String destIvyPattern) throws ParseException, IOException {
-    	return determineArtifactsToCopy(moduleId, confs, cache, destFilePattern, destIvyPattern,
FilterHelper.NO_FILTER);
-    }
-    
-    public Map determineArtifactsToCopy(ModuleId moduleId, String[] confs, final File cache,
String destFilePattern, String destIvyPattern, Filter artifactFilter) throws ParseException,
IOException {
-        if (artifactFilter == null) {
-        	artifactFilter = FilterHelper.NO_FILTER;
-        }
+	public Map determineArtifactsToCopy(ModuleRevisionId mrid, String destFilePattern, RetrieveOptions
options) throws ParseException, IOException {
+		ModuleId moduleId = mrid.getModuleId();
+		
+        CacheManager cacheManager = getCacheManager(options);
+        String[] confs = getConfs(mrid, options);
+        String destIvyPattern = IvyPatternHelper.substituteVariables(options.getDestIvyPattern(),
_settings.getVariables());
         
         // find what we must retrieve where
         final Map artifactsToCopy = new HashMap(); // Artifact source -> Set (String copyDestAbsolutePath)
@@ -205,9 +222,9 @@
         XmlReportParser parser = new XmlReportParser();
         for (int i = 0; i < confs.length; i++) {
             final String conf = confs[i];
-            Collection artifacts = new ArrayList(Arrays.asList(parser.getArtifacts(moduleId,
conf, cache)));
+            Collection artifacts = new ArrayList(Arrays.asList(parser.getArtifacts(moduleId,
conf, cacheManager.getCache())));
             if (destIvyPattern != null) {
-                ModuleRevisionId[] mrids = parser.getRealDependencyRevisionIds(moduleId,
conf, cache);
+                ModuleRevisionId[] mrids = parser.getRealDependencyRevisionIds(moduleId,
conf, cacheManager.getCache());
                 for (int j = 0; j < mrids.length; j++) {
                     artifacts.add(DefaultArtifact.newIvyArtifact(mrids[j], null));
                 }
@@ -216,7 +233,7 @@
                 Artifact artifact = (Artifact)iter.next();
                 String destPattern = "ivy".equals(artifact.getType()) ? destIvyPattern: destFilePattern;
                 
-                if (!"ivy".equals(artifact.getType()) && !artifactFilter.accept(artifact))
{
+                if (!"ivy".equals(artifact.getType()) && !options.getArtifactFilter().accept(artifact))
{
                 	continue;	// skip this artifact, the filter didn't accept it!
                 }
                 

Added: 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=auto&rev=509221
==============================================================================
--- incubator/ivy/core/trunk/src/java/org/apache/ivy/core/retrieve/RetrieveOptions.java (added)
+++ incubator/ivy/core/trunk/src/java/org/apache/ivy/core/retrieve/RetrieveOptions.java Mon
Feb 19 07:37:10 2007
@@ -0,0 +1,125 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.ivy.core.retrieve;
+
+import org.apache.ivy.core.cache.CacheManager;
+import org.apache.ivy.util.filter.Filter;
+import org.apache.ivy.util.filter.FilterHelper;
+
+/**
+ * A set of options used during retrieve related tasks
+ * 
+ * @see RetrieveEngine
+ * @author Xavier Hanin
+ */
+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;
+	
+	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;
+	}
+	
+	
+}

Modified: incubator/ivy/core/trunk/test/java/org/apache/ivy/core/retrieve/RetrieveTest.java
URL: http://svn.apache.org/viewvc/incubator/ivy/core/trunk/test/java/org/apache/ivy/core/retrieve/RetrieveTest.java?view=diff&rev=509221&r1=509220&r2=509221
==============================================================================
--- incubator/ivy/core/trunk/test/java/org/apache/ivy/core/retrieve/RetrieveTest.java (original)
+++ incubator/ivy/core/trunk/test/java/org/apache/ivy/core/retrieve/RetrieveTest.java Mon
Feb 19 07:37:10 2007
@@ -28,7 +28,6 @@
 import org.apache.ivy.core.module.descriptor.ModuleDescriptor;
 import org.apache.ivy.core.report.ResolveReport;
 import org.apache.ivy.core.resolve.ResolveOptions;
-import org.apache.ivy.util.filter.FilterHelper;
 import org.apache.tools.ant.Project;
 import org.apache.tools.ant.taskdefs.Delete;
 
@@ -74,11 +73,11 @@
         assertNotNull(md);
         
         String pattern = "build/test/retrieve/[module]/[conf]/[artifact]-[revision].[ext]";
-        _ivy.retrieve(md.getModuleRevisionId().getModuleId(), md.getConfigurationsNames(),
_cache, pattern);
+        _ivy.retrieve(md.getModuleRevisionId(), pattern, getRetrieveOptions());
         assertTrue(new File(IvyPatternHelper.substitute(pattern, "org1", "mod1.2", "2.0",
"mod1.2", "jar", "jar", "default")).exists());
 
         pattern = "build/test/retrieve/[module]/[conf]/[type]s/[artifact]-[revision].[ext]";
-        _ivy.retrieve(md.getModuleRevisionId().getModuleId(), md.getConfigurationsNames(),
_cache, pattern);
+        _ivy.retrieve(md.getModuleRevisionId(), pattern, getRetrieveOptions());
         assertTrue(new File(IvyPatternHelper.substitute(pattern, "org1", "mod1.2", "2.0",
"mod1.2", "jar", "jar", "default")).exists());
     }
 
@@ -91,11 +90,11 @@
         assertNotNull(md);
         
         String pattern = "build/test/retrieve/[module]/[conf]/[artifact]-[revision].[ext]";
-        _ivy.retrieve(md.getModuleRevisionId().getModuleId(), md.getConfigurationsNames(),
_cache, pattern, null, FilterHelper.NO_FILTER, false, false, true);
+        _ivy.retrieve(md.getModuleRevisionId(), pattern, getRetrieveOptions().setMakeSymlinks(true));
         assertLink(IvyPatternHelper.substitute(pattern, "org1", "mod1.2", "2.0", "mod1.2",
"jar", "jar", "default"));
 
         pattern = "build/test/retrieve/[module]/[conf]/[type]s/[artifact]-[revision].[ext]";
-        _ivy.retrieve(md.getModuleRevisionId().getModuleId(), md.getConfigurationsNames(),
_cache, pattern, null, FilterHelper.NO_FILTER, false, false, true);
+        _ivy.retrieve(md.getModuleRevisionId(), pattern, getRetrieveOptions().setMakeSymlinks(true));
         assertLink(IvyPatternHelper.substitute(pattern, "org1", "mod1.2", "2.0", "mod1.2",
"jar", "jar", "default"));
     }
 
@@ -129,15 +128,19 @@
         assertNotNull(md);
         
         String pattern = "build/test/${retrieve.dir}/[module]/[conf]/[artifact]-[revision].[ext]";
-        _ivy.retrieve(md.getModuleRevisionId().getModuleId(), md.getConfigurationsNames(),
_cache, pattern);
+        _ivy.retrieve(md.getModuleRevisionId(), pattern, getRetrieveOptions());
         pattern = IvyPatternHelper.substituteVariable(pattern, "retrieve.dir", "retrieve");
         assertTrue(new File(IvyPatternHelper.substitute(pattern, "org1", "mod1.2", "2.0",
"mod1.2", "jar", "jar", "default")).exists());
 
         pattern = "build/test/${retrieve.dir}/[module]/[conf]/[type]s/[artifact]-[revision].[ext]";
-        _ivy.retrieve(md.getModuleRevisionId().getModuleId(), md.getConfigurationsNames(),
_cache, pattern);
+        _ivy.retrieve(md.getModuleRevisionId(), pattern, getRetrieveOptions());
         pattern = IvyPatternHelper.substituteVariable(pattern, "retrieve.dir", "retrieve");
         assertTrue(new File(IvyPatternHelper.substitute(pattern, "org1", "mod1.2", "2.0",
"mod1.2", "jar", "jar", "default")).exists());
     }
+
+	private RetrieveOptions getRetrieveOptions() {
+		return new RetrieveOptions().setCache(CacheManager.getInstance(_ivy.getSettings(), _cache));
+	}
 
     
     private ResolveOptions getResolveOptions(String[] confs) {



Mime
View raw message