ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hi...@apache.org
Subject svn commit: r835606 - in /ant/ivy/ivyde/trunk: ./ org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/ org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/actions/...
Date Thu, 12 Nov 2009 22:25:46 GMT
Author: hibou
Date: Thu Nov 12 22:25:46 2009
New Revision: 835606

URL: http://svn.apache.org/viewvc?rev=835606&view=rev
Log:
IVYDE-219: add a multi resolve job and make it return the errors found if any

Added:
    ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyMultiResolveJob.java
  (with props)
Modified:
    ant/ivy/ivyde/trunk/CHANGES.txt
    ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/IvyDERuntimeClasspathEntryResolver.java
    ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathContainer.java
    ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathUtil.java
    ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/actions/ProjectResolveAction.java
    ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/actions/ResolveAllAction.java
    ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/workspaceresolver/WorkspaceResourceChangeListener.java

Modified: ant/ivy/ivyde/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/ant/ivy/ivyde/trunk/CHANGES.txt?rev=835606&r1=835605&r2=835606&view=diff
==============================================================================
--- ant/ivy/ivyde/trunk/CHANGES.txt (original)
+++ ant/ivy/ivyde/trunk/CHANGES.txt Thu Nov 12 22:25:46 2009
@@ -23,6 +23,7 @@
 - FIX: Ivy Classpath Contributed to Dependent Projects When not Exported (IVYDE-193)
 - FIX: Incorrect project:// path in the ivysettings configuration make the UI crash (IVYDE-203)
 - FIX: conf attributes must not be null (IVYDE-209) (thanks to Ivica Loncar)
+- FIX: Errors are not reported when multiple resolve are launched (IVYDE-219)
 
   version 2.0.0 final
 ==========================

Modified: ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/IvyDERuntimeClasspathEntryResolver.java
URL: http://svn.apache.org/viewvc/ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/IvyDERuntimeClasspathEntryResolver.java?rev=835606&r1=835605&r2=835606&view=diff
==============================================================================
--- ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/IvyDERuntimeClasspathEntryResolver.java
(original)
+++ ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/IvyDERuntimeClasspathEntryResolver.java
Thu Nov 12 22:25:46 2009
@@ -71,7 +71,10 @@
         }
         IvyClasspathContainer ivycp = (IvyClasspathContainer) container;
         if (ivycp.getConf().isInheritedResolveBeforeLaunch()) {
-            ivycp.launchResolve(false, false, new NullProgressMonitor());
+            IStatus status = ivycp.launchResolve(false, false, new NullProgressMonitor());
+            if (status.getCode() != IStatus.OK) {
+                throw new CoreException(status);
+            }
         }
         IClasspathEntry[] cpes = container.getClasspathEntries();
         int property = -1;

Modified: ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathContainer.java
URL: http://svn.apache.org/viewvc/ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathContainer.java?rev=835606&r1=835605&r2=835606&view=diff
==============================================================================
--- ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathContainer.java
(original)
+++ ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathContainer.java
Thu Nov 12 22:25:46 2009
@@ -25,12 +25,12 @@
 import org.apache.ivy.Ivy;
 import org.apache.ivy.core.module.descriptor.ModuleDescriptor;
 import org.apache.ivy.core.resolve.ResolveOptions;
-import org.apache.ivy.util.Message;
 import org.apache.ivyde.eclipse.IvyDEException;
 import org.apache.ivyde.eclipse.IvyPlugin;
 import org.eclipse.core.runtime.IPath;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
 import org.eclipse.core.runtime.jobs.ISchedulingRule;
 import org.eclipse.jdt.core.ElementChangedEvent;
 import org.eclipse.jdt.core.IClasspathAttribute;
@@ -45,7 +45,6 @@
 import org.eclipse.jdt.internal.core.JavaElementDelta;
 import org.eclipse.jdt.internal.core.JavaModelManager;
 import org.eclipse.jdt.internal.ui.packageview.PackageExplorerContentProvider;
-import org.eclipse.jface.dialogs.MessageDialog;
 import org.eclipse.swt.widgets.Display;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.Constants;
