summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorAdrian Goerler2011-07-06 16:31:02 (EDT)
committer Adrian Goerler2011-07-06 16:31:02 (EDT)
commit95ae4bd8d79941992553979465c85b322a8036ae (patch)
treeda22759f910a9f0ea3198474185a4e03132b7fae
parent5322c585e12f678020d557615f14c81cd55e093f (diff)
downloadegit-95ae4bd8d79941992553979465c85b322a8036ae.zip
egit-95ae4bd8d79941992553979465c85b322a8036ae.tar.gz
egit-95ae4bd8d79941992553979465c85b322a8036ae.tar.bz2
Update progress monitor while counting objects.refs/changes/38/3838/2
The EGit progress monitor is fixed so that its state is also updated for unbounded monitors. Bug: 332696 Change-Id: Ice374512a4dac75b57cda7a846de4a898d76c449 Signed-off-by: Adrian Goerler <adrian.goerler@sap.com>
-rw-r--r--org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/EclipseGitProgressTransformerTest.java64
-rw-r--r--org.eclipse.egit.core/src/org/eclipse/egit/core/EclipseGitProgressTransformer.java40
2 files changed, 83 insertions, 21 deletions
diff --git a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/EclipseGitProgressTransformerTest.java b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/EclipseGitProgressTransformerTest.java
new file mode 100644
index 0000000..50f47b2
--- /dev/null
+++ b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/EclipseGitProgressTransformerTest.java
@@ -0,0 +1,64 @@
+/*******************************************************************************
+ * Copyright (C) 2011, Adrian G&ouml;rler <adrian.goerler@sap.com>
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+package org.eclipse.egit.core.test;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.egit.core.EclipseGitProgressTransformer;
+import org.eclipse.jgit.lib.ProgressMonitor;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+
+@RunWith(MockitoJUnitRunner.class)
+public class EclipseGitProgressTransformerTest {
+
+ @Mock
+ IProgressMonitor eclipseMonitor;
+
+ ProgressMonitor classUnderTest;
+
+ @Before
+ public void setup() {
+ classUnderTest = new EclipseGitProgressTransformer(eclipseMonitor);
+ }
+
+ @Test
+ public void testUnboundedMonitor() {
+ final String title = "Title";
+
+ classUnderTest.beginTask(title, ProgressMonitor.UNKNOWN);
+ Mockito.verify(eclipseMonitor).subTask("Title");
+
+ classUnderTest.update(10);
+ classUnderTest.update(0);
+ Mockito.verify(eclipseMonitor, Mockito.times(1)).subTask("Title, 10");
+ classUnderTest.update(20);
+ Mockito.verify(eclipseMonitor).subTask("Title, 30");
+
+ }
+
+ @Test
+ public void testBoundedMonitor() {
+ final String title = "Title";
+
+ classUnderTest.beginTask(title, 50);
+ Mockito.verify(eclipseMonitor).subTask("Title");
+
+ classUnderTest.update(10);
+ classUnderTest.update(0);
+ Mockito.verify(eclipseMonitor, Mockito.times(1)).subTask("Title: 20% (10/50)");
+ classUnderTest.update(20);
+ Mockito.verify(eclipseMonitor).subTask("Title: 60% (30/50)");
+
+ }
+
+}
diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/EclipseGitProgressTransformer.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/EclipseGitProgressTransformer.java
index 8fe9ff8..67603dd 100644
--- a/org.eclipse.egit.core/src/org/eclipse/egit/core/EclipseGitProgressTransformer.java
+++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/EclipseGitProgressTransformer.java
@@ -58,8 +58,9 @@ public class EclipseGitProgressTransformer implements ProgressMonitor {
return;
final int cmp = lastWorked + work;
- if (lastWorked == UNKNOWN && cmp > 0) {
- task.subTask(msg + ", " + cmp); //$NON-NLS-1$
+ if (totalWork == UNKNOWN && cmp > 0) {
+ if (lastWorked != cmp)
+ task.subTask(msg + ", " + cmp); //$NON-NLS-1$
} else if (totalWork <= 0) {
// Do nothing to update the task.
} else if (cmp * 100 / totalWork != lastWorked * 100 / totalWork) {
@@ -69,25 +70,22 @@ public class EclipseGitProgressTransformer implements ProgressMonitor {
while (m.length() < 25)
m.append(' ');
- if (totalWork == UNKNOWN) {
- m.append(cmp);
- } else {
- final String twstr = String.valueOf(totalWork);
- String cmpstr = String.valueOf(cmp);
- while (cmpstr.length() < twstr.length())
- cmpstr = " " + cmpstr; //$NON-NLS-1$
- final int pcnt = (cmp * 100 / totalWork);
- if (pcnt < 100)
- m.append(' ');
- if (pcnt < 10)
- m.append(' ');
- m.append(pcnt);
- m.append("% ("); //$NON-NLS-1$
- m.append(cmpstr);
- m.append("/"); //$NON-NLS-1$
- m.append(twstr);
- m.append(")"); //$NON-NLS-1$
- }
+ final String twstr = String.valueOf(totalWork);
+ String cmpstr = String.valueOf(cmp);
+ while (cmpstr.length() < twstr.length())
+ cmpstr = " " + cmpstr; //$NON-NLS-1$
+ final int pcnt = (cmp * 100 / totalWork);
+ if (pcnt < 100)
+ m.append(' ');
+ if (pcnt < 10)
+ m.append(' ');
+ m.append(pcnt);
+ m.append("% ("); //$NON-NLS-1$
+ m.append(cmpstr);
+ m.append("/"); //$NON-NLS-1$
+ m.append(twstr);
+ m.append(")"); //$NON-NLS-1$
+
task.subTask(m.toString());
}
lastWorked = cmp;