ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hi...@apache.org
Subject svn commit: r991943 - in /ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse: ./ cpcontainer/ resolve/ retrieve/ ui/menu/
Date Thu, 02 Sep 2010 14:17:51 GMT
Author: hibou
Date: Thu Sep  2 14:17:50 2010
New Revision: 991943

URL: http://svn.apache.org/viewvc?rev=991943&view=rev
Log:
Some refactoring so the IvyDE resolve API can be used elsewhere: this simplify a lot the standalone
retrieve.

Added:
    ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/resolve/
    ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/resolve/IvyResolver.java
      - copied, changed from r991920, ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/IvyResolver.java
    ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/resolve/IvyRunner.java
      - copied, changed from r991920, ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyRunner.java
    ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/resolve/ResolveResult.java
Removed:
    ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/IvyResolver.java
    ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyRunner.java
    ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/retrieve/IvyRetriever.java
Modified:
    ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathContainerMapper.java
    ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathResolver.java
    ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyResolveJob.java
    ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/menu/RetrieveAction.java

Modified: ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathContainerMapper.java
URL: http://svn.apache.org/viewvc/ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathContainerMapper.java?rev=991943&r1=991942&r2=991943&view=diff
==============================================================================
--- ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathContainerMapper.java
(original)
+++ ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathContainerMapper.java
Thu Sep  2 14:17:50 2010
@@ -33,6 +33,7 @@ import org.apache.ivy.core.module.id.Mod
 import org.apache.ivy.core.report.ArtifactDownloadReport;
 import org.apache.ivy.core.resolve.DownloadOptions;
 import org.apache.ivyde.eclipse.IvyPlugin;
+import org.apache.ivyde.eclipse.resolve.ResolveResult;
 import org.apache.ivyde.eclipse.workspaceresolver.WorkspaceResolver;
 import org.eclipse.core.runtime.IPath;
 import org.eclipse.core.runtime.IProgressMonitor;
@@ -64,14 +65,13 @@ public class IvyClasspathContainerMapper
                       */retrievedArtifacts;
 
     public IvyClasspathContainerMapper(IProgressMonitor monitor, Ivy ivy,
-            IvyClasspathContainerConfiguration conf, Collection all, Map artifactsByDependency,
-            Map retrievedArtifacts) {
+            IvyClasspathContainerConfiguration conf, ResolveResult resolveResult) {
         this.monitor = monitor;
         this.ivy = ivy;
         this.conf = conf;
-        this.all = all;
-        this.artifactsByDependency = artifactsByDependency;
-        this.retrievedArtifacts = retrievedArtifacts;
+        this.all = resolveResult.getArtifactReports();
+        this.artifactsByDependency = resolveResult.getArtifactsByDependency();
+        this.retrievedArtifacts = resolveResult.getRetrievedArtifacts();
     }
 
     public IClasspathEntry[] map() {

Modified: ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathResolver.java
URL: http://svn.apache.org/viewvc/ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathResolver.java?rev=991943&r1=991942&r2=991943&view=diff
==============================================================================
--- ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathResolver.java
(original)
+++ ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathResolver.java
Thu Sep  2 14:17:50 2010
@@ -18,30 +18,18 @@
 package org.apache.ivyde.eclipse.cpcontainer;
 
 import java.io.IOException;
-import java.text.ParseException;
 import java.util.HashSet;
 import java.util.Iterator;
-import java.util.LinkedHashSet;
-import java.util.Map;
 import java.util.Set;
 
 import org.apache.ivy.Ivy;
-import org.apache.ivy.core.IvyPatternHelper;
 import org.apache.ivy.core.module.descriptor.ModuleDescriptor;
 import org.apache.ivy.core.module.id.ModuleRevisionId;
 import org.apache.ivy.core.report.ArtifactDownloadReport;
-import org.apache.ivy.core.report.ResolveReport;
-import org.apache.ivy.core.retrieve.RetrieveOptions;
 import org.apache.ivy.util.Message;
-import org.apache.ivy.util.filter.ArtifactTypeFilter;
-import org.apache.ivyde.eclipse.FakeProjectManager;
-import org.apache.ivyde.eclipse.IvyPlugin;
-import org.apache.ivyde.eclipse.IvyResolver;
-import org.apache.ivyde.eclipse.retrieve.RetrieveSetup;
-import org.eclipse.core.resources.IFolder;
-import org.eclipse.core.resources.IProject;
+import org.apache.ivyde.eclipse.resolve.IvyResolver;
+import org.apache.ivyde.eclipse.resolve.ResolveResult;
 import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
 import org.eclipse.jdt.core.IClasspathEntry;
 
 /**
@@ -53,19 +41,14 @@ public class IvyClasspathResolver extend
 
     private IClasspathEntry[] classpathEntries = null;
 
-    /**
-     * Mapping of resolved artifact to their retrieved path, <code>null</code>
if there were no
-     * retrieve
-     * <p>
-     * The paths may be relative It shouldn't be an issue has every relative path should
be relative
-     * to the eclipse project FIXME: not sure why the Ivy API is returning a set of paths...
-     */
-    private Map/* <ArtifactDownloadReport, Set<String>> */retrievedArtifacts
= null;
-
     public IvyClasspathResolver(IvyClasspathContainerConfiguration conf, Ivy ivy,
             ModuleDescriptor md, boolean usePreviousResolveIfExist, IProgressMonitor monitor)
{
-        super(conf.getIvyXmlPath(), ivy, md, usePreviousResolveIfExist, monitor, conf.getConfs(),
-                conf.getJavaProject().getProject());
+        super(ivy, conf.getIvyXmlPath(), md, monitor, conf.getConfs(), conf.getJavaProject()
+                .getProject());
+        setUsePreviousResolveIfExist(usePreviousResolveIfExist);
+        setRetrievePattern(conf.getRetrievedClasspathSetup().getRetrievePattern());
+        setRetrieveSync(conf.getRetrievedClasspathSetup().isRetrieveSync());
+        setRetrieveTypes(conf.getRetrievedClasspathSetup().getRetrieveTypes());
         this.conf = conf;
     }
 
@@ -73,28 +56,24 @@ public class IvyClasspathResolver extend
         return classpathEntries;
     }
 
