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/28 21:22:37 UTC

svn commit: r523466 - in /incubator/ivy/core/trunk: ./ doc/doc/use/ src/java/org/apache/ivy/ant/

Author: maartenc
Date: Wed Mar 28 14:22:36 2007
New Revision: 523466

URL: http://svn.apache.org/viewvc?view=rev&rev=523466
Log:
IvyArtifactProperty and IvyArtifactReport tasks should be a post resolve task (IVY-452)

Modified:
    incubator/ivy/core/trunk/CHANGES.txt
    incubator/ivy/core/trunk/doc/doc/use/artifactproperty.html
    incubator/ivy/core/trunk/doc/doc/use/artifactreport.html
    incubator/ivy/core/trunk/doc/doc/use/cachepath.html
    incubator/ivy/core/trunk/doc/doc/use/postresolvetask.html
    incubator/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyArtifactProperty.java
    incubator/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyArtifactReport.java

Modified: incubator/ivy/core/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/ivy/core/trunk/CHANGES.txt?view=diff&rev=523466&r1=523465&r2=523466
==============================================================================
--- incubator/ivy/core/trunk/CHANGES.txt (original)
+++ incubator/ivy/core/trunk/CHANGES.txt Wed Mar 28 14:22:36 2007
@@ -9,6 +9,7 @@
 =====================================
 - NEW: define artifacts not declared by the dependency module descriptor (IVY-419)
 
+- IMPROVE: IvyArtifactProperty and IvyArtifactReport tasks should be a post resolve task (IVY-452)
 - IMPROVE: Rename ivy configuration in settings to remove ambiguity on configuration meaning (IVY-438)
 - IMPROVE: Please typedef CacheResolver as "cache" for us (IVY-359)
 - IMPROVE: ivy:retrieve should be able to create symlinks (IVY-353) (thanks to John Williams)

Modified: incubator/ivy/core/trunk/doc/doc/use/artifactproperty.html
URL: http://svn.apache.org/viewvc/incubator/ivy/core/trunk/doc/doc/use/artifactproperty.html?view=diff&rev=523466&r1=523465&r2=523466
==============================================================================
--- incubator/ivy/core/trunk/doc/doc/use/artifactproperty.html (original)
+++ incubator/ivy/core/trunk/doc/doc/use/artifactproperty.html Wed Mar 28 14:22:36 2007
@@ -27,6 +27,8 @@
 <div class="since">since 1.1</div>
 Sets an ant property for each dependency artifacts previously resolved.
 
+<span class="since">since 1.5</span> This is a [[ant:postresolvetask post resolve task]], with all the behaviour and attributes common to all post resolve tasks.
+
 Please prefer the use of retrieve + standard ant path creation, which make your build more independent from ivy (once artifacts are properly retrieved, ivy is not required any more).
 
 The property name and value are generated using the classical pattern concept, all artifact tokens and ivy variables being available.

Modified: incubator/ivy/core/trunk/doc/doc/use/artifactreport.html
URL: http://svn.apache.org/viewvc/incubator/ivy/core/trunk/doc/doc/use/artifactreport.html?view=diff&rev=523466&r1=523465&r2=523466
==============================================================================
--- incubator/ivy/core/trunk/doc/doc/use/artifactreport.html (original)
+++ incubator/ivy/core/trunk/doc/doc/use/artifactreport.html Wed Mar 28 14:22:36 2007
@@ -27,6 +27,8 @@
 <span class="since">since 1.4</span>
 The artifactreport task generates an xml report of all artifacts dependencies resolved by the last <a href="../../doc/use/resolve.html">resolve</a> task call during the same build.
 
+<span class="since">since 1.5</span> This is a [[ant:postresolvetask post resolve task]], with all the behaviour and attributes common to all post resolve tasks.
+
 This report is different from the standard <a href="../../doc/use/report.html">report</a> which reports all modules and artifacts, whle this report is much simpler and focuses only on artifacts, and gives more information on artifacts, such as the original location and the retrieve location. 
 
 It is thus easy to use to generate things like a classpath file for an IDE.

Modified: incubator/ivy/core/trunk/doc/doc/use/cachepath.html
URL: http://svn.apache.org/viewvc/incubator/ivy/core/trunk/doc/doc/use/cachepath.html?view=diff&rev=523466&r1=523465&r2=523466
==============================================================================
--- incubator/ivy/core/trunk/doc/doc/use/cachepath.html (original)
+++ incubator/ivy/core/trunk/doc/doc/use/cachepath.html Wed Mar 28 14:22:36 2007
@@ -26,7 +26,7 @@
 	<textarea id="xooki-source">
 Constructs an ant path consisting of artifacts in ivy cache (or origin location with depending on useOrigin setting) for a resolved module configuration.
 
