ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hi...@apache.org
Subject svn commit: r992783 - in /ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/resolve: IvyResolveJob.java IvyResolveJobListener.java IvyResolver.java
Date Sun, 05 Sep 2010 13:51:01 GMT
Author: hibou
Date: Sun Sep  5 13:51:00 2010
New Revision: 992783

URL: http://svn.apache.org/viewvc?rev=992783&view=rev
Log:
Improve the progess bar durong the resolve

Modified:
    ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/resolve/IvyResolveJob.java
    ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/resolve/IvyResolveJobListener.java
    ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/resolve/IvyResolver.java

Modified: ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/resolve/IvyResolveJob.java
URL: http://svn.apache.org/viewvc/ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/resolve/IvyResolveJob.java?rev=992783&r1=992782&r2=992783&view=diff
==============================================================================
--- ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/resolve/IvyResolveJob.java
(original)
+++ ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/resolve/IvyResolveJob.java
Sun Sep  5 13:51:00 2010
@@ -47,6 +47,12 @@ import org.eclipse.core.runtime.jobs.Job
  */
 public class IvyResolveJob extends Job {
 
+    private static final int MONITOR_LENGTH = 1000;
+
+    private static final int IVY_LOAD_LENGTH = 100;
+
+    private static final int POST_RESOLVE_LENGTH = 100;
+
     private static final int WAIT_BEFORE_LAUNCH = 1000;
 
     private final List resolveQueue = new ArrayList();
@@ -79,6 +85,8 @@ public class IvyResolveJob extends Job {
             resolveQueue.clear();
         }
 
+        monitor.beginTask("Loading ivy descriptors...", MONITOR_LENGTH);
+
         Map/* <ModuleDescriptor, ResolveRequest> */inworkspaceModules = new LinkedHashMap();
         List/* <ResolveRequest> */otherModules = new ArrayList();
         Map/* <ResolveRequest, Ivy> */ivys = new HashMap();
@@ -87,6 +95,8 @@ public class IvyResolveJob extends Job {
         MultiStatus errorsStatus = new MultiStatus(IvyPlugin.ID, IStatus.ERROR,
                 "Some projects fail to be resolved", null);
 
+        int step = IVY_LOAD_LENGTH / toResolve.size();
+
         // Ivy use the SaxParserFactory, and we want it to instanciate the xerces parser
which is in
         // the dependencies of IvyDE, so accessible via the current classloader
         ClassLoader old = Thread.currentThread().getContextClassLoader();
@@ -103,6 +113,7 @@ public class IvyResolveJob extends Job {
                     cachedIvy.setErrorMarker(e);
                     errorsStatus.add(e.asStatus(IStatus.ERROR, "Failed to configure Ivy for
"
                             + request));
+                    monitor.worked(step);
                     continue;
                 }
                 cachedIvy.setErrorMarker(null);
@@ -117,6 +128,7 @@ public class IvyResolveJob extends Job {
                     cachedIvy.setErrorMarker(e);
                     errorsStatus.add(e.asStatus(IStatus.ERROR, "Failed to load the descriptor
for "
                             + request));
+                    monitor.worked(step);
                     continue;
                 } finally {
                     ivy.popContext();
@@ -128,11 +140,14 @@ public class IvyResolveJob extends Job {
                 } else {
                     otherModules.add(request);
                 }
+                monitor.worked(step);
             }
         } finally {
             Thread.currentThread().setContextClassLoader(old);
         }
 
+        step = (MONITOR_LENGTH - IVY_LOAD_LENGTH - POST_RESOLVE_LENGTH) / toResolve.size();
+
         if (!inworkspaceModules.isEmpty()) {
             // for the modules which are using the workspace resolver, make sure
             // we resolve them in the correct order
@@ -154,7 +169,8 @@ public class IvyResolveJob extends Job {
                 request = (ResolveRequest) inworkspaceModules.get(it.next());
                 Ivy ivy = (Ivy) ivys.get(request);
                 ModuleDescriptor md = (ModuleDescriptor) mds.get(request);
-                boolean canceled = launchResolveThread(request, monitor, errorsStatus, ivy,
md);
+                boolean canceled = launchResolveThread(request, monitor, step, errorsStatus,
ivy,
+                    md);
                 if (canceled) {
                     return Status.CANCEL_STATUS;
                 }
@@ -167,18 +183,22 @@ public class IvyResolveJob extends Job {
                 ResolveRequest request = (ResolveRequest) it.next();
                 Ivy ivy = (Ivy) ivys.get(request);
                 ModuleDescriptor md = (ModuleDescriptor) mds.get(request);
-                boolean canceled = launchResolveThread(request, monitor, errorsStatus, ivy,
md);
+                boolean canceled = launchResolveThread(request, monitor, step, errorsStatus,
ivy,
+                    md);
                 if (canceled) {
                     return Status.CANCEL_STATUS;
                 }
             }
         }
 
+        step = POST_RESOLVE_LENGTH / toResolve.size();
+
         // launch every post batch resolve
         Iterator itRequests = toResolve.iterator();
         while (itRequests.hasNext()) {
             ResolveRequest request = (ResolveRequest) itRequests.next();
             request.getResolver().postBatchResolve();
+            monitor.worked(step);
         }
 
         if (errorsStatus.getChildren().length != 0) {
@@ -189,14 +209,14 @@ public class IvyResolveJob extends Job {
     }
 
     private boolean launchResolveThread(ResolveRequest request, final IProgressMonitor monitor,
-            MultiStatus errorsStatus, final Ivy ivy, final ModuleDescriptor md) {
+            final int step, MultiStatus errorsStatus, final Ivy ivy, final ModuleDescriptor
md) {
 
         final IStatus[] status = new IStatus[1];
 
         final IvyResolver resolver = request.getResolver();
         Runnable resolveRunner = new Runnable() {
             public void run() {
-                status[0] = resolver.resolve(ivy, md, monitor);
+                status[0] = resolver.resolve(ivy, md, monitor, step);
             }
         };
 

Modified: ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/resolve/IvyResolveJobListener.java
URL: http://svn.apache.org/viewvc/ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/resolve/IvyResolveJobListener.java?rev=992783&r1=992782&r2=992783&view=diff
==============================================================================
--- ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/resolve/IvyResolveJobListener.java
(original)
+++ ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/resolve/IvyResolveJobListener.java
Sun Sep  5 13:51:00 2010
@@ -23,6 +23,7 @@ import org.apache.ivy.core.event.downloa
 import org.apache.ivy.core.event.download.PrepareDownloadEvent;
 import org.apache.ivy.core.event.download.StartArtifactDownloadEvent;
 import org.apache.ivy.core.event.resolve.EndResolveDependencyEvent;
+import org.apache.ivy.core.event.resolve.EndResolveEvent;
 import org.apache.ivy.core.event.resolve.StartResolveDependencyEvent;
 import org.apache.ivy.core.module.descriptor.Artifact;
 import org.apache.ivy.plugins.repository.TransferEvent;
@@ -36,11 +37,11 @@ public class IvyResolveJobListener imple
 
     private static final int KILO_BITS_UNIT = 1024;
 
-    private static final int MONITOR_LENGTH = 1000;
-
     private static final int WORK_PER_ARTIFACT = 100;
 
-    private long expectedTotalLength = 1;
+    private static final int RESOLVE_PERCENT = 2;
+
+    private long totalLength = 1;
 
     private int workPerArtifact = WORK_PER_ARTIFACT;
 
@@ -50,8 +51,14 @@ public class IvyResolveJobListener imple
 
     private IProgressMonitor dlmonitor;
 
-    public IvyResolveJobListener(IProgressMonitor monitor) {
+    private final int downloadStep;
+
+    private int resolveStep;
+
+    public IvyResolveJobListener(IProgressMonitor monitor, int step) {
         this.monitor = monitor;
+        this.resolveStep = step / RESOLVE_PERCENT;
+        this.downloadStep = step;
     }
 
     public void transferProgress(TransferEvent evt) {
@@ -62,20 +69,19 @@ public class IvyResolveJobListener imple
             case TransferEvent.TRANSFER_STARTED:
                 currentLength = 0;
                 if (evt.isTotalLengthSet()) {
-                    expectedTotalLength = evt.getTotalLength();
+                    totalLength = evt.getTotalLength();
                     dlmonitor
                             .beginTask("downloading " + evt.getResource(), DOWNLOAD_MONITOR_LENGTH);
                 }
                 break;
             case TransferEvent.TRANSFER_PROGRESS:
-                if (expectedTotalLength > 1) {
+                if (totalLength > 1) {
                     currentLength += evt.getLength();
-                    int progress = (int) (currentLength * DOWNLOAD_MONITOR_LENGTH
-                            / expectedTotalLength);
+                    int progress = (int) (currentLength * DOWNLOAD_MONITOR_LENGTH / totalLength);
                     dlmonitor.worked(progress);
                     monitor.subTask("downloading " + evt.getResource() + ": "
                             + (currentLength / KILO_BITS_UNIT) + " / "
-                            + (expectedTotalLength / KILO_BITS_UNIT) + "kB");
+                            + (totalLength / KILO_BITS_UNIT) + "kB");
                 }
                 break;
             default:
@@ -91,7 +97,7 @@ public class IvyResolveJobListener imple
             PrepareDownloadEvent pde = (PrepareDownloadEvent) event;
             Artifact[] artifacts = pde.getArtifacts();
             if (artifacts.length > 0) {
-                workPerArtifact = MONITOR_LENGTH / artifacts.length;
+                workPerArtifact = downloadStep / artifacts.length;
             }
         } else if (event instanceof StartArtifactDownloadEvent) {
             StartArtifactDownloadEvent evt = (StartArtifactDownloadEvent) event;
@@ -111,6 +117,8 @@ public class IvyResolveJobListener imple
             monitor.subTask("resolving " + ev.getDependencyDescriptor().getDependencyRevisionId());
         } else if (event instanceof EndResolveDependencyEvent) {
             monitor.subTask(" ");
+        } else if (event instanceof EndResolveEvent) {
+            monitor.worked(resolveStep);
         }
     }
 

Modified: ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/resolve/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?rev=992783&r1=992782&r2=992783&view=diff
==============================================================================
--- ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/resolve/IvyResolver.java
(original)
+++ ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/resolve/IvyResolver.java
Sun Sep  5 13:51:00 2010
@@ -57,8 +57,6 @@ import org.eclipse.core.runtime.Status;
  */
 public class IvyResolver {
 
-    private static final int MONITOR_LENGTH = 1000;
-
     private boolean usePreviousResolveIfExist = false;
 
     private String[] confs;
@@ -105,14 +103,13 @@ public class IvyResolver {
         return project;
     }
 
-    public IStatus resolve(Ivy ivy, ModuleDescriptor md, IProgressMonitor monitor) {
+    public IStatus resolve(Ivy ivy, ModuleDescriptor md, IProgressMonitor monitor, int step)
{
         computeConfs(confInput, md);
         try {
             ivy.pushContext();
-            IvyResolveJobListener ivyResolveJobListener = new IvyResolveJobListener(monitor);
+            IvyResolveJobListener ivyResolveJobListener = new IvyResolveJobListener(monitor,
step);
             ivy.getEventManager().addIvyListener(ivyResolveJobListener);
 
-            monitor.beginTask("Resolve of " + toString(), MONITOR_LENGTH);
             monitor.setTaskName("Resolve of " + toString());
 
             ResolveResult result = new ResolveResult();
@@ -143,7 +140,6 @@ public class IvyResolver {
                 return new Status(IStatus.ERROR, IvyPlugin.ID, IStatus.ERROR, errorMsg, e);
             } finally {
                 Thread.currentThread().setContextClassLoader(old);
-                monitor.done();
                 ivy.getEventManager().removeIvyListener(ivyResolveJobListener);
             }
 



Mime
View raw message