-    protected void postResolveOrRefresh() {
-        IvyClasspathContainerMapper mapper = new IvyClasspathContainerMapper(monitor, ivy,
conf,
-                all, artifactsByDependency, retrievedArtifacts);
+    protected void postResolveOrRefresh(ResolveResult resolveResult) throws IOException {
+        IvyClasspathContainerMapper mapper = new IvyClasspathContainerMapper(getMonitor(),
+                getIvy(), conf, resolveResult);
 
-        warnIfDuplicates(mapper);
+        warnIfDuplicates(mapper, resolveResult.getArtifactReports());
 
         classpathEntries = mapper.map();
     }
 
-    protected void postDoResolve(ResolveReport report) throws IOException {
-        maybeRetrieve(report);
-    }
-
     /**
      * Trigger a warn if there are duplicates entries due to configuration conflict.
      * <p>
      * TODO: the algorithm can be more clever and find which configuration are conflicting.
      * 
      */
-    private void warnIfDuplicates(IvyClasspathContainerMapper mapper) {
-        ArtifactDownloadReport[] reports = (ArtifactDownloadReport[]) all
-                .toArray(new ArtifactDownloadReport[all.size()]);
+    private void warnIfDuplicates(IvyClasspathContainerMapper mapper, Set artifactReports)
{
+        ArtifactDownloadReport[] reports = (ArtifactDownloadReport[]) artifactReports
+                .toArray(new ArtifactDownloadReport[0]);
 
         Set duplicates = new HashSet();
 
@@ -132,57 +111,7 @@ public class IvyClasspathResolver extend
                 buffer.append("\n  - ");
             }
         }
-        ivy.getLoggerEngine().log(buffer.toString(), Message.MSG_WARN);
-    }
-
-    private void maybeRetrieve(ResolveReport report) throws IOException {
-        if (!conf.isInheritedRetrievedClasspath()) {
-            return;
-        }
-        if (FakeProjectManager.isFake(conf.getJavaProject())) {
-            return;
-        }
-        RetrieveSetup setup = conf.getInheritedRetrievedClasspathSetup();
-        IProject project = conf.getJavaProject().getProject();
-        String pattern = project.getLocation().toPortableString() + "/"
-                + setup.getRetrievePattern();
-        monitor.setTaskName("retrieving dependencies in " + pattern);
-        RetrieveOptions options = new RetrieveOptions();
-        options.setSync(setup.isRetrieveSync());
-        options.setResolveId(report.getResolveId());
-        options.setConfs(confs);
-        String inheritedRetrieveTypes = setup.getRetrieveTypes();
-        if (inheritedRetrieveTypes != null && !inheritedRetrieveTypes.equals("*"))
{
-            options.setArtifactFilter(new ArtifactTypeFilter(IvyClasspathUtil
-                    .split(inheritedRetrieveTypes)));
-        }
-
-        // Actually do the retrieve
-        // FIXME here we will parse a report we already have
-        // with a better Java API, we could do probably better
-        int numberOfItemsRetrieved = ivy.retrieve(md.getModuleRevisionId(), pattern, options);
-        if (numberOfItemsRetrieved > 0) {
-            // Only refresh if we actually retrieved a file.
-            String refreshPath = IvyPatternHelper.getTokenRoot(setup.getRetrievePattern());
-            IFolder folder = project.getFolder(refreshPath);
-            RefreshFolderJob refreshFolderJob = new RefreshFolderJob(folder);
-            refreshFolderJob.schedule();
-        }
-
-        // recompute the files which has been copied to build a classpath
-        String resolvedPattern = IvyPatternHelper.substituteVariables(pattern, ivy.getSettings()
-                .getVariables());
-        try {
-            // FIXME same as above
-            retrievedArtifacts = ivy.getRetrieveEngine().determineArtifactsToCopy(
-                md.getModuleRevisionId(), resolvedPattern, options);
-        } catch (ParseException e) {
-            // ooops, failed to parse a report we already have...
-            IvyPlugin.log(IStatus.ERROR,
-                "failed to parse a resolve report in order to do the retrieve", e);
-            return;
-        }
-        all = new LinkedHashSet(retrievedArtifacts.keySet());
+        getIvy().getLoggerEngine().log(buffer.toString(), Message.MSG_WARN);
     }
 
 }