-This is a <a href="../../doc/use/postresolvetask.html">post resolve task</a>, with all the behaviour and attributes common to all post resolve tasks.
+This is a [[ant:postresolvetask post resolve task]], with all the behaviour and attributes common to all post resolve tasks.
 
 Please prefer the use of retrieve + standard ant path creation, which make your build more independent from ivy (once artifacts are properly retrieved, ivy is not required any more).
 

Modified: incubator/ivy/core/trunk/doc/doc/use/postresolvetask.html
URL: http://svn.apache.org/viewvc/incubator/ivy/core/trunk/doc/doc/use/postresolvetask.html?view=diff&rev=523466&r1=523465&r2=523466
==============================================================================
--- incubator/ivy/core/trunk/doc/doc/use/postresolvetask.html (original)
+++ incubator/ivy/core/trunk/doc/doc/use/postresolvetask.html Wed Mar 28 14:22:36 2007
@@ -31,6 +31,8 @@
 <li>[[ant:retrieve]]</li>
 <li>[[ant:cachefileset]]</li>
 <li>[[ant:cachepath]]</li>
+<li>[[ant:artifactproperty]] <span class="since">(since 1.5)</span></li>
+<li>[[ant:artifactreport]] <span class="since">(since 1.5)</span></li>
 </ul>
 
 All these tasks will trigger automatically a resolve if:

Modified: incubator/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyArtifactProperty.java
URL: http://svn.apache.org/viewvc/incubator/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyArtifactProperty.java?view=diff&rev=523466&r1=523465&r2=523466
==============================================================================
--- incubator/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyArtifactProperty.java (original)
+++ incubator/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyArtifactProperty.java Wed Mar 28 14:22:36 2007
@@ -22,9 +22,7 @@
 import org.apache.ivy.core.IvyPatternHelper;
 import org.apache.ivy.core.cache.CacheManager;
 import org.apache.ivy.core.module.descriptor.Artifact;
-import org.apache.ivy.core.module.id.ModuleId;
 import org.apache.ivy.core.resolve.ResolveOptions;
-import org.apache.ivy.core.settings.IvySettings;
 import org.apache.ivy.plugins.report.XmlReportParser;
 import org.apache.tools.ant.BuildException;
 
@@ -34,23 +32,10 @@
  * 
  * @author Xavier Hanin
  */
