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 ma...@apache.org on 2007/03/26 21:55:59 UTC

svn commit: r522640 - in /incubator/ivy/core/trunk: src/java/org/apache/ivy/ src/java/org/apache/ivy/ant/ src/java/org/apache/ivy/core/cache/ src/java/org/apache/ivy/core/deliver/ test/java/org/apache/ivy/ant/

Author: maartenc
Date: Mon Mar 26 14:55:57 2007
New Revision: 522640

URL: http://svn.apache.org/viewvc?view=rev&rev=522640
Log:
Added resolveId support to deliver task (IVY-366)

Modified:
    incubator/ivy/core/trunk/src/java/org/apache/ivy/Ivy.java
    incubator/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyDeliver.java
    incubator/ivy/core/trunk/src/java/org/apache/ivy/core/cache/CacheManager.java
    incubator/ivy/core/trunk/src/java/org/apache/ivy/core/deliver/DeliverEngine.java
    incubator/ivy/core/trunk/src/java/org/apache/ivy/core/deliver/DeliverOptions.java
    incubator/ivy/core/trunk/test/java/org/apache/ivy/ant/IvyDeliverTest.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=522640&r1=522639&r2=522640
==============================================================================
--- incubator/ivy/core/trunk/src/java/org/apache/ivy/Ivy.java (original)
+++ incubator/ivy/core/trunk/src/java/org/apache/ivy/Ivy.java Mon Mar 26 14:55:57 2007
@@ -265,6 +265,10 @@
 		_deliverEngine.deliver(mrid, revision, destIvyPattern, DeliverOptions.newInstance(_settings));
 	}
 