@@ -55,8 +54,7 @@
  */
 public class IvyClasspathContainer implements IClasspathContainer {
 
-    public static final String CONTAINER_ID =
-        "org.apache.ivyde.eclipse.cpcontainer.IVYDE_CONTAINER";
+    public static final String CONTAINER_ID = "org.apache.ivyde.eclipse.cpcontainer.IVYDE_CONTAINER";
 
     private IClasspathEntry[] classpathEntries;
 
@@ -141,39 +139,27 @@
         }
     };
 
-    private IvyResolveJob computeClasspathEntries(final boolean usePreviousResolveIfExist,
-            boolean isUser) {
-        try {
-            synchronized (this) {
-                if (job != null) {
-                    // resolve job already running
-                    return job;
-                }
-                job = new IvyResolveJob(this, usePreviousResolveIfExist);
-                job.setUser(isUser);
-                job.setRule(RESOLVE_EVENT_RULE);
+    private IvyResolveJob createResolveJob(final boolean usePreviousResolveIfExist, boolean
isUser) {
+        synchronized (this) {
+            if (job != null) {
+                // resolve job already running
                 return job;
             }
-        } catch (Throwable e) {
-            // IVYDE-79 : catch Throwable in order to catch java.lang.NoClassDefFoundError
too
-            Message.error(e.getMessage());
-            IvyPlugin.log(IStatus.ERROR, "The creation of the job failed", e);
-            MessageDialog.openError(IvyPlugin.getActiveWorkbenchShell(), "Resolve failed",
e
-                    .getMessage());
-            return null;
+            job = new IvyResolveJob(this, usePreviousResolveIfExist);
+            job.setUser(isUser);
+            job.setRule(RESOLVE_EVENT_RULE);
+            return job;
         }
     }
 
-    public void launchResolve(boolean usePreviousResolveIfExist, boolean isUser,
+    public IStatus launchResolve(boolean usePreviousResolveIfExist, boolean isUser,
             IProgressMonitor monitor) {
-        IvyResolveJob j = computeClasspathEntries(usePreviousResolveIfExist, isUser);
-        if (j != null) {
-            if (monitor != null) {
-                j.run(monitor);
-            } else {
-                j.schedule();
-            }
+        IvyResolveJob j = createResolveJob(usePreviousResolveIfExist, isUser);
+        if (monitor != null) {
+            return j.run(monitor);
         }
+        j.schedule();
+        return Status.OK_STATUS;
     }
 
     void updateClasspathEntries(final IClasspathEntry[] newEntries) {
@@ -210,7 +196,7 @@
                 null);
 
             // the following code was imported from:
-          // http://svn.codehaus.org/m2eclipse/trunk/org.maven.ide.eclipse/src/org/maven/ide/eclipse
+            // http://svn.codehaus.org/m2eclipse/trunk/org.maven.ide.eclipse/src/org/maven/ide/eclipse
             // /embedder/BuildPathManager.java
             // revision: 370; function setClasspathContainer; line 215
 

Modified: ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathUtil.java
URL: http://svn.apache.org/viewvc/ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathUtil.java?rev=835606&r1=835605&r2=835606&view=diff
==============================================================================
--- ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathUtil.java
(original)
+++ ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathUtil.java
Thu Nov 12 22:25:46 2009
@@ -22,8 +22,8 @@
 import java.net.URL;
 import java.text.ParseException;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
 
@@ -295,10 +295,10 @@
 
     public static List/* <IvyClasspathContainer> */getIvyClasspathContainers(IProject
project) {
         IJavaProject javaProject = JavaCore.create(project);
-        if (javaProject.exists()) {
+        if (javaProject != null && javaProject.exists()) {
             return getIvyClasspathContainers(javaProject);
         }
-        return Arrays.asList(new IvyClasspathContainer[] {});
+        return Collections.EMPTY_LIST;
     }
 
     /**

Added: ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyMultiResolveJob.java
URL: http://svn.apache.org/viewvc/ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyMultiResolveJob.java?rev=835606&view=auto
==============================================================================
--- ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyMultiResolveJob.java
(added)
+++ ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyMultiResolveJob.java
Thu Nov 12 22:25:46 2009
@@ -0,0 +1,78 @@
+/*
+ *  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.cpcontainer;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.ivyde.eclipse.IvyPlugin;
+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.core.runtime.SubProgressMonitor;
+import org.eclipse.core.runtime.jobs.Job;
+
+public class IvyMultiResolveJob extends Job {
+
+    private final List containers;
+
+    public IvyMultiResolveJob(List/* <IvyClasspathContainer> */containers) {
+        super("Multiple Ivy resolve");
+        this.containers = containers;
+    }
+
+    protected IStatus run(IProgressMonitor monitor) {
+        MultiStatus errorsStatus = new MultiStatus(IvyPlugin.ID, IStatus.ERROR,
+                "Some projects fail to be resolved", null);
+
+        monitor.beginTask("Resolving dependencies", containers.size());
+
+        Iterator containerIterator = containers.iterator();
+        while (containerIterator.hasNext()) {
+            if (monitor.isCanceled()) {
+                return Status.CANCEL_STATUS;
+            }
+            IvyClasspathContainer container = (IvyClasspathContainer) containerIterator.next();
+
+            SubProgressMonitor subMonitor = new SubProgressMonitor(monitor, 1);
+            String projectName = container.getConf().getJavaProject().getProject().getName();
+            subMonitor.beginTask("Resolving dependencies of " + projectName + " ("
+                    + container.getDescription() + ")", 1);
+
+            IStatus jobStatus = container.launchResolve(false, true, subMonitor);
+            switch (jobStatus.getCode()) {
+                case IStatus.CANCEL:
+                    return Status.CANCEL_STATUS;
+                case IStatus.OK:
+                case IStatus.INFO:
+                    break;
+                case IStatus.ERROR:
+                    errorsStatus.add(jobStatus);
+                    break;
+            }
+        }
+
+        if (errorsStatus.getChildren().length != 0) {
+            return errorsStatus;
+        }
+
+        return Status.OK_STATUS;
+    }
+
+}

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

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

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

Modified: ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/actions/ProjectResolveAction.java
URL: http://svn.apache.org/viewvc/ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/actions/ProjectResolveAction.java?rev=835606&r1=835605&r2=835606&view=diff
==============================================================================
--- ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/actions/ProjectResolveAction.java
(original)
+++ ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/actions/ProjectResolveAction.java
Thu Nov 12 22:25:46 2009
@@ -17,58 +17,31 @@
  */
 package org.apache.ivyde.eclipse.ui.actions;
 
-import java.util.Iterator;
+import java.util.ArrayList;
 import java.util.List;
 
-import org.apache.ivyde.eclipse.cpcontainer.IvyClasspathContainer;
 import org.apache.ivyde.eclipse.cpcontainer.IvyClasspathUtil;
+import org.apache.ivyde.eclipse.cpcontainer.IvyMultiResolveJob;
 import org.eclipse.core.resources.IProject;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.SubProgressMonitor;
 import org.eclipse.core.runtime.jobs.Job;
-import org.eclipse.jdt.core.IJavaProject;
-import org.eclipse.jdt.core.JavaCore;
 import org.eclipse.jface.action.Action;
 
 public class ProjectResolveAction extends Action {
-    IProject[] projects;
-    
+
+    private final IProject[] projects;
+
     public ProjectResolveAction(IProject[] projects) {
         this.projects = projects;
         this.setText("Resolve");
     }
-    
-    public void run() {
-        final IProject[] finalProjects = projects;
 
-        Job multipleResolveJob = new Job("Resolving dependencies") {
-            protected IStatus run(IProgressMonitor monitor) {
-                for (int i = 0; i < finalProjects.length; i++) {
-                    IJavaProject javaProject = JavaCore.create(finalProjects[i]);
-                    if (javaProject == null)
-                        continue;
-
-                    List/* <IvyClasspathContainer> */classpathContainers = IvyClasspathUtil
-                            .getIvyClasspathContainers(javaProject);
-
-                    Iterator containerIterator = classpathContainers.iterator();
-                    while (containerIterator.hasNext()) {
-                        if (monitor.isCanceled()) {
-                            return Status.CANCEL_STATUS;
-                        }
-                        SubProgressMonitor subMonitor = new SubProgressMonitor(monitor, 1);
-                        IvyClasspathContainer container = (IvyClasspathContainer) containerIterator
-                                .next();
-                        container.launchResolve(false, true, subMonitor);
-                    }
-                }
-                
-                return Status.OK_STATUS;
-            }
-        };
+    public void run() {
+        List allContainers = new ArrayList();
+        for (int i = 0; i < projects.length; i++) {
+            allContainers.addAll(IvyClasspathUtil.getIvyClasspathContainers(projects[i]));
+        }
 
+        Job multipleResolveJob = new IvyMultiResolveJob(allContainers);
         multipleResolveJob.setUser(true);
         multipleResolveJob.schedule();
     }

Modified: ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/actions/ResolveAllAction.java
URL: http://svn.apache.org/viewvc/ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/actions/ResolveAllAction.java?rev=835606&r1=835605&r2=835606&view=diff
==============================================================================
--- ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/actions/ResolveAllAction.java
(original)
+++ ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/actions/ResolveAllAction.java
Thu Nov 12 22:25:46 2009
@@ -18,17 +18,11 @@
 package org.apache.ivyde.eclipse.ui.actions;
 
 import java.util.ArrayList;
-import java.util.Iterator;
 import java.util.List;
 
-import org.apache.ivyde.eclipse.IvyPlugin;
-import org.apache.ivyde.eclipse.cpcontainer.IvyClasspathContainer;
 import org.apache.ivyde.eclipse.cpcontainer.IvyClasspathUtil;
+import org.apache.ivyde.eclipse.cpcontainer.IvyMultiResolveJob;
 import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.SubProgressMonitor;
 import org.eclipse.core.runtime.jobs.Job;
 import org.eclipse.jdt.core.IJavaModel;
 import org.eclipse.jdt.core.IJavaProject;
@@ -40,74 +34,36 @@
 import org.eclipse.ui.IWorkbenchWindowActionDelegate;
 
 public class ResolveAllAction implements IWorkbenchWindowActionDelegate {
-    /**
-     * The constructor.
-     */
-    public ResolveAllAction() {
-    }
 
-    /**
-     * The action has been activated. The argument of the method represents the 'real' action
-     * sitting in the workbench UI.
-     * 
-     * @see IWorkbenchWindowActionDelegate#run
-     */
     public void run(IAction action) {
-        Job resolveAllJob = new Job("Resolve all dependencies") {
-            protected IStatus run(IProgressMonitor monitor) {
-                IJavaModel model = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot());
-                IJavaProject[] projects;
-                try {
-                    projects = model.getJavaProjects();
-                } catch (JavaModelException e) {
-                    return new Status(IStatus.ERROR, IvyPlugin.ID, IStatus.ERROR,
-                            "Unable to get the list of available java projects", e);
-                }
-                List containers = new ArrayList();
-                for (int i = 0; i < projects.length; i++) {
-                    containers.addAll(IvyClasspathUtil.getIvyClasspathContainers(projects[i]));
-                }
-                monitor.beginTask("Resolve all dependencies", containers.size());
-                for (Iterator iter = containers.iterator(); iter.hasNext();) {
-                    if (monitor.isCanceled()) {
-                        return Status.CANCEL_STATUS;
-                    }
-                    SubProgressMonitor subMonitor = new SubProgressMonitor(monitor, 1);
-                    IvyClasspathContainer cp = (IvyClasspathContainer) iter.next();
-                    cp.launchResolve(false, true, subMonitor);
-                }
-
-                return Status.OK_STATUS;
-            }
-        };
+        IJavaModel model = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot());
+        IJavaProject[] projects;
+        try {
+            projects = model.getJavaProjects();
+        } catch (JavaModelException e) {
+            // TODO deal with it properly
+            return;
+        }
+
+        List allContainers = new ArrayList();
+        for (int i = 0; i < projects.length; i++) {
+            allContainers.addAll(IvyClasspathUtil.getIvyClasspathContainers(projects[i]));
+        }
 
+        Job resolveAllJob = new IvyMultiResolveJob(allContainers);
         resolveAllJob.setUser(true);
         resolveAllJob.schedule();
     }
 
-    /**
-     * Selection in the workbench has been changed. We can change the state of the 'real'
action
-     * here if we want, but this can only happen after the delegate has been created.
-     * 
-     * @see IWorkbenchWindowActionDelegate#selectionChanged
-     */
     public void selectionChanged(IAction action, ISelection selection) {
+        // nothing to do
     }
 
-    /**
-     * We can use this method to dispose of any system resources we previously allocated.
-     * 
-     * @see IWorkbenchWindowActionDelegate#dispose
-     */
     public void dispose() {
+        // nothing to do
     }
 
-    /**
-     * We will cache window object in order to be able to provide parent shell for the message
-     * dialog.
-     * 
-     * @see IWorkbenchWindowActionDelegate#init
-     */
     public void init(IWorkbenchWindow window) {
+        // nothing to do
     }
 }

Modified: ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/workspaceresolver/WorkspaceResourceChangeListener.java
URL: http://svn.apache.org/viewvc/ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/workspaceresolver/WorkspaceResourceChangeListener.java?rev=835606&r1=835605&r2=835606&view=diff
==============================================================================
--- ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/workspaceresolver/WorkspaceResourceChangeListener.java
(original)
+++ ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/workspaceresolver/WorkspaceResourceChangeListener.java
Thu Nov 12 22:25:46 2009
@@ -17,6 +17,7 @@
  */
 package org.apache.ivyde.eclipse.workspaceresolver;
 
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Iterator;
 import java.util.LinkedHashSet;
@@ -25,6 +26,7 @@
 import org.apache.ivyde.eclipse.IvyPlugin;
 import org.apache.ivyde.eclipse.cpcontainer.IvyClasspathContainer;
 import org.apache.ivyde.eclipse.cpcontainer.IvyClasspathUtil;
+import org.apache.ivyde.eclipse.cpcontainer.IvyMultiResolveJob;
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IFolder;
 import org.eclipse.core.resources.IProject;
@@ -35,14 +37,10 @@
 import org.eclipse.core.resources.IResourceRuleFactory;
 import org.eclipse.core.resources.IWorkspaceRoot;
 import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.resources.WorkspaceJob;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.OperationCanceledException;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.SubProgressMonitor;
 import org.eclipse.core.runtime.jobs.ISchedulingRule;
 import org.eclipse.jdt.core.IClasspathEntry;
 import org.eclipse.jdt.core.IJavaProject;
@@ -113,21 +111,10 @@
         // dependent projects after the close operation has finished.
         IResourceRuleFactory ruleFactory = ResourcesPlugin.getWorkspace().getRuleFactory();
         ISchedulingRule modifyRule = ruleFactory.modifyRule(javaProject.getCorrespondingResource());
-        class IvyClosedProjectJob extends WorkspaceJob {
-
-            public IvyClosedProjectJob() {
-                super("IvyClosedProjectJob");
-            }
-
-            public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException
{
-                resolveAffectedProjects(javaProject.getPath(), isUser(), monitor);
-                return Status.OK_STATUS;
-            }
-        }
-
-        IvyClosedProjectJob job = new IvyClosedProjectJob();
-        job.setRule(modifyRule);
-        job.schedule();
+        List affectedContainers = getAffectedContainers(javaProject.getPath());
+        IvyMultiResolveJob multiResolveJob = new IvyMultiResolveJob(affectedContainers);
+        multiResolveJob.setRule(modifyRule);
+        multiResolveJob.schedule();
 
     }
 
@@ -172,30 +159,27 @@
         IResourceRuleFactory ruleFactory = ResourcesPlugin.getWorkspace().getRuleFactory();
         ISchedulingRule modifyRule = ruleFactory.modifyRule(ResourcesPlugin.getWorkspace()
                 .getRoot());
-        class IvyOpenProjectJob extends WorkspaceJob {
-
-            public IvyOpenProjectJob() {
-                super("IvyOpenProjectJob");
-            }
-
-            public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException
{
-                resolveAllProjectsExcept(projects, isUser(), monitor);
-                return Status.OK_STATUS;
-            }
-        }
-
-        IvyOpenProjectJob job = new IvyOpenProjectJob();
-        job.setRule(modifyRule);
-        job.schedule();
+        List allContainers = getAllContainersExcludingProjects(projects);
+        IvyMultiResolveJob multiResolveJob = new IvyMultiResolveJob(allContainers);
+        multiResolveJob.setRule(modifyRule);
+        multiResolveJob.schedule();
     }
 
-    /*
-     * Only resolve those projects which include the specified project path as ivy dependency
+    /**
+     * Return the IvyDE container which include the specified project path as ivy dependency
      */
-    private void resolveAffectedProjects(IPath projectPath, boolean isUser, IProgressMonitor
monitor)
-            throws JavaModelException {
+    private List getAffectedContainers(IPath projectPath) {
+        List/* <IvyClasspathContainer> */allContainers = new ArrayList();
+
         IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
-        IJavaProject[] projects = JavaCore.create(root).getJavaProjects();
+        IJavaProject[] projects;
+        try {
+            projects = JavaCore.create(root).getJavaProjects();
+        } catch (JavaModelException e) {
+            // something bad happend in the JDT...
+            IvyPlugin.log(e);
+            return allContainers;
+        }
 
         for (int i = 0; i < projects.length; i++) {
             IJavaProject javaProject = projects[i];
@@ -212,44 +196,35 @@
                             || !containerEntry.getPath().equals(projectPath)) {
                         continue;
                     }
-
-                    SubProgressMonitor subMonitor = null;
-                    if (monitor != null) {
-                        if (monitor.isCanceled()) {
-                            return;
-                        }
-                        subMonitor = new SubProgressMonitor(monitor, 1);
-                    }
-                    ivycp.launchResolve(false, isUser, subMonitor);
+                    allContainers.add(ivycp);
                     break;
                 }
             }
         }
+
+        return allContainers;
     }
 