-public class IvyArtifactProperty extends IvyTask {
-    private String _conf;
+public class IvyArtifactProperty extends IvyPostResolveTask {
     private String _name;
     private String _value;
-    
-    private String _organisation;
-    private String _module;
-    private boolean _haltOnFailure = true;
-    private File _cache;
-    private String _resolveId;
 
-    public String getConf() {
-        return _conf;
-    }
-    public void setConf(String conf) {
-        _conf = conf;
-    }
     public String getName() {
         return _name;
     }
@@ -63,79 +48,17 @@
     public void setValue(String value) {
         _value = value;
     }
-    public String getModule() {
-        return _module;
-    }
-    public void setModule(String module) {
-        _module = module;
-    }
-    public String getOrganisation() {
-        return _organisation;
-    }
-    public void setOrganisation(String organisation) {
-        _organisation = organisation;
-    }
-    public boolean isHaltonfailure() {
-        return _haltOnFailure;
-    }
-    public void setHaltonfailure(boolean haltOnFailure) {
-        _haltOnFailure = haltOnFailure;
-    }
-    public File getCache() {
-        return _cache;
-    }
-    public void setCache(File cache) {
-        _cache = cache;
-    }
-    public String getResolveId() {
-    	return _resolveId;
-    }
-    public void setResolveId(String resolveId) {
-    	_resolveId = resolveId;
-    }
 
     public void execute() throws BuildException {
-        IvySettings settings = getSettings(); 
-        
-        _organisation = getProperty(_organisation, settings, "ivy.organisation", _resolveId);
-        _module = getProperty(_module, settings, "ivy.module", _resolveId);
-
-        if (_cache == null) {
-            _cache = settings.getDefaultCache();
-        }
-
-        ensureResolved(isHaltonfailure(), false, getOrganisation(), getModule(), _resolveId, _cache);
-        
-        _conf = getProperty(_conf, settings, "ivy.resolved.configurations", _resolveId);
-        if ("*".equals(_conf)) {
-            _conf = getProperty(settings, "ivy.resolved.configurations", _resolveId);
-            if (_conf == null) {
-                throw new BuildException("bad provided for ivy artifactproperty: * can only be used with a prior call to <resolve/>");
-            }
-        }
-
-        _organisation = getProperty(_organisation, settings, "ivy.organisation", _resolveId);
-        _module = getProperty(_module, settings, "ivy.module", _resolveId);
-        
-        
-        if ((_organisation == null) && (_resolveId == null)) {
-            throw new BuildException("no organisation provided for ivy artifactproperty: It can either be set explicitely via the attribute 'organisation' or via 'ivy.organisation' property or a prior call to <resolve/>");
-        }
-        if ((_module == null) && (_resolveId == null)) {
-            throw new BuildException("no module name provided for ivy artifactproperty: It can either be set explicitely via the attribute 'module' or via 'ivy.module' property or a prior call to <resolve/>");
-        }
-        if (_conf == null) {
-            throw new BuildException("no conf provided for ivy artifactproperty: It can either be set explicitely via the attribute 'conf' or via 'ivy.resolved.configurations' property or a prior call to <resolve/>");
-        }
-        
-        String resolveId = getResolveId();
-        if (resolveId == null) {
-        	resolveId = ResolveOptions.getDefaultResolveId(new ModuleId(_organisation, _module));
-        }
+    	prepareAndCheck();
 
         try {
-        	CacheManager cacheMgr = getIvyInstance().getCacheManager(_cache);
-            String[] confs = splitConfs(_conf);
+        	CacheManager cacheMgr = getIvyInstance().getCacheManager(getCache());
+            String[] confs = splitConfs(getConf());
+            String resolveId = getResolveId();
+            if (resolveId == null) {
+            	resolveId = ResolveOptions.getDefaultResolveId(getResolvedModuleId());
+            }
             XmlReportParser parser = new XmlReportParser();
             for (int i = 0; i < confs.length; i++) {
             	File report = cacheMgr.getConfigurationResolveReportInCache(resolveId, confs[i]);
@@ -144,8 +67,8 @@
                 Artifact[] artifacts = parser.getArtifacts();
                 for (int j = 0; j < artifacts.length; j++) {
                     Artifact artifact = artifacts[j];
-                    String name = IvyPatternHelper.substitute(settings.substitute(getName()), artifact, confs[i]);
-                    String value = IvyPatternHelper.substitute(settings.substitute(getValue()), artifact, confs[i]);
+                    String name = IvyPatternHelper.substitute(getSettings().substitute(getName()), artifact, confs[i]);
+                    String value = IvyPatternHelper.substitute(getSettings().substitute(getValue()), artifact, confs[i]);
                     getProject().setProperty(name, value);
                 }
             }

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=523466&r1=523465&r2=523466
==============================================================================
--- 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 Wed Mar 28 14:22:36 2007
@@ -34,7 +34,6 @@
 import javax.xml.transform.sax.TransformerHandler;
 import javax.xml.transform.stream.StreamResult;
 
-import org.apache.ivy.Ivy;
 import org.apache.ivy.core.cache.ArtifactOrigin;
 import org.apache.ivy.core.cache.CacheManager;
 import org.apache.ivy.core.module.descriptor.Artifact;
@@ -43,7 +42,6 @@
 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;
 import org.xml.sax.SAXException;
@@ -53,13 +51,9 @@
 /**
  * Generates a report of all artifacts involved during the last resolve. 
  */
-public class IvyArtifactReport extends IvyTask {
+public class IvyArtifactReport extends IvyPostResolveTask {
     private File _tofile;
-    private String _conf;
     private String _pattern;
-    private boolean _haltOnFailure = true;
-    private File _cache;
-    private String _resolveId;
 
     public File getTofile() {
         return _tofile;
@@ -67,96 +61,45 @@
     public void setTofile(File tofile) {
         _tofile = tofile;
     }
-    public String getConf() {
-        return _conf;
-    }
-    public void setConf(String conf) {
-        _conf = conf;
-    }
     public String getPattern() {
         return _pattern;
     }
     public void setPattern(String pattern) {
         _pattern = pattern;
     }
-    public boolean isHaltonfailure() {
-        return _haltOnFailure;
-    }
-    public void setHaltonfailure(boolean haltOnFailure) {
-        _haltOnFailure = haltOnFailure;
-    }
-    public File getCache() {
-        return _cache;
-    }
-    public void setCache(File cache) {
-        _cache = cache;
-    }
-    public String getResolveId() {
-    	return _resolveId;
-    }
-    public void setResolveId(String resolveId) {
-    	_resolveId = resolveId;
-    }
 
     public void execute() throws BuildException {
+    	prepareAndCheck();
         if (_tofile == null) {
             throw new BuildException("no destination file name: please provide it through parameter 'tofile'");
         }
 
-        Ivy ivy = getIvyInstance();
-        IvySettings settings = ivy.getSettings();
-        if (_cache == null) {
-            _cache = settings.getDefaultCache();
-        }
+        _pattern = getProperty(_pattern, getSettings(), "ivy.retrieve.pattern");
 
-        ensureResolved(isHaltonfailure(), false, null, null, _resolveId, _cache);
-
-        String organisation = getProperty(null, settings, "ivy.organisation", _resolveId);
-        String module = getProperty(null, settings, "ivy.module", _resolveId);
-        String revision = getProperty(Ivy.getWorkingRevision(), settings, "ivy.revision", _resolveId);
-
-        _pattern = getProperty(_pattern, settings, "ivy.retrieve.pattern");
-        _conf = getProperty(_conf, settings, "ivy.resolved.configurations", _resolveId);
-        if ("*".equals(_conf)) {
-            _conf = getProperty(settings, "ivy.resolved.configurations", _resolveId);
-            if (_conf == null) {
-                throw new BuildException("bad provided for ivy artifact report task: * can only be used with a prior call to <resolve/>");
-            }
-        }
-
-        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) {
-            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) {
-            throw new BuildException("no conf provided for ivy artifact report task: It can either be set explicitely via the attribute 'conf' or via 'ivy.resolved.configurations' property or a prior call to <resolve/>");
-        }
         try {
-            String[] confs = splitConfs(_conf);
-            CacheManager cacheManager = CacheManager.getInstance(settings, _cache);
+            String[] confs = splitConfs(getConf());
+            CacheManager cacheManager = CacheManager.getInstance(getSettings(), getCache());
             ModuleDescriptor md = null;
-            if (_resolveId != null) {
-            	md = (ModuleDescriptor) getResolvedDescriptor(_resolveId);
+            if (getResolveId() != null) {
+            	md = (ModuleDescriptor) getResolvedDescriptor(getResolveId());
             } else {
-            	md = (ModuleDescriptor) getResolvedDescriptor(organisation, module, false);
+            	md = (ModuleDescriptor) getResolvedDescriptor(getOrganisation(), getModule(), false);
             }
-			IvyNode[] dependencies = ivy.getResolveEngine()
+			IvyNode[] dependencies = getIvyInstance().getResolveEngine()
             	.getDependencies(md, 
             			new ResolveOptions()
             				.setConfs(confs)
             				.setCache(cacheManager)
-            				.setResolveId(_resolveId)
-            				.setValidate(doValidate(settings)),
+            				.setResolveId(getResolveId())
+            				.setValidate(doValidate(getSettings())),
             			null);
 
-            Map artifactsToCopy = ivy.getRetrieveEngine().determineArtifactsToCopy(
-            		ModuleRevisionId.newInstance(organisation, module, revision), 
+            Map artifactsToCopy = getIvyInstance().getRetrieveEngine().determineArtifactsToCopy(
+            		ModuleRevisionId.newInstance(getOrganisation(), getModule(), getRevision()), 
             		_pattern, 
             		new RetrieveOptions()
             			.setConfs(confs)
-            			.setResolveId(_resolveId)
+            			.setResolveId(getResolveId())
             			.setCache(cacheManager));
             
             Map moduleRevToArtifactsMap = new HashMap();
@@ -170,8 +113,7 @@
                 moduleRevArtifacts.add(artifact);
             }
 
-            CacheManager cache = getCacheManager();
-            generateXml(cache, dependencies, moduleRevToArtifactsMap, artifactsToCopy);
+            generateXml(cacheManager, dependencies, moduleRevToArtifactsMap, artifactsToCopy);
         } catch (ParseException e) {
             log(e.getMessage(), Project.MSG_ERR);
             throw new BuildException("syntax errors in ivy file: "+e, e);
@@ -338,10 +280,5 @@
         }
         return (p.startsWith(l)) ? p.substring(l.length()) : p;
     }
-
-	protected CacheManager getCacheManager() {
-		CacheManager cache = new CacheManager(getSettings(), _cache);
-		return cache;
-	}
 
 }