+	public void deliver(String revision, String destIvyPattern, DeliverOptions options) throws IOException, ParseException {
+		_deliverEngine.deliver(revision, destIvyPattern, options);
+	}
+
 	/**
 	 * Example of use:
 	 * deliver(mrid, "1.5", "target/ivy/ivy-[revision].xml", 

Modified: incubator/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyDeliver.java
URL: http://svn.apache.org/viewvc/incubator/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyDeliver.java?view=diff&rev=522640&r1=522639&r2=522640
==============================================================================
--- incubator/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyDeliver.java (original)
+++ incubator/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyDeliver.java Mon Mar 26 14:55:57 2007
@@ -328,13 +328,15 @@
                         settings.substitute(deliveryListPath));
             }
         }
-        if (_organisation == null) {
-            throw new BuildException(
-                    "no organisation provided for ivy deliver task: It can either be set explicitely via the attribute 'organisation' or via 'ivy.organisation' property or a prior call to <resolve/>");
-        }
-        if (_module == null) {
-            throw new BuildException(
-                    "no module name provided for ivy deliver task: It can either be set explicitely via the attribute 'module' or via 'ivy.module' property or a prior call to <resolve/>");
+        if (_resolveId == null) {
+	        if (_organisation == null) {
+	            throw new BuildException(
+	                    "no organisation provided for ivy deliver task: It can either be set explicitely via the attribute 'organisation' or via 'ivy.organisation' property or a prior call to <resolve/>");
+	        }
+	        if (_module == null) {
+	            throw new BuildException(
+	                    "no module name provided for ivy deliver task: It can either be set explicitely via the attribute 'module' or via 'ivy.module' property or a prior call to <resolve/>");
+	        }
         }
         if (_revision == null) {
             _revision = Ivy.getWorkingRevision();
@@ -355,8 +357,11 @@
             throw new BuildException(
                     "no status provided: either provide it as parameter or through the ivy.status.default property");
         }
-        ModuleRevisionId mrid = ModuleRevisionId.newInstance(
-        		_organisation, _module, _revision);
+        
+        ModuleRevisionId mrid = null;
+        if (_resolveId == null) {
+        	mrid = ModuleRevisionId.newInstance(_organisation, _module, _revision);
+        }
         boolean isLeading = false;
         try {
             if (!_deliveryList.exists()) {
@@ -371,13 +376,17 @@
             } else {
                 drResolver = new DefaultPublishingDRResolver();
             }
-            ivy.deliver(mrid, _pubRevision, _deliverpattern, 
-            		new DeliverOptions(_status, pubdate, 
-            				CacheManager.getInstance(settings, _cache), 
-            				drResolver, doValidate(settings), _replacedynamicrev));
-
+            
+            DeliverOptions options = new DeliverOptions(_status, pubdate, 
+    				CacheManager.getInstance(settings, _cache), 
+    				drResolver, doValidate(settings), _replacedynamicrev).setResolveId(_resolveId);
+            if (mrid == null) {
+            	ivy.deliver(_pubRevision, _deliverpattern, options);
+            } else {
+            	ivy.deliver(mrid, _pubRevision, _deliverpattern, options);
+            }
         } catch (Exception e) {
-            throw new BuildException("impossible to deliver " + mrid + ": " + e, e);
+            throw new BuildException("impossible to deliver " + mrid == null ? _resolveId : mrid + ": " + e, e);
         } finally {
             if (isLeading) {
                 if (_deliveryList.exists()) {

Modified: incubator/ivy/core/trunk/src/java/org/apache/ivy/core/cache/CacheManager.java
URL: http://svn.apache.org/viewvc/incubator/ivy/core/trunk/src/java/org/apache/ivy/core/cache/CacheManager.java?view=diff&rev=522640&r1=522639&r2=522640
==============================================================================
--- incubator/ivy/core/trunk/src/java/org/apache/ivy/core/cache/CacheManager.java (original)
+++ incubator/ivy/core/trunk/src/java/org/apache/ivy/core/cache/CacheManager.java Mon Mar 26 14:55:57 2007
@@ -18,6 +18,7 @@
 package org.apache.ivy.core.cache;
 
 import java.io.File;
+import java.io.FilenameFilter;
 
 import org.apache.ivy.core.IvyPatternHelper;
 import org.apache.ivy.core.module.descriptor.Artifact;
@@ -63,6 +64,16 @@
     
     public File getConfigurationResolveReportInCache(String resolveId, String conf) {
     	return new File(_cache, resolveId + "-" + conf + ".xml");
+    }
+    
+    public File[] getConfigurationResolveReportsInCache(final String resolveId) {
+		final String prefix = resolveId + "-";
+		final String suffix = ".xml";
+    	return _cache.listFiles(new FilenameFilter() {
+			public boolean accept(File dir, String name) {
+				return (name.startsWith(prefix) && name.endsWith(suffix));
+			}
+    	});
     }
 
     /**

Modified: incubator/ivy/core/trunk/src/java/org/apache/ivy/core/deliver/DeliverEngine.java
URL: http://svn.apache.org/viewvc/incubator/ivy/core/trunk/src/java/org/apache/ivy/core/deliver/DeliverEngine.java?view=diff&rev=522640&r1=522639&r2=522640
==============================================================================
--- incubator/ivy/core/trunk/src/java/org/apache/ivy/core/deliver/DeliverEngine.java (original)
+++ incubator/ivy/core/trunk/src/java/org/apache/ivy/core/deliver/DeliverEngine.java Mon Mar 26 14:55:57 2007
@@ -35,6 +35,7 @@
 import org.apache.ivy.core.settings.IvySettings;
 import org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorParser;
 import org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorUpdater;
+import org.apache.ivy.plugins.report.XmlReportParser;
 import org.apache.ivy.util.Message;
 import org.xml.sax.SAXException;
 
@@ -44,6 +45,31 @@
     public DeliverEngine(IvySettings settings) {
 		_settings = settings;
 	}
+
+    /**
+     * Delivers a resolved ivy file based upon last resolve call status.
+     * 
+     * If resolve report file cannot be found in cache, then it throws 
+     * an IllegalStateException (maybe resolve has not been called before ?).
+     *
+     * @param revision the revision to which the module should be delivered
+     * @param destIvyPattern the pattern to which the delivered ivy file should be written
+     * @param options the options with which deliver should be done 
+     */
+    public void deliver(String revision, String destIvyPattern, DeliverOptions options) throws IOException, ParseException {
+    	String resolveId = options.getResolveId();
+    	if (resolveId == null) {
+            throw new IllegalArgumentException("A resolveId must be specified for delivering.");
+    	}
+    	File[] files = options.getCache().getConfigurationResolveReportsInCache(resolveId);
+    	if (files.length == 0) {
+            throw new IllegalStateException("No previous resolve found for id '" + resolveId + "' Please resolve dependencies before delivering.");
+    	}
+    	XmlReportParser parser = new XmlReportParser();
+    	parser.parse(files[0]);
+    	ModuleRevisionId mrid = parser.getResolvedModule();
+    	deliver(mrid, revision, destIvyPattern, options);
+    }
 
     /**
      * Delivers a resolved ivy file based upon last resolve call status.

Modified: incubator/ivy/core/trunk/src/java/org/apache/ivy/core/deliver/DeliverOptions.java
URL: http://svn.apache.org/viewvc/incubator/ivy/core/trunk/src/java/org/apache/ivy/core/deliver/DeliverOptions.java?view=diff&rev=522640&r1=522639&r2=522640
==============================================================================
--- incubator/ivy/core/trunk/src/java/org/apache/ivy/core/deliver/DeliverOptions.java (original)
+++ incubator/ivy/core/trunk/src/java/org/apache/ivy/core/deliver/DeliverOptions.java Mon Mar 26 14:55:57 2007
@@ -32,6 +32,7 @@
 	private PublishingDependencyRevisionResolver _pdrResolver = new DefaultPublishingDRResolver(); 
 	private boolean _validate = true;
 	private boolean _resolveDynamicRevisions = true;
+	private String _resolveId;
 	
 	/**
 	 * Returns an instance of DeliverOptions with options corresponding to default values
@@ -154,8 +155,27 @@
 		return this;
 	}
 	
+	/**
+	 * Returns the id of a previous resolve to use for delivering.
+	 * @return the id of a previous resolve
+	 */
+	public String getResolveId() {
+		return _resolveId;
+	}
+	
+	/**
+	 * Sets the id of a previous resolve to use for delivering.
+	 * @param resolveId the id of a previous resolve
+	 * @return the instance of DeliverOptions on which the method has been called, 
+	 * for easy method chaining 
+	 */
+	public DeliverOptions setResolveId(String resolveId) {
+		_resolveId = resolveId;
+		return this;
+	}
+	
 	public String toString() {
-		return "status="+_status+" pubdate="+_pubdate+" validate="+_validate+" resolveDynamicRevisions="+_resolveDynamicRevisions+" cache="+_cache;
+		return "status="+_status+" pubdate="+_pubdate+" validate="+_validate+" resolveDynamicRevisions="+_resolveDynamicRevisions+" cache="+_cache+" resolveId="+_resolveId;
 	}
 	
 }