Modified: ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyResolveJob.java
URL: http://svn.apache.org/viewvc/ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyResolveJob.java?rev=991943&r1=991942&r2=991943&view=diff
==============================================================================
--- ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyResolveJob.java
(original)
+++ ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyResolveJob.java
Thu Sep  2 14:17:50 2010
@@ -34,6 +34,7 @@ import org.apache.ivy.plugins.version.Ve
 import org.apache.ivyde.eclipse.IvyDEException;
 import org.apache.ivyde.eclipse.IvyMarkerManager;
 import org.apache.ivyde.eclipse.IvyPlugin;
+import org.apache.ivyde.eclipse.resolve.IvyRunner;
 import org.eclipse.core.resources.ResourcesPlugin;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.IStatus;

Copied: ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/resolve/IvyResolver.java
(from r991920, ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/IvyResolver.java)
URL: http://svn.apache.org/viewvc/ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/resolve/IvyResolver.java?p2=ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/resolve/IvyResolver.java&p1=ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/IvyResolver.java&r1=991920&r2=991943&rev=991943&view=diff
==============================================================================
--- ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/IvyResolver.java
(original)
+++ ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/resolve/IvyResolver.java
Thu Sep  2 14:17:50 2010
@@ -15,36 +15,39 @@
  *  limitations under the License.
  *
  */
-package org.apache.ivyde.eclipse;
+package org.apache.ivyde.eclipse.resolve;
 
 import java.io.File;
 import java.io.IOException;
 import java.text.ParseException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
-import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
 import org.apache.ivy.Ivy;
+import org.apache.ivy.core.IvyPatternHelper;
 import org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor;
 import org.apache.ivy.core.module.descriptor.ModuleDescriptor;
 import org.apache.ivy.core.module.id.ModuleRevisionId;
-import org.apache.ivy.core.report.ArtifactDownloadReport;
 import org.apache.ivy.core.report.ConfigurationResolveReport;
 import org.apache.ivy.core.report.ResolveReport;
 import org.apache.ivy.core.resolve.IvyNode;
 import org.apache.ivy.core.resolve.ResolveData;
 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.plugins.report.XmlReportParser;
 import org.apache.ivy.plugins.resolver.DependencyResolver;
 import org.apache.ivy.util.Message;
