karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ff...@apache.org
Subject svn commit: r1423283 - /karaf/branches/karaf-2.3.x/main/src/main/java/org/apache/karaf/main/StartupListener.java
Date Tue, 18 Dec 2012 06:01:23 GMT
Author: ffang
Date: Tue Dec 18 06:01:22 2012
New Revision: 1423283

URL: http://svn.apache.org/viewvc?rev=1423283&view=rev
Log:
[KARAF-2073]Progress bar sometimes goes backwards

Modified:
    karaf/branches/karaf-2.3.x/main/src/main/java/org/apache/karaf/main/StartupListener.java

Modified: karaf/branches/karaf-2.3.x/main/src/main/java/org/apache/karaf/main/StartupListener.java
URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.3.x/main/src/main/java/org/apache/karaf/main/StartupListener.java?rev=1423283&r1=1423282&r2=1423283&view=diff
==============================================================================
--- karaf/branches/karaf-2.3.x/main/src/main/java/org/apache/karaf/main/StartupListener.java
(original)
+++ karaf/branches/karaf-2.3.x/main/src/main/java/org/apache/karaf/main/StartupListener.java
Tue Dec 18 06:01:22 2012
@@ -34,10 +34,12 @@ import org.osgi.framework.startlevel.Fra
  */
 class StartupListener implements FrameworkListener, SynchronousBundleListener {
     private static final String SYSTEM_PROP_KARAF_CONSOLE_STARTED = "karaf.console.started";
+    private int currentPercentage;
 
 	private final BundleContext context;
     StartupListener(BundleContext context) {
         this.context = context;
+        this.currentPercentage = 0;
         context.addBundleListener(this);
         context.addFrameworkListener(this);
     }
@@ -71,20 +73,24 @@ class StartupListener implements Framewo
         // progress bar can only have 72 characters so that 80 char wide terminal will display
properly
         int percent = (done * 100) / total;
         int scaledPercent = (int) (72.0 * (percent / 100.0));
-        StringBuilder sb = new StringBuilder();
-        sb.append(String.format("\r%3d%% [", percent));
-        for (int i = 0; i < 72; i++) {
-            if (i < scaledPercent) {
-                sb.append('=');
-            } else if (i == scaledPercent) {
-                sb.append('>');
-            } else {
-                sb.append(' ');
+        // Make sure we do not go backwards with percentage
+        if (percent > currentPercentage) {
+            currentPercentage = percent;
+            StringBuilder sb = new StringBuilder();
+            sb.append(String.format("\r%3d%% [", percent));
+            for (int i = 0; i < 72; i++) {
+                if (i < scaledPercent) {
+                    sb.append('=');
+                } else if (i == scaledPercent) {
+                    sb.append('>');
+                } else {
+                    sb.append(' ');
+                }
             }
+            sb.append(']');
+            System.out.print(sb.toString());
+            System.out.flush();
         }
-        sb.append(']');
-        System.out.print(sb.toString());
-        System.out.flush();
         if (done == total) {
             System.out.println();
         }



Mime
View raw message