Modified: incubator/ivy/core/trunk/test/java/org/apache/ivy/ant/IvyDeliverTest.java
URL: http://svn.apache.org/viewvc/incubator/ivy/core/trunk/test/java/org/apache/ivy/ant/IvyDeliverTest.java?view=diff&rev=522640&r1=522639&r2=522640
==============================================================================
--- incubator/ivy/core/trunk/test/java/org/apache/ivy/ant/IvyDeliverTest.java (original)
+++ incubator/ivy/core/trunk/test/java/org/apache/ivy/ant/IvyDeliverTest.java Mon Mar 26 14:55:57 2007
@@ -33,6 +33,7 @@
 import org.apache.ivy.util.FileUtil;
 import org.apache.tools.ant.Project;
 import org.apache.tools.ant.taskdefs.Delete;
+import org.apache.tools.ant.types.Path;
 
 
 public class IvyDeliverTest extends TestCase {
@@ -103,6 +104,72 @@
         DependencyDescriptor[] dds = md.getDependencies();
         assertEquals(1, dds.length);
         assertEquals(ModuleRevisionId.newInstance("org1", "mod1.2", "2.2"), dds[0].getDependencyRevisionId());
+    }
+    
+    public void testWithResolveId() throws Exception {
+    	IvyResolve resolve = new IvyResolve();
+    	resolve.setProject(_project);
+    	resolve.setCache(_cache);
+    	resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-simple.xml"));
+    	resolve.setResolveId("withResolveId");
+    	resolve.execute();
+    	
+    	// resolve another ivy file
+    	resolve = new IvyResolve();
+    	resolve.setProject(_project);
+    	resolve.setCache(_cache);
+    	resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-latest.xml"));
+    	resolve.execute();
+    	
+    	_deliver.setResolveId("withResolveId");
+        _deliver.setPubrevision("1.2");
+        _deliver.setDeliverpattern("build/test/deliver/ivy-[revision].xml");
+        _deliver.execute();
+
+        // should have done the ivy delivering
+        File deliveredIvyFile = new File("build/test/deliver/ivy-1.2.xml");
+        assertTrue(deliveredIvyFile.exists()); 
+        ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(new IvySettings(), deliveredIvyFile.toURL(), true);
+        assertEquals(ModuleRevisionId.newInstance("apache", "resolve-simple", "1.2"), md.getModuleRevisionId());
+        DependencyDescriptor[] dds = md.getDependencies();
+        assertEquals(1, dds.length);
+        assertEquals(ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"), dds[0].getDependencyRevisionId());
+    }
+    
+    public void testWithResolveIdInAnotherBuild() throws Exception {
+    	// create a new build
+        Project other = new Project();
+        other.setProperty("ivy.settings.file", "test/repositories/ivysettings.xml");
+        other.setProperty("build", "build/test/deliver");
+
+        // do a resolve in the new build
+    	IvyResolve resolve = new IvyResolve();
+    	resolve.setProject(other);
+    	resolve.setCache(_cache);
+    	resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-simple.xml"));
+    	resolve.setResolveId("withResolveId");
+    	resolve.execute();
+
+    	// resolve another ivy file
+    	resolve = new IvyResolve();
+    	resolve.setProject(_project);
+    	resolve.setCache(_cache);
+    	resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-latest.xml"));
+    	resolve.execute();
+    	
+    	_deliver.setResolveId("withResolveId");
+        _deliver.setPubrevision("1.2");
+        _deliver.setDeliverpattern("build/test/deliver/ivy-[revision].xml");
+        _deliver.execute();
+
+        // should have done the ivy delivering
+        File deliveredIvyFile = new File("build/test/deliver/ivy-1.2.xml");
+        assertTrue(deliveredIvyFile.exists()); 
+        ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(new IvySettings(), deliveredIvyFile.toURL(), true);
+        assertEquals(ModuleRevisionId.newInstance("apache", "resolve-simple", "1.2"), md.getModuleRevisionId());
+        DependencyDescriptor[] dds = md.getDependencies();
+        assertEquals(1, dds.length);
+        assertEquals(ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"), dds[0].getDependencyRevisionId());
     }
 
     public void testWithBranch() throws Exception {