ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hi...@apache.org
Subject svn commit: r993157 - /ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/resolve/IvyResolveJobListener.java
Date Mon, 06 Sep 2010 21:43:06 GMT
Author: hibou
Date: Mon Sep  6 21:43:05 2010
New Revision: 993157

URL: http://svn.apache.org/viewvc?rev=993157&view=rev
Log:
Fix the progress of the download

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

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=993157&r1=993156&r2=993157&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
Mon Sep  6 21:43:05 2010
@@ -26,36 +26,32 @@ import org.apache.ivy.core.event.resolve
 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.core.module.id.ModuleRevisionId;
 import org.apache.ivy.plugins.repository.TransferEvent;
 import org.apache.ivy.plugins.repository.TransferListener;
 import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.SubProgressMonitor;
 
 public class IvyResolveJobListener implements TransferListener, IvyListener {
 
-    private static final int DOWNLOAD_MONITOR_LENGTH = 100;
-
     private static final int KILO_BITS_UNIT = 1024;
 
-    private static final int WORK_PER_ARTIFACT = 100;
-
     private static final int RESOLVE_PERCENT = 2;
 
     private long totalLength = 1;
 
-    private int workPerArtifact = WORK_PER_ARTIFACT;
+    private int workPerArtifact = 0;
 
     private long currentLength = 0;
 
-    private final IProgressMonitor monitor;
+    private int currentProgress = 0;
 
-    private IProgressMonitor dlmonitor;
+    private final IProgressMonitor monitor;
 
     private final int downloadStep;
 
     private int resolveStep;
 
-    public IvyResolveJobListener(IProgressMonitor monitor, int step) {
+    public IvyResolveJobListener(final IProgressMonitor monitor, int step) {
         this.monitor = monitor;
         this.resolveStep = step / RESOLVE_PERCENT;
         this.downloadStep = step;
@@ -68,31 +64,35 @@ public class IvyResolveJobListener imple
                 break;
             case TransferEvent.TRANSFER_STARTED:
                 currentLength = 0;
+                currentProgress = 0;
                 if (evt.isTotalLengthSet()) {
                     totalLength = evt.getTotalLength();
-                    dlmonitor
-                            .beginTask("downloading " + evt.getResource(), DOWNLOAD_MONITOR_LENGTH);
+                    monitor.subTask("downloading " + evt.getResource() + ": 0 / "
+                            + (totalLength / KILO_BITS_UNIT) + "kB");
                 }
                 break;
             case TransferEvent.TRANSFER_PROGRESS:
                 if (totalLength > 1) {
                     currentLength += evt.getLength();
-                    int progress = (int) (currentLength * DOWNLOAD_MONITOR_LENGTH / totalLength);
-                    dlmonitor.worked(progress);
+                    int progress = (int) ((currentLength * workPerArtifact) / totalLength);
+                    // log an accumulated diff
+                    monitor.worked(progress - currentProgress);
+                    currentProgress = progress;
                     monitor.subTask("downloading " + evt.getResource() + ": "
                             + (currentLength / KILO_BITS_UNIT) + " / "
                             + (totalLength / KILO_BITS_UNIT) + "kB");
                 }
                 break;
+            case TransferEvent.TRANSFER_COMPLETED:
+                monitor.worked(workPerArtifact - currentProgress);
+                break;
             default:
         }
     }
 
     public void progress(IvyEvent event) {
         if (event instanceof TransferEvent) {
-            if (dlmonitor != null) {
-                transferProgress((TransferEvent) event);
-            }
+            transferProgress((TransferEvent) event);
         } else if (event instanceof PrepareDownloadEvent) {
             PrepareDownloadEvent pde = (PrepareDownloadEvent) event;
             Artifact[] artifacts = pde.getArtifacts();
@@ -102,19 +102,14 @@ public class IvyResolveJobListener imple
         } else if (event instanceof StartArtifactDownloadEvent) {
             StartArtifactDownloadEvent evt = (StartArtifactDownloadEvent) event;
             monitor.subTask("downloading " + evt.getArtifact());
-            if (dlmonitor != null) {
-                dlmonitor.done();
-            }
-            dlmonitor = new SubProgressMonitor(monitor, workPerArtifact);
         } else if (event instanceof EndArtifactDownloadEvent) {
-            if (dlmonitor != null) {
-                dlmonitor.done();
-            }
+            monitor.worked(workPerArtifact - currentProgress);
+            currentProgress = 0;
             monitor.subTask(" ");
-            dlmonitor = null;
         } else if (event instanceof StartResolveDependencyEvent) {
             StartResolveDependencyEvent ev = (StartResolveDependencyEvent) event;
-            monitor.subTask("resolving " + ev.getDependencyDescriptor().getDependencyRevisionId());
+            ModuleRevisionId mrid = ev.getDependencyDescriptor().getDependencyRevisionId();
+            monitor.subTask("looking for " + mrid);
         } else if (event instanceof EndResolveDependencyEvent) {
             monitor.subTask(" ");
         } else if (event instanceof EndResolveEvent) {



Mime
View raw message