-    private void resolveAllProjectsExcept(Collection sourceProjects, boolean isUser,
-            IProgressMonitor monitor) throws JavaModelException {
-        IJavaProject[] projects = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot())
-                .getJavaProjects();
+    private List getAllContainersExcludingProjects(Collection sourceProjects) {
+        List/* <IvyClasspathContainer> */allContainers = new ArrayList();
+
+        IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
+        IJavaProject[] projects;
+        try {
+            projects = JavaCore.create(root).getJavaProjects();
+        } catch (JavaModelException e) {
+            // something bad happend in the JDT...
+            IvyPlugin.log(e);
+            return allContainers;
+        }
+
         for (int i = 0; i < projects.length; i++) {
-            if (sourceProjects.contains(projects[i])) {
-                continue;
-            }
-            SubProgressMonitor subMonitor = null;
-            if (monitor != null) {
-                if (monitor.isCanceled()) {
-                    return;
-                }
-                subMonitor = new SubProgressMonitor(monitor, 1);
-            }
-            List/* <IvyClasspathContainer> */containers = IvyClasspathUtil
-                    .getIvyClasspathContainers(projects[i]);
-            Iterator/* <IvyClasspathContainer> */itContainer = containers.iterator();
-            while (itContainer.hasNext()) {
-                IvyClasspathContainer ivycp = (IvyClasspathContainer) itContainer.next();
-                ivycp.launchResolve(false, isUser, subMonitor);
+            if (!sourceProjects.contains(projects[i])) {
+                allContainers.addAll(IvyClasspathUtil.getIvyClasspathContainers(projects[i]));
             }
         }
+
+        return allContainers;
     }
 
 }



Mime
View raw message