ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hi...@apache.org
Subject svn commit: r988166 - in /ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse: ./ cpcontainer/ retrieve/ ui/menu/
Date Mon, 23 Aug 2010 16:02:50 GMT
Author: hibou
Date: Mon Aug 23 16:02:50 2010
New Revision: 988166

URL: http://svn.apache.org/viewvc?rev=988166&view=rev
Log:
IVYDE-56
 * the standalone retrieve needs a resolve

Added:
    ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/IvyResolver.java
  (contents, props changed)
      - copied, changed from r988101, ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyResolveJobThread.java
    ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathResolver.java
  (contents, props changed)
      - copied, changed from r988101, ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyResolveJobThread.java
    ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/retrieve/IvyRetriever.java
  (with props)
Removed:
    ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyResolveJobThread.java
Modified:
    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/IvyMenuContributionItem.java
    ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/menu/RetrieveAction.java

Copied: ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/IvyResolver.java
(from r988101, ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyResolveJobThread.java)
URL: http://svn.apache.org/viewvc/ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/IvyResolver.java?p2=ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/IvyResolver.java&p1=ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyResolveJobThread.java&r1=988101&r2=988166&rev=988166&view=diff
==============================================================================
--- ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyResolveJobThread.java
(original)
+++ ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/IvyResolver.java
Mon Aug 23 16:02:50 2010
@@ -15,7 +15,7 @@
  *  limitations under the License.
  *
  */
-package org.apache.ivyde.eclipse.cpcontainer;
+package org.apache.ivyde.eclipse;
 
 import java.io.File;
 import java.io.IOException;
@@ -31,7 +31,6 @@ 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;
@@ -42,125 +41,94 @@ import org.apache.ivy.core.resolve.IvyNo
 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.retrieve.RetrieveSetup;
-import org.eclipse.core.resources.IFolder;
+import org.apache.ivyde.eclipse.cpcontainer.IvyResolveJobListener;
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.MultiStatus;
 import org.eclipse.core.runtime.Status;
-import org.eclipse.jdt.core.IClasspathEntry;
 
 /**
  * Eclipse classpath container that will contain the ivy resolved entries.
  */