+import org.apache.ivy.util.filter.ArtifactTypeFilter;
+import org.apache.ivyde.eclipse.FakeProjectManager;
+import org.apache.ivyde.eclipse.IvyPlugin;
+import org.apache.ivyde.eclipse.cpcontainer.IvyClasspathUtil;
 import org.apache.ivyde.eclipse.cpcontainer.IvyResolveJobListener;
+import org.apache.ivyde.eclipse.cpcontainer.RefreshFolderJob;
+import org.eclipse.core.resources.IFolder;
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.IStatus;
@@ -58,41 +61,75 @@ public class IvyResolver {
 
     private static final int MONITOR_LENGTH = 1000;
 
-    protected final Ivy ivy;
+    private final Ivy ivy;
 
-    protected final IProgressMonitor monitor;
+    private final IProgressMonitor monitor;
 
-    protected final ModuleDescriptor md;
+    private final ModuleDescriptor md;
 
-    private final boolean usePreviousResolveIfExist;
+    private boolean usePreviousResolveIfExist = false;
 
-    protected LinkedHashSet/* <ArtifactDownloadReport> */all;
+    private String[] confs;
 
-    private Set problemMessages;
+    private final IProject project;
 
-    protected String[] confs;
+    private final List confInput;
 
-    protected Map artifactsByDependency = new HashMap();
+    private String retrievePattern = null;
 
-    private final String ivyXmlPath;
+    private boolean retrieveSync = true;
 
-    protected final IProject project;
+    private String retrieveTypes = null;
 
-    private final List confInput;
+    private final String ivyXmlPath;
 
-    public IvyResolver(String ivyXmlPath, Ivy ivy, ModuleDescriptor md,
-            boolean usePreviousResolveIfExist, IProgressMonitor monitor, List confInput,
+    public IvyResolver(Ivy ivy, String ivyXmlPath, ModuleDescriptor md, IProgressMonitor
monitor, List confInput,
             IProject project) {
+        this.ivyXmlPath = ivyXmlPath;
         this.confInput = confInput;
         this.project = project;
-        this.ivyXmlPath = ivyXmlPath;
         this.ivy = ivy;
         this.md = md;
-        this.usePreviousResolveIfExist = usePreviousResolveIfExist;
         this.monitor = monitor;
         computeConfs(confInput);
     }
 
+    public void setUsePreviousResolveIfExist(boolean usePreviousResolveIfExist) {
+        this.usePreviousResolveIfExist = usePreviousResolveIfExist;
+    }
+
+    public void setRetrievePattern(String retrievePattern) {
+        this.retrievePattern = retrievePattern;
+    }
+
+    public void setRetrieveSync(boolean retrieveSync) {
+        this.retrieveSync = retrieveSync;
+    }
+
+    public void setRetrieveTypes(String retrieveTypes) {
+        this.retrieveTypes = retrieveTypes;
+    }
+
+    public Ivy getIvy() {
+        return ivy;
+    }
+
+    public IProgressMonitor getMonitor() {
+        return monitor;
+    }
+
+    public ModuleDescriptor getMd() {
+        return md;
+    }
+
+    public String[] getConfs() {
+        return confs;
+    }
+
+    public IProject getProject() {
+        return project;
+    }
+
     public IStatus resolve() {
         try {
             ivy.pushContext();
@@ -102,34 +139,30 @@ public class IvyResolver {
             monitor.beginTask("Resolve of " + toString(), MONITOR_LENGTH);
             monitor.setTaskName("Resolve of " + toString());
 
+            ResolveResult result = new ResolveResult();
+
             // context Classloader hook for commons logging used by httpclient
             // It will also be used by the SaxParserFactory in Ivy
             ClassLoader old = Thread.currentThread().getContextClassLoader();
             Thread.currentThread().setContextClassLoader(IvyResolver.class.getClassLoader());
             try {
-
                 if (usePreviousResolveIfExist) {
-                    IStatus status = resolveWithPrevious();
-                    if (!status.isOK()) {
-                        return status;
-                    }
+                    result = resolveWithPrevious();
                 } else {
-                    Message.info("\n\nIVYDE: calling resolve on " + ivyXmlPath + "\n");
-                    IStatus status = doResolve();
-                    if (!status.isOK()) {
-                        return status;
-                    }
+                    result = doResolve();
                 }
 
-                postResolveOrRefresh();
+                maybeRetrieve(result);
+
+                postResolveOrRefresh(result);
             } catch (ParseException e) {
-                String errorMsg = "Error while parsing the ivy file " + ivyXmlPath + "\n"
+                String errorMsg = "Error while parsing the ivy file from " + this.toString()
+ "\n"
                         + e.getMessage();
                 Message.error(errorMsg);
                 return new Status(IStatus.ERROR, IvyPlugin.ID, IStatus.ERROR, errorMsg, e);
             } catch (Exception e) {
-                String errorMsg = "Error while resolving dependencies for " + ivyXmlPath
+ "\n"
-                        + e.getMessage();
+                String errorMsg = "Error while resolving dependencies for " + this.toString()
+                        + "\n" + e.getMessage();
                 Message.error(errorMsg);
                 return new Status(IStatus.ERROR, IvyPlugin.ID, IStatus.ERROR, errorMsg, e);
             } finally {
@@ -138,10 +171,10 @@ public class IvyResolver {
                 ivy.getEventManager().removeIvyListener(ivyResolveJobListener);
             }
 
-            if (!problemMessages.isEmpty()) {
+            if (!result.getProblemMessages().isEmpty()) {
                 MultiStatus multiStatus = new MultiStatus(IvyPlugin.ID, IStatus.ERROR,
                         "Impossible to resolve dependencies of " + md.getModuleRevisionId(),
null);
-                for (Iterator iter = problemMessages.iterator(); iter.hasNext();) {
+                for (Iterator iter = result.getProblemMessages().iterator(); iter.hasNext();)
{
                     multiStatus.add(new Status(IStatus.ERROR, IvyPlugin.ID, IStatus.ERROR,
                             (String) iter.next(), null));
                 }
@@ -155,7 +188,7 @@ public class IvyResolver {
         }
     }
 
-    protected void postResolveOrRefresh() throws IOException {
+    protected void postResolveOrRefresh(ResolveResult resolveResult) throws IOException {
         // nothing to do by default
     }
 
@@ -170,68 +203,53 @@ public class IvyResolver {
         }
     }
 
-    private IStatus resolveWithPrevious() throws ParseException, IOException {
-        all = new LinkedHashSet();
-        problemMessages = new HashSet();
-        // we check if all required configurations have been
-        // resolved
-        boolean parsingOk = true;
-        for (int i = 0; i < confs.length && parsingOk; i++) {
+    private ResolveResult resolveWithPrevious() throws ParseException, IOException {
+        ResolveResult result = new ResolveResult();
+
+        // we check if all required configurations have been resolved
+        for (int i = 0; i < confs.length; i++) {
             File report = ivy.getResolutionCacheManager().getConfigurationResolveReportInCache(
                 ResolveOptions.getDefaultResolveId(md), confs[i]);
-            parsingOk = false;
             if (report.exists()) {
                 // found a report, try to parse it.
                 try {
                     XmlReportParser parser = new XmlReportParser();
                     parser.parse(report);
-                    all.addAll(Arrays.asList(parser.getArtifactReports()));
-                    parsingOk = true;
-                    findAllArtifactOnRefresh(parser);
+                    result.addArtifactReports(parser.getArtifactReports());
+                    findAllArtifactOnRefresh(parser, result);
                 } catch (ParseException e) {
                     Message.info("\n\nIVYDE: Error while parsing the report " + report
                             + ". Falling back by doing a resolve again.");
-                    // it fails, so let's try resolving
+                    // it fails, so let's try resolving for all configuration
+                    return doResolve();
                 }
             }
         }
-        if (!parsingOk) {
-            // no resolve previously done for at least one conf... we do it now
-            return doResolve();
-        }
-        return Status.OK_STATUS;
+
+        return result;
     }
 
-    private IStatus doResolve() throws ParseException, IOException {
+    private ResolveResult doResolve() throws ParseException, IOException {
         ResolveOptions resolveOption = new ResolveOptions().setConfs(confs);
         resolveOption.setValidate(ivy.getSettings().doValidate());
         ResolveReport report = ivy.resolve(md, resolveOption);
-        problemMessages = new HashSet(report.getAllProblemMessages());
 
-        all = new LinkedHashSet();
+        ResolveResult result = new ResolveResult(report);
+
         for (int i = 0; i < confs.length; i++) {
             ConfigurationResolveReport configurationReport = report
                     .getConfigurationReport(confs[i]);
             Set revisions = configurationReport.getModuleRevisionIds();
             for (Iterator it = revisions.iterator(); it.hasNext();) {
                 ModuleRevisionId revId = (ModuleRevisionId) it.next();
-                ArtifactDownloadReport[] aReports = configurationReport.getDownloadReports(revId);
-                all.addAll(Arrays.asList(aReports));
+                result.addArtifactReports(configurationReport.getDownloadReports(revId));
             }
         }
 
         confs = report.getConfigurations();
-        artifactsByDependency.putAll(getArtifactsByDependency(report));
-        if (monitor.isCanceled()) {
-            return Status.CANCEL_STATUS;
-        }
+        collectArtifactsByDependency(report, result);
 
-        postDoResolve(report);
-        return Status.OK_STATUS;
-    }
-
-    protected void postDoResolve(ResolveReport report) throws IOException {
-        // nothing to do by default
+        return result;
     }
 
     /**
@@ -241,7 +259,8 @@ public class IvyResolver {
      * @param parser
      * @throws ParseException
      */
-    private void findAllArtifactOnRefresh(XmlReportParser parser) throws ParseException {
+    private void findAllArtifactOnRefresh(XmlReportParser parser, ResolveResult result)
+            throws ParseException {
         ModuleRevisionId[] dependencyMrdis = parser.getDependencyRevisionIds();
         for (int iDep = 0; iDep < dependencyMrdis.length; iDep++) {
             DependencyResolver depResolver = ivy.getSettings().getResolver(dependencyMrdis[iDep]);
@@ -253,21 +272,64 @@ public class IvyResolver {
             ResolvedModuleRevision dependency = depResolver.getDependency(depDescriptor,
                 new ResolveData(ivy.getResolveEngine(), options));
             if (dependency != null) {
-                artifactsByDependency.put(dependencyMrdis[iDep], dependency.getDescriptor()
+                result.putArtifactsForDep(dependencyMrdis[iDep], dependency.getDescriptor()
                         .getAllArtifacts());
             }
         }
     }
 
-    private Map/* <ModuleRevisionId, Artifact[]> */getArtifactsByDependency(ResolveReport
r) {
-        Map result = new HashMap();
+    private void collectArtifactsByDependency(ResolveReport r, ResolveResult result) {
         for (Iterator it = r.getDependencies().iterator(); it.hasNext();) {
             IvyNode node = (IvyNode) it.next();
             if (node.getDescriptor() != null) {
-                result.put(node.getResolvedId(), node.getDescriptor().getAllArtifacts());
+                result.putArtifactsForDep(node.getResolvedId(), node.getDescriptor()
+                        .getAllArtifacts());
             }
         }
-        return result;
+    }
+
+    private void maybeRetrieve(ResolveResult result) throws IOException {
+        if (result.isPreviousUsed() || retrievePattern == null
+                || FakeProjectManager.isFake(project)) {
+            return;
+        }
+
+        String pattern = project.getLocation().toPortableString() + "/" + retrievePattern;
+        getMonitor().setTaskName("retrieving dependencies in " + pattern);
+        RetrieveOptions options = new RetrieveOptions();
+        options.setSync(retrieveSync);
+        options.setResolveId(result.getReport().getResolveId());
+        options.setConfs(getConfs());
+        if (retrieveTypes != null && !retrieveTypes.equals("*")) {
+            options.setArtifactFilter(new ArtifactTypeFilter(IvyClasspathUtil.split(retrieveTypes)));
+        }
+
+        // Actually do the retrieve
+        // FIXME here we will parse a report we already have
+        // with a better Java API, we could do probably better
+        int numberOfItemsRetrieved = getIvy().retrieve(getMd().getModuleRevisionId(), pattern,
+            options);
+        if (numberOfItemsRetrieved > 0) {
+            // Only refresh if we actually retrieved a file.
+            String refreshPath = IvyPatternHelper.getTokenRoot(retrievePattern);
+            IFolder folder = project.getFolder(refreshPath);
+            RefreshFolderJob refreshFolderJob = new RefreshFolderJob(folder);
+            refreshFolderJob.schedule();
+        }
+
+        // recompute the files which has been copied to build a classpath
+        String resolvedPattern = IvyPatternHelper.substituteVariables(pattern, getIvy()
+                .getSettings().getVariables());
+        try {
+            // FIXME same as above
+            Map retrievedArtifacts = getIvy().getRetrieveEngine().determineArtifactsToCopy(
+                getMd().getModuleRevisionId(), resolvedPattern, options);
+            result.setRetrievedArtifacts(retrievedArtifacts);
+        } catch (ParseException e) {
+            // ooops, failed to parse a report we already have...
+            IvyPlugin.log(IStatus.ERROR,
+                "failed to parse a resolve report in order to do the retrieve", e);
+        }
     }
 
     public String toString() {

Copied: ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/resolve/IvyRunner.java
(from r991920, ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyRunner.java)
URL: http://svn.apache.org/viewvc/ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/resolve/IvyRunner.java?p2=ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/resolve/IvyRunner.java&p1=ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyRunner.java&r1=991920&r2=991943&rev=991943&view=diff
==============================================================================
--- ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyRunner.java
(original)
+++ ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/resolve/IvyRunner.java
Thu Sep  2 14:17:50 2010
@@ -15,7 +15,7 @@
  *  limitations under the License.
  *
  */
-package org.apache.ivyde.eclipse.cpcontainer;
+package org.apache.ivyde.eclipse.resolve;
 
 import org.apache.ivy.Ivy;
 import org.eclipse.core.runtime.IProgressMonitor;

Added: ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/resolve/ResolveResult.java
URL: http://svn.apache.org/viewvc/ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/resolve/ResolveResult.java?rev=991943&view=auto
==============================================================================
--- ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/resolve/ResolveResult.java
(added)
+++ ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/resolve/ResolveResult.java
Thu Sep  2 14:17:50 2010
@@ -0,0 +1,134 @@
+/*
+ *  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.ivyde.eclipse.resolve;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.ivy.core.module.descriptor.Artifact;
+import org.apache.ivy.core.module.id.ModuleRevisionId;
+import org.apache.ivy.core.report.ArtifactDownloadReport;
+import org.apache.ivy.core.report.ResolveReport;
+import org.eclipse.core.runtime.MultiStatus;
+
+/**
+ * Container of result of an Ivy resolve and maybe retrieve
+ */
+public class ResolveResult {
+
+    private final boolean previousUsed;
+
+    private Set/* <ArtifactDownloadReport> */artifactReports = new LinkedHashSet();
+
+    private Set problemMessages = new HashSet();
+
+    private final ResolveReport report;
+
+    protected Map/* <ModuleRevisionId, Artifact[]> */artifactsByDependency = new HashMap();
+
+    /**
+     * Mapping of resolved artifact to their retrieved path, <code>null</code>
if there were no
+     * retrieve
+     * <p>
+     * The paths may be relative It shouldn't be an issue has every relative path should
be relative
+     * to the eclipse project FIXME: not sure why the Ivy API is returning a set of paths...
+     */
+    private Map/* <ArtifactDownloadReport, Set<String>> */retrievedArtifacts;
+
+    /**
+     * Constructor to be used when the resolve have been refreshed
+     */
+    ResolveResult() {
+        report = null;
+        previousUsed = true;
+    }
+
+    /**
+     * Constructor to be used based on the fresh resolve report
+     */
+    ResolveResult(ResolveReport report) {
+        this.report = report;
+        previousUsed = false;
+        problemMessages = new HashSet(report.getAllProblemMessages());
+    }
+
+    /**
+     * 
+     * @return <code>true</code> if the refresh has been successful
+     */
+    public boolean isPreviousUsed() {
+        return previousUsed;
+    }
+
+    /**
+     * 
+     * @return the report from the resolve, <code>null</code> if there was a
successful refresh
+     */
+    public ResolveReport getReport() {
+        return report;
+    }
+
+    /**
+     * Get the list of errors of the resolve. They will be used to build a {@link MultiStatus}.
+     * 
+     * @return the list of error message
+     */
+    public Set/* <String> */getProblemMessages() {
+        return problemMessages;
+    }
+
+    void addArtifactReports(ArtifactDownloadReport[] reports) {
+        artifactReports.addAll(Arrays.asList(reports));
+    }
+
+    /**
+     * 
+     * @return the reports of the artifacts resolved
+     */
+    public Set/* <ArtifactDownloadReport> */getArtifactReports() {
+        return artifactReports;
+    }
+
+    void putArtifactsForDep(ModuleRevisionId mrid, Artifact[] artifacts) {
+        artifactsByDependency.put(mrid, artifacts);
+    }
+
+    /**
+     * 
+     * @return the reports of the artifacts by dependency
+     */
+    public Map /* <ModuleRevisionId, Artifact[]> */getArtifactsByDependency() {
+        return artifactsByDependency;
+    }
+
+    void setRetrievedArtifacts(Map retrievedArtifacts) {
+        this.retrievedArtifacts = retrievedArtifacts;
+    }
+
+    /**
+     * 
+     * @return the path(s) of the retrieved artifacts
+     */
+    public Map/* <ArtifactDownloadReport, Set<String>> */getRetrievedArtifacts()
{
+        return retrievedArtifacts;
+    }
+}

Modified: ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/menu/RetrieveAction.java
URL: http://svn.apache.org/viewvc/ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/menu/RetrieveAction.java?rev=991943&r1=991942&r2=991943&view=diff
==============================================================================
--- ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/menu/RetrieveAction.java
(original)
+++ ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/menu/RetrieveAction.java
Thu Sep  2 14:17:50 2010
@@ -17,11 +17,15 @@
  */
 package org.apache.ivyde.eclipse.ui.menu;
 
+import java.util.List;
+
 import org.apache.ivy.Ivy;
 import org.apache.ivy.core.module.descriptor.ModuleDescriptor;
 import org.apache.ivyde.eclipse.IvyMarkerManager;
 import org.apache.ivyde.eclipse.IvyPlugin;
-import org.apache.ivyde.eclipse.retrieve.IvyRetriever;
+import org.apache.ivyde.eclipse.cpcontainer.IvyClasspathUtil;
+import org.apache.ivyde.eclipse.resolve.IvyResolver;
+import org.apache.ivyde.eclipse.retrieve.RetrieveSetup;
 import org.apache.ivyde.eclipse.retrieve.StandaloneRetrieveSetup;
 import org.apache.ivyde.eclipse.retrieve.StandaloneRetrieveSetupState;
 import org.eclipse.core.runtime.IStatus;
@@ -30,14 +34,14 @@ import org.eclipse.jface.action.Action;
 
 public class RetrieveAction extends Action {
 
-    private final StandaloneRetrieveSetup retrieveSetup;
+    private final StandaloneRetrieveSetup setup;
 
     public RetrieveAction(StandaloneRetrieveSetup retrieveSetup) {
-        this.retrieveSetup = retrieveSetup;
+        this.setup = retrieveSetup;
     }
 
     public void run() {
-        StandaloneRetrieveSetupState state = retrieveSetup.getState();
+        StandaloneRetrieveSetupState state = setup.getState();
         Ivy ivy = state.getSafelyIvy();
         if (ivy == null) {
             return;
@@ -46,15 +50,16 @@ public class RetrieveAction extends Acti
         if (md == null) {
             return;
         }
-        IvyRetriever retriever = new IvyRetriever(ivy, md, false, new NullProgressMonitor(),
-                retrieveSetup);
-        IStatus status = retriever.resolve();
+        RetrieveSetup retrieveSetup = setup.getRetrieveSetup();
+        List confs = IvyClasspathUtil.split(retrieveSetup.getRetrieveConfs());
+        IvyResolver resolver = new IvyResolver(ivy, setup.getIvyXmlPath(), md,
+                new NullProgressMonitor(), confs, setup.getProject());
+        IStatus status = resolver.resolve();
         IvyMarkerManager ivyMarkerManager = IvyPlugin.getDefault().getIvyMarkerManager();
-        ivyMarkerManager.setResolveStatus(status, retrieveSetup.getProject(),
-            retrieveSetup.getIvyXmlPath());
+        ivyMarkerManager.setResolveStatus(status, setup.getProject(), setup.getIvyXmlPath());
         if (status.isOK() || status.getCode() == IStatus.CANCEL) {
-            IvyPlugin.log(IStatus.INFO, "Successful retrieve of '" + retrieveSetup.getName()
-                    + "' in " + retrieveSetup.getProject().getName(), null);
+            IvyPlugin.log(IStatus.INFO, "Successful retrieve of '" + setup.getName() + "'
in "
+                    + setup.getProject().getName(), null);
             return;
         }
         IvyPlugin.log(status);



Mime
View raw message