ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hi...@apache.org
Subject svn commit: r991885 - in /ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer: IvyResolveJob.java IvyRunner.java
Date Thu, 02 Sep 2010 10:36:55 GMT
Author: hibou
Date: Thu Sep  2 10:36:54 2010
New Revision: 991885

URL: http://svn.apache.org/viewvc?rev=991885&view=rev
Log:
Extract more common ivy-running pattern

Added:
    ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyRunner.java
      - copied, changed from r991872, ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyProgressMonitor.java
Modified:
    ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyResolveJob.java

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=991885&r1=991884&r2=991885&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 10:36:54 2010
@@ -180,55 +180,46 @@ public class IvyResolveJob extends Job {
 
     private boolean launchResolveThread(ResolveRequest request, IProgressMonitor monitor,
             MultiStatus errorsStatus, Ivy ivy, ModuleDescriptor md) {
-        IStatus jobStatus = launchResolveThread(request, monitor, ivy, md);
-        switch (jobStatus.getCode()) {
-            case IStatus.CANCEL:
-                return true;
-            case IStatus.OK:
-            case IStatus.INFO:
-                break;
-            case IStatus.ERROR:
-                errorsStatus.add(jobStatus);
-                break;
-            default:
-                IvyPlugin.log(IStatus.WARNING, "Unknown IStatus: " + jobStatus.getCode(),
null);
-        }
-        return false;
-    }
 
-    private IStatus launchResolveThread(ResolveRequest request, IProgressMonitor monitor,
Ivy ivy,
-            ModuleDescriptor md) {
-        if (monitor.isCanceled()) {
-            return Status.CANCEL_STATUS;
-        }
-
-        boolean usePreviousResolveIfExist = request.isUsePreviousResolveIfExist();
         IvyClasspathContainerConfiguration conf = request.getContainer().getConf();
         final IvyClasspathResolver resolver = new IvyClasspathResolver(conf, ivy, md,
-                usePreviousResolveIfExist, monitor);
+                request.isUsePreviousResolveIfExist(), monitor);
+
         final IStatus[] status = new IStatus[1];
-        Thread resolverThread = new Thread(new Runnable() {
+
+        Runnable resolveRunner = new Runnable() {
             public void run() {
                 status[0] = resolver.resolve();
             }
-        });
-        resolverThread.setName("IvyDE resolver thread");
-
-        resolverThread.start();
+        };
 
-        IvyProgressMonitor ivyProgressMonitor = new IvyProgressMonitor();
-        if (ivyProgressMonitor.wait(ivy, monitor, resolverThread)) {
-            return Status.CANCEL_STATUS;
+        IvyRunner ivyRunner = new IvyRunner();
+        if (ivyRunner.launchIvyThread(resolveRunner, ivy, monitor)) {
+            return true;
         }
 
         if (status[0] == Status.OK_STATUS) {
             request.getContainer().updateClasspathEntries(resolver.getClasspathEntries());
         }
+
         IvyMarkerManager ivyMarkerManager = IvyPlugin.getDefault().getIvyMarkerManager();
         ivyMarkerManager.setResolveStatus(status[0], conf.getJavaProject().getProject(),
             conf.getIvyXmlPath());
-        return status[0];
 
+        switch (status[0].getCode()) {
+            case IStatus.CANCEL:
+                return true;
+            case IStatus.OK:
+            case IStatus.INFO:
+                break;
+            case IStatus.ERROR:
+                errorsStatus.add(status[0]);
+                break;
+            default:
+                IvyPlugin.log(IStatus.WARNING, "Unknown IStatus: " + status[0].getCode(),
null);
+        }
+
+        return false;
     }
 
 }

Copied: ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyRunner.java
(from r991872, ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyProgressMonitor.java)
URL: http://svn.apache.org/viewvc/ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyRunner.java?p2=ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyRunner.java&p1=ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyProgressMonitor.java&r1=991872&r2=991885&rev=991885&view=diff
==============================================================================
--- ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyProgressMonitor.java
(original)
+++ ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyRunner.java
Thu Sep  2 10:36:54 2010
@@ -20,35 +20,42 @@ package org.apache.ivyde.eclipse.cpconta
 import org.apache.ivy.Ivy;
 import org.eclipse.core.runtime.IProgressMonitor;
 
-public class IvyProgressMonitor {
+public class IvyRunner {
 
     private static final int WAIT_FOR_JOIN = 100;
 
     /**
-     * Wait for the Ivy work to finish, or try to interrupt it if requested by the end user
via the
-     * progress monitor
+     * Launch some ivy related work and cancel it if the end user has requested it
      * 
+     * @param runnable
+     *            the ivy work to do
      * @param ivy
-     *            the ivy to monitor
+     *            the ivy instance which handle the work, used to cancel the work if requested
      * @param monitor
-     *            the monitor coming from the end user
-     * @param resolverThread
-     *            the thread doing the Ivy work
-     * @return <code>true</code> if the work has been interrupted
+     *            the monitor from the end user
+     * @return <code>true</code> if the work has been canceled
      */
-    public boolean wait(Ivy ivy, IProgressMonitor monitor, Thread resolverThread) {
+    public boolean launchIvyThread(Runnable runnable, Ivy ivy, IProgressMonitor monitor)
{
+        if (monitor != null && monitor.isCanceled()) {
+            return true;
+        }
+
+        Thread runnerThread = new Thread(runnable);
+        runnerThread.setName("IvyDE resolver thread");
+        runnerThread.start();
+
         while (true) {
             try {
-                resolverThread.join(WAIT_FOR_JOIN);
+                runnerThread.join(WAIT_FOR_JOIN);
             } catch (InterruptedException e) {
-                ivy.interrupt(resolverThread);
+                ivy.interrupt(runnerThread);
                 return true;
             }
-            if (!resolverThread.isAlive()) {
+            if (!runnerThread.isAlive()) {
                 return false;
             }
             if (monitor != null && monitor.isCanceled()) {
-                ivy.interrupt(resolverThread);
+                ivy.interrupt(runnerThread);
                 return true;
             }
         }



Mime
View raw message