-public class IvyResolveJobThread extends Thread {
+public class IvyResolver {
 
     private static final int MONITOR_LENGTH = 1000;
 
-    private final Ivy ivy;
+    protected final Ivy ivy;
 
-    private final IProgressMonitor monitor;
+    protected final IProgressMonitor monitor;
 
-    private final IvyClasspathContainerConfiguration conf;
-
-    private final ModuleDescriptor md;
+    protected final ModuleDescriptor md;
 
     private final boolean usePreviousResolveIfExist;
 
-    private IStatus status = null;
-
-    private IClasspathEntry[] classpathEntries = null;
-
     private LinkedHashSet/* <ArtifactDownloadReport> */all;
 
     private List problemMessages;
 
-    private String[] confs;
+    protected String[] confs;
 
     private Map 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
= null;
+    private final String ivyXmlPath;
+
+    protected final IProject project;
 
-    public IvyResolveJobThread(IvyClasspathContainerConfiguration conf, Ivy ivy,
-            ModuleDescriptor md, boolean usePreviousResolveIfExist, IProgressMonitor monitor)
{
+    public IvyResolver(String ivyXmlPath, Ivy ivy, ModuleDescriptor md,
+            boolean usePreviousResolveIfExist, IProgressMonitor monitor, List confInput,
+            IProject project) {
+        this.project = project;
+        this.ivyXmlPath = ivyXmlPath;
         this.ivy = ivy;
         this.md = md;
         this.usePreviousResolveIfExist = usePreviousResolveIfExist;
         this.monitor = monitor;
-        this.conf = conf;
+        computeConfs(confInput);
     }
 
-    public IStatus getStatus() {
-        return status;
-    }
-
-    public IClasspathEntry[] getClasspathEntries() {
-        return classpathEntries;
-    }
-
-    public void run() {
+    public IStatus resolve() {
         try {
             ivy.pushContext();
             IvyResolveJobListener ivyResolveJobListener = new IvyResolveJobListener(monitor);
             ivy.getEventManager().addIvyListener(ivyResolveJobListener);
 
-            monitor.beginTask("Resolve of " + conf.toString(), MONITOR_LENGTH);
-            monitor.setTaskName("Resolve of " + conf.toString());
+            monitor.beginTask("Resolve of " + toString(), MONITOR_LENGTH);
+            monitor.setTaskName("Resolve of " + toString());
 
             // 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(IvyResolveJobThread.class.getClassLoader());
+            Thread.currentThread().setContextClassLoader(IvyResolver.class.getClassLoader());
             try {
-                computeConfs();
 
                 if (usePreviousResolveIfExist) {
-                    if (!resolveWithPrevious()) {
-                        // resolve canceled
-                        return;
+                    IStatus status = resolveWithPrevious();
+                    if (!status.isOK()) {
+                        return status;
                     }
                 } else {
-                    Message.info("\n\nIVYDE: calling resolve on " + conf.getIvyXmlPath()
+ "\n");
-                    if (!resolve()) {
-                        // resolve canceled
-                        return;
+                    Message.info("\n\nIVYDE: calling resolve on " + ivyXmlPath + "\n");
+                    IStatus status = doResolve();
+                    if (!status.isOK()) {
+                        return status;
                     }
                 }
 
-                IvyClasspathContainerMapper mapper = new IvyClasspathContainerMapper(monitor,
ivy,
-                        conf, all, artifactsByDependency, retrievedArtifacts);
-
-                warnIfDuplicates(mapper);
-
-                classpathEntries = mapper.map();
+                postResolveOrRefresh();
             } catch (ParseException e) {
-                String errorMsg = "Error while parsing the ivy file " + conf.getIvyXmlPath()
+ "\n"
+                String errorMsg = "Error while parsing the ivy file " + ivyXmlPath + "\n"
                         + e.getMessage();
                 Message.error(errorMsg);
-                status = new Status(IStatus.ERROR, IvyPlugin.ID, IStatus.ERROR, errorMsg,
e);
-                return;
+                return new Status(IStatus.ERROR, IvyPlugin.ID, IStatus.ERROR, errorMsg, e);
             } catch (Exception e) {
-                String errorMsg = "Error while resolving dependencies for " + conf.getIvyXmlPath()
-                        + "\n" + e.getMessage();
+                String errorMsg = "Error while resolving dependencies for " + ivyXmlPath
+ "\n"
+                        + e.getMessage();
                 Message.error(errorMsg);
-                status = new Status(IStatus.ERROR, IvyPlugin.ID, IStatus.ERROR, errorMsg,
e);
-                return;
+                return new Status(IStatus.ERROR, IvyPlugin.ID, IStatus.ERROR, errorMsg, e);
             } finally {
                 Thread.currentThread().setContextClassLoader(old);
                 monitor.done();
@@ -174,20 +142,23 @@ public class IvyResolveJobThread extends
                     multiStatus.add(new Status(IStatus.ERROR, IvyPlugin.ID, IStatus.ERROR,
                             (String) iter.next(), null));
                 }
-                status = multiStatus;
-                return;
+                return multiStatus;
             }
 
-            status = Status.OK_STATUS;
+            return Status.OK_STATUS;
         } catch (Throwable e) {
-            status = new Status(IStatus.ERROR, IvyPlugin.ID, IStatus.ERROR, "The resolve
job of "
-                    + conf + " has unexpectedly stopped", e);
+            return new Status(IStatus.ERROR, IvyPlugin.ID, IStatus.ERROR, "The resolve job
of "
+                    + toString() + " has unexpectedly stopped", e);
         }
     }
 
-    private void computeConfs() {
+    protected void postResolveOrRefresh() throws IOException {
+        // nothing to do by default
+    }
+
+    private void computeConfs(List/* <String> */confInput) {
         Set configurations = new HashSet();
-        configurations.addAll(conf.getConfs());
+        configurations.addAll(confInput);
 
         if (configurations.contains("*")) {
             confs = md.getConfigurationsNames();
@@ -196,7 +167,7 @@ public class IvyResolveJobThread extends
         }
     }
 
-    private boolean resolveWithPrevious() throws ParseException, IOException {
+    private IStatus resolveWithPrevious() throws ParseException, IOException {
         all = new LinkedHashSet();
         problemMessages = new ArrayList();
         // we check if all required configurations have been
@@ -223,12 +194,12 @@ public class IvyResolveJobThread extends
         }
         if (!parsingOk) {
             // no resolve previously done for at least one conf... we do it now
-            return resolve();
+            return doResolve();
         }
-        return true;
+        return Status.OK_STATUS;
     }
 
-    private boolean resolve() throws ParseException, IOException {
+    private IStatus doResolve() throws ParseException, IOException {
         ResolveOptions resolveOption = new ResolveOptions().setConfs(confs);
         resolveOption.setValidate(ivy.getSettings().doValidate());
         ResolveReport report = ivy.resolve(md, resolveOption);
@@ -249,11 +220,15 @@ public class IvyResolveJobThread extends
         confs = report.getConfigurations();
         artifactsByDependency.putAll(getArtifactsByDependency(report));
         if (monitor.isCanceled()) {
-            status = Status.CANCEL_STATUS;
-            return false;
+            return Status.CANCEL_STATUS;
         }
-        maybeRetrieve(report);
-        return true;
+
+        postDoResolve(report);
+        return Status.OK_STATUS;
+    }
+
+    protected void postDoResolve(ResolveReport report) throws IOException {
+        // nothing to do by default
     }
 
     /**
@@ -281,55 +256,6 @@ public class IvyResolveJobThread extends
         }
     }
 
-    /**
-     * 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()]);
-
-        Set duplicates = new HashSet();
-
-        for (int i = 0; i < reports.length - 1; i++) {
-            if (!mapper.accept(reports[i].getArtifact())) {
-                continue;
-            }
-
-            ModuleRevisionId mrid1 = reports[i].getArtifact().getModuleRevisionId();
-
-            for (int j = i + 1; j < reports.length; j++) {
-                if (!mapper.accept(reports[j].getArtifact())) {
-                    continue;
-                }
-                ModuleRevisionId mrid2 = reports[j].getArtifact().getModuleRevisionId();
-                if (mrid1.getModuleId().equals(mrid2.getModuleId())
-                        && !mrid1.getRevision().equals(mrid2.getRevision())) {
-                    duplicates.add(mrid1.getModuleId());
-                    break;
-                }
-            }
-        }
-
-        if (duplicates.isEmpty()) {
-            return;
-        }
-
-        StringBuffer buffer = new StringBuffer("There are some duplicates entries due to
conflicts"
-                + " between the resolved configurations " + conf.getConfs());
-        buffer.append(":\n  - ");
-        Iterator it = duplicates.iterator();
-        while (it.hasNext()) {
-            buffer.append(it.next());
-            if (it.hasNext()) {
-                buffer.append("\n  - ");
-            }
-        }
-        ivy.getLoggerEngine().log(buffer.toString(), Message.MSG_WARN);
-    }
-
     private Map/* <ModuleRevisionId, Artifact[]> */getArtifactsByDependency(ResolveReport
r) {
         Map result = new HashMap();
         for (Iterator it = r.getDependencies().iterator(); it.hasNext();) {
@@ -341,54 +267,7 @@ public class IvyResolveJobThread extends
         return result;
     }
 
-    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());
+    public String toString() {
+        return ivyXmlPath + confs + " in " + project.getName();
     }
-
 }

Propchange: ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/IvyResolver.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/IvyResolver.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Propchange: ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/IvyResolver.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Copied: ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathResolver.java
(from r988101, ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyResolveJobThread.java)
URL: http://svn.apache.org/viewvc/ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathResolver.java?p2=ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathResolver.java&p1=ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyResolveJobThread.java&r1=988101&r2=988166&rev=988166&view=diff
==============================================================================
--- ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyResolveJobThread.java
(original)
+++ ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathResolver.java
Mon Aug 23 16:02:50 2010
@@ -17,74 +17,45 @@
  */
 package org.apache.ivyde.eclipse.cpcontainer;
 
-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.IvyResolver;
 import org.apache.ivyde.eclipse.retrieve.RetrieveSetup;
 import org.eclipse.core.resources.IFolder;
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.MultiStatus;
-import org.eclipse.core.runtime.Status;
 import org.eclipse.jdt.core.IClasspathEntry;
 
 /**
  * Eclipse classpath container that will contain the ivy resolved entries.
  */
-public class IvyResolveJobThread extends Thread {
-
-    private static final int MONITOR_LENGTH = 1000;
-
-    private final Ivy ivy;
-
-    private final IProgressMonitor monitor;
+public class IvyClasspathResolver extends IvyResolver {
 
     private final IvyClasspathContainerConfiguration conf;
 
-    private final ModuleDescriptor md;
-
-    private final boolean usePreviousResolveIfExist;
-
-    private IStatus status = null;
-
     private IClasspathEntry[] classpathEntries = null;
 
     private LinkedHashSet/* <ArtifactDownloadReport> */all;
 
-    private List problemMessages;
-
-    private String[] confs;
-
     private Map artifactsByDependency = new HashMap();
 
     /**
@@ -96,189 +67,28 @@ public class IvyResolveJobThread extends
      */
     private Map/* <ArtifactDownloadReport, Set<String>> */retrievedArtifacts
= null;
 
-    public IvyResolveJobThread(IvyClasspathContainerConfiguration conf, Ivy ivy,
+    public IvyClasspathResolver(IvyClasspathContainerConfiguration conf, Ivy ivy,
             ModuleDescriptor md, boolean usePreviousResolveIfExist, IProgressMonitor monitor)
{
-        this.ivy = ivy;
-        this.md = md;
-        this.usePreviousResolveIfExist = usePreviousResolveIfExist;
-        this.monitor = monitor;
+        super(conf.getIvyXmlPath(), ivy, md, usePreviousResolveIfExist, monitor, conf.getConfs(),
+                conf.getJavaProject().getProject());
         this.conf = conf;
     }
 
-    public IStatus getStatus() {
-        return status;
-    }
-
     public IClasspathEntry[] getClasspathEntries() {
         return classpathEntries;
     }
 
-    public void run() {
-        try {
-            ivy.pushContext();
-            IvyResolveJobListener ivyResolveJobListener = new IvyResolveJobListener(monitor);
-            ivy.getEventManager().addIvyListener(ivyResolveJobListener);
-
-            monitor.beginTask("Resolve of " + conf.toString(), MONITOR_LENGTH);
-            monitor.setTaskName("Resolve of " + conf.toString());
-
-            // 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(IvyResolveJobThread.class.getClassLoader());
-            try {
-                computeConfs();
-
-                if (usePreviousResolveIfExist) {
-                    if (!resolveWithPrevious()) {
-                        // resolve canceled
-                        return;
-                    }
-                } else {
-                    Message.info("\n\nIVYDE: calling resolve on " + conf.getIvyXmlPath()
+ "\n");
-                    if (!resolve()) {
-                        // resolve canceled
-                        return;
-                    }
-                }
-
-                IvyClasspathContainerMapper mapper = new IvyClasspathContainerMapper(monitor,
ivy,
-                        conf, all, artifactsByDependency, retrievedArtifacts);
-
-                warnIfDuplicates(mapper);
+    protected void postResolveOrRefresh() {
+        IvyClasspathContainerMapper mapper = new IvyClasspathContainerMapper(monitor, ivy,
conf,
+                all, artifactsByDependency, retrievedArtifacts);
 
-                classpathEntries = mapper.map();
-            } catch (ParseException e) {
-                String errorMsg = "Error while parsing the ivy file " + conf.getIvyXmlPath()
+ "\n"
-                        + e.getMessage();
-                Message.error(errorMsg);
-                status = new Status(IStatus.ERROR, IvyPlugin.ID, IStatus.ERROR, errorMsg,
e);
-                return;
-            } catch (Exception e) {
-                String errorMsg = "Error while resolving dependencies for " + conf.getIvyXmlPath()
-                        + "\n" + e.getMessage();
-                Message.error(errorMsg);
-                status = new Status(IStatus.ERROR, IvyPlugin.ID, IStatus.ERROR, errorMsg,
e);
-                return;
-            } finally {
-                Thread.currentThread().setContextClassLoader(old);
-                monitor.done();
-                ivy.getEventManager().removeIvyListener(ivyResolveJobListener);
-            }
+        warnIfDuplicates(mapper);
 
-            if (!problemMessages.isEmpty()) {
-                MultiStatus multiStatus = new MultiStatus(IvyPlugin.ID, IStatus.ERROR,
-                        "Impossible to resolve dependencies of " + md.getModuleRevisionId(),
null);
-                for (Iterator iter = problemMessages.iterator(); iter.hasNext();) {
-                    multiStatus.add(new Status(IStatus.ERROR, IvyPlugin.ID, IStatus.ERROR,
-                            (String) iter.next(), null));
-                }
-                status = multiStatus;
-                return;
-            }
-
-            status = Status.OK_STATUS;
-        } catch (Throwable e) {
-            status = new Status(IStatus.ERROR, IvyPlugin.ID, IStatus.ERROR, "The resolve
job of "
-                    + conf + " has unexpectedly stopped", e);
-        }
-    }
-
-    private void computeConfs() {
-        Set configurations = new HashSet();
-        configurations.addAll(conf.getConfs());
-
-        if (configurations.contains("*")) {
-            confs = md.getConfigurationsNames();
-        } else {
-            confs = (String[]) configurations.toArray(new String[configurations.size()]);
-        }
+        classpathEntries = mapper.map();
     }
 
-    private boolean resolveWithPrevious() throws ParseException, IOException {
-        all = new LinkedHashSet();
-        problemMessages = new ArrayList();
-        // we check if all required configurations have been
-        // resolved
-        boolean parsingOk = true;
-        for (int i = 0; i < confs.length && parsingOk; 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);
-                } 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
-                }
-            }
-        }
-        if (!parsingOk) {
-            // no resolve previously done for at least one conf... we do it now
-            return resolve();
-        }
-        return true;
-    }
-
-    private boolean resolve() throws ParseException, IOException {
-        ResolveOptions resolveOption = new ResolveOptions().setConfs(confs);
-        resolveOption.setValidate(ivy.getSettings().doValidate());
-        ResolveReport report = ivy.resolve(md, resolveOption);
-        problemMessages = report.getAllProblemMessages();
-
-        all = new LinkedHashSet();
-        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));
-            }
-        }
-
-        confs = report.getConfigurations();
-        artifactsByDependency.putAll(getArtifactsByDependency(report));
-        if (monitor.isCanceled()) {
-            status = Status.CANCEL_STATUS;
-            return false;
-        }
+    protected void postDoResolve(ResolveReport report) throws IOException {
         maybeRetrieve(report);
-        return true;
-    }
-
-    /**
-     * Populate the map of artifact. The map should be populated by metadata in cache as
this is
-     * called in the refresh process.
-     * 
-     * @param parser
-     * @throws ParseException
-     */
-    private void findAllArtifactOnRefresh(XmlReportParser parser) throws ParseException {
-        ModuleRevisionId[] dependencyMrdis = parser.getDependencyRevisionIds();
-        for (int iDep = 0; iDep < dependencyMrdis.length; iDep++) {
-            DependencyResolver depResolver = ivy.getSettings().getResolver(dependencyMrdis[iDep]);
-            DefaultDependencyDescriptor depDescriptor = new DefaultDependencyDescriptor(
-                    dependencyMrdis[iDep], false);
-            ResolveOptions options = new ResolveOptions();
-            options.setRefresh(true);
-            options.setUseCacheOnly(true);
-            ResolvedModuleRevision dependency = depResolver.getDependency(depDescriptor,
-                new ResolveData(ivy.getResolveEngine(), options));
-            if (dependency != null) {
-                artifactsByDependency.put(dependencyMrdis[iDep], dependency.getDescriptor()
-                        .getAllArtifacts());
-            }
-        }
     }
 
     /**
@@ -330,17 +140,6 @@ public class IvyResolveJobThread extends
         ivy.getLoggerEngine().log(buffer.toString(), Message.MSG_WARN);
     }
 
-    private Map/* <ModuleRevisionId, Artifact[]> */getArtifactsByDependency(ResolveReport
r) {
-        Map result = new HashMap();
-        for (Iterator it = r.getDependencies().iterator(); it.hasNext();) {
-            IvyNode node = (IvyNode) it.next();
-            if (node.getDescriptor() != null) {
-                result.put(node.getResolvedId(), node.getDescriptor().getAllArtifacts());
-            }
-        }
-        return result;
-    }
-
     private void maybeRetrieve(ResolveReport report) throws IOException {
         if (!conf.isInheritedRetrievedClasspath()) {
             return;

Propchange: ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathResolver.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathResolver.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Propchange: ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathResolver.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

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=988166&r1=988165&r2=988166&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
Mon Aug 23 16:02:50 2010
@@ -196,31 +196,37 @@ public class IvyResolveJob extends Job {
             return new Status(IStatus.ERROR, IvyPlugin.ID, "Unexpected error");
         }
         boolean usePreviousResolveIfExist = request.isUsePreviousResolveIfExist();
-        IvyResolveJobThread resolver = new IvyResolveJobThread(conf, ivy, md,
+        final IvyClasspathResolver resolver = new IvyClasspathResolver(conf, ivy, md,
                 usePreviousResolveIfExist, monitor);
-        resolver.setName("IvyDE resolver thread");
+        final IStatus[] status = new IStatus[1];
+        Thread resolverThread = new Thread(new Runnable() {
+            public void run() {
+                status[0] = resolver.resolve();
+            }
+        });
+        resolverThread.setName("IvyDE resolver thread");
 
-        resolver.start();
+        resolverThread.start();
         while (true) {
             try {
-                resolver.join(WAIT_FOR_JOIN);
+                resolverThread.join(WAIT_FOR_JOIN);
             } catch (InterruptedException e) {
-                ivy.interrupt(resolver);
+                ivy.interrupt(resolverThread);
                 return Status.CANCEL_STATUS;
             }
-            if (resolver.getStatus() != null || !resolver.isAlive()) {
+            if (status[0] != null || !resolverThread.isAlive()) {
                 break;
             }
             if (monitor.isCanceled()) {
-                ivy.interrupt(resolver);
+                ivy.interrupt(resolverThread);
                 return Status.CANCEL_STATUS;
             }
         }
-        if (resolver.getStatus() == Status.OK_STATUS) {
+        if (status[0] == Status.OK_STATUS) {
             request.getContainer().updateClasspathEntries(resolver.getClasspathEntries());
         }
-        setResolveStatus(conf, resolver.getStatus());
-        return resolver.getStatus();
+        setResolveStatus(conf, status[0]);
+        return status[0];
 
     }
 
@@ -250,8 +256,8 @@ public class IvyResolveJob extends Job {
                     marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_INFO);
                     break;
                 default:
-                    IvyPlugin.log(IStatus.WARNING, "Unsupported resolve status: "
-                            + status.getSeverity(), null);
+                    IvyPlugin.log(IStatus.WARNING,
+                        "Unsupported resolve status: " + status.getSeverity(), null);
             }
         } catch (CoreException e) {
             IvyPlugin.log(e);

Added: ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/retrieve/IvyRetriever.java
URL: http://svn.apache.org/viewvc/ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/retrieve/IvyRetriever.java?rev=988166&view=auto
==============================================================================
--- ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/retrieve/IvyRetriever.java
(added)
+++ ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/retrieve/IvyRetriever.java
Mon Aug 23 16:02:50 2010
@@ -0,0 +1,66 @@
+/*
+ *  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.retrieve;
+
+import java.io.IOException;
+
+import org.apache.ivy.Ivy;
+import org.apache.ivy.core.IvyPatternHelper;
+import org.apache.ivy.core.module.descriptor.ModuleDescriptor;
+import org.apache.ivy.core.retrieve.RetrieveOptions;
+import org.apache.ivy.util.filter.ArtifactTypeFilter;
+import org.apache.ivyde.eclipse.IvyResolver;
+import org.apache.ivyde.eclipse.cpcontainer.IvyClasspathUtil;
+import org.apache.ivyde.eclipse.cpcontainer.RefreshFolderJob;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.runtime.IProgressMonitor;
+
+public class IvyRetriever extends IvyResolver {
+
+    private final StandaloneRetrieveSetup setup;
+
+    public IvyRetriever(Ivy ivy, ModuleDescriptor md, boolean usePreviousResolveIfExist,
+            IProgressMonitor monitor, StandaloneRetrieveSetup setup) {
+        super(setup.getIvyXmlPath(), ivy, md, usePreviousResolveIfExist, monitor, IvyClasspathUtil
+                .split(setup.getRetrieveSetup().getRetrieveConfs()), setup.getProject());
+        this.setup = setup;
+    }
+
+    protected void postResolveOrRefresh() throws IOException {
+        String pattern = project.getLocation().toPortableString() + "/"
+                + setup.getRetrieveSetup().getRetrievePattern();
+        RetrieveOptions c = new RetrieveOptions();
+        c.setSync(setup.getRetrieveSetup().isRetrieveSync());
+        c.setConfs(confs);
+        String inheritedRetrieveTypes = setup.getRetrieveSetup().getRetrieveTypes();
+        if (inheritedRetrieveTypes != null && !inheritedRetrieveTypes.equals("*"))
{
+            c.setArtifactFilter(new ArtifactTypeFilter(IvyClasspathUtil
+                    .split(inheritedRetrieveTypes)));
+        }
+
+        int numberOfItemsRetrieved = ivy.retrieve(md.getModuleRevisionId(), pattern, c);
+        if (numberOfItemsRetrieved > 0) {
+            // Only refresh if we actually retrieved a file.
+            String refreshPath = IvyPatternHelper.getTokenRoot(setup.getRetrieveSetup()
+                    .getRetrievePattern());
+            IFolder folder = project.getFolder(refreshPath);
+            RefreshFolderJob refreshFolderJob = new RefreshFolderJob(folder);
+            refreshFolderJob.schedule();
+        }
+    }
+}

Propchange: ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/retrieve/IvyRetriever.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/retrieve/IvyRetriever.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Propchange: ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/retrieve/IvyRetriever.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/menu/IvyMenuContributionItem.java
URL: http://svn.apache.org/viewvc/ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/menu/IvyMenuContributionItem.java?rev=988166&r1=988165&r2=988166&view=diff
==============================================================================
--- ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/menu/IvyMenuContributionItem.java
(original)
+++ ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/menu/IvyMenuContributionItem.java
Mon Aug 23 16:02:50 2010
@@ -147,7 +147,7 @@ public class IvyMenuContributionItem ext
                 while (itSetup.hasNext()) {
                     StandaloneRetrieveSetup retrieveSetup = (StandaloneRetrieveSetup) itSetup
                             .next();
-                    RetrieveAction action = new RetrieveAction(project, retrieveSetup);
+                    RetrieveAction action = new RetrieveAction(retrieveSetup);
                     action.setText("Retrieve '" + retrieveSetup.getName()
                             + (oneProject ? "'" : "' of " + project.getName()));
                     fillMenu(menuManager, items, new ActionContributionItem(action));

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=988166&r1=988165&r2=988166&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
Mon Aug 23 16:02:50 2010
@@ -17,45 +17,25 @@
  */
 package org.apache.ivyde.eclipse.ui.menu;
 
-import java.io.IOException;
-
 import org.apache.ivy.Ivy;
-import org.apache.ivy.core.IvyPatternHelper;
 import org.apache.ivy.core.module.descriptor.ModuleDescriptor;
-import org.apache.ivy.core.retrieve.RetrieveOptions;
-import org.apache.ivy.util.filter.ArtifactTypeFilter;
 import org.apache.ivyde.eclipse.IvyDEException;
 import org.apache.ivyde.eclipse.IvyPlugin;
-import org.apache.ivyde.eclipse.cpcontainer.IvyClasspathUtil;
-import org.apache.ivyde.eclipse.cpcontainer.RefreshFolderJob;
+import org.apache.ivyde.eclipse.retrieve.IvyRetriever;
 import org.apache.ivyde.eclipse.retrieve.StandaloneRetrieveSetup;
-import org.eclipse.core.resources.IFolder;
-import org.eclipse.core.resources.IProject;
 import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
 import org.eclipse.jface.action.Action;
 
 public class RetrieveAction extends Action {
 
     private final StandaloneRetrieveSetup retrieveSetup;
 
-    private final IProject project;
-
-    public RetrieveAction(IProject project, StandaloneRetrieveSetup retrieveSetup) {
-        this.project = project;
+    public RetrieveAction(StandaloneRetrieveSetup retrieveSetup) {
         this.retrieveSetup = retrieveSetup;
     }
 
     public void run() {
-        String pattern = project.getLocation().toPortableString() + "/"
-                + retrieveSetup.getRetrieveSetup().getRetrievePattern();
-        RetrieveOptions c = new RetrieveOptions();
-        c.setSync(retrieveSetup.getRetrieveSetup().isRetrieveSync());
-        c.setConfs(retrieveSetup.getRetrieveSetup().getRetrieveConfs().split(","));
-        String inheritedRetrieveTypes = retrieveSetup.getRetrieveSetup().getRetrieveTypes();
-        if (inheritedRetrieveTypes != null && !inheritedRetrieveTypes.equals("*"))
{
-            c.setArtifactFilter(new ArtifactTypeFilter(IvyClasspathUtil
-                    .split(inheritedRetrieveTypes)));
-        }
         Ivy ivy;
         ModuleDescriptor md;
         try {
@@ -65,21 +45,14 @@ public class RetrieveAction extends Acti
             e.log(IStatus.ERROR, null);
             return;
         }
-        try {
-            int numberOfItemsRetrieved = ivy.retrieve(md.getModuleRevisionId(), pattern,
c);
-            if (numberOfItemsRetrieved > 0) {
-                // Only refresh if we actually retrieved a file.
-                String refreshPath = IvyPatternHelper.getTokenRoot(retrieveSetup.getRetrieveSetup()
-                        .getRetrievePattern());
-                IFolder folder = project.getFolder(refreshPath);
-                RefreshFolderJob refreshFolderJob = new RefreshFolderJob(folder);
-                refreshFolderJob.schedule();
-            }
-        } catch (IOException e) {
-            IvyPlugin.log(IStatus.ERROR, "Error while retrieving '" + retrieveSetup.getName()
-                    + "' in " + retrieveSetup.getProject().getName(), e);
+        IvyRetriever retriever = new IvyRetriever(ivy, md, false, new NullProgressMonitor(),
+                retrieveSetup);
+        IStatus status = retriever.resolve();
+        if (status.isOK() || status.getCode() == IStatus.CANCEL) {
+            IvyPlugin.log(IStatus.INFO, "Successful retrieve of '" + retrieveSetup.getName()
+                    + "' in " + retrieveSetup.getProject().getName(), null);
+            return;
         }
-        IvyPlugin.log(IStatus.INFO, "Sucessfull retrieve of '" + retrieveSetup.getName()
+ "' in "
-                + retrieveSetup.getProject().getName(), null);
+        IvyPlugin.log(status);
     }
 }



Mime
View raw message