You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by ff...@apache.org on 2012/12/04 05:24:49 UTC

svn commit: r1416771 - in /cxf/branches/2.5.x-fixes: ./ osgi/karaf/commands/src/main/java/org/apache/cxf/karaf/commands/ListBussesCommand.java

Author: ffang
Date: Tue Dec  4 04:24:48 2012
New Revision: 1416771

URL: http://svn.apache.org/viewvc?rev=1416771&view=rev
Log:
Merged revisions 1416768 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/branches/2.6.x-fixes

................
  r1416768 | ffang | 2012-12-04 12:08:14 +0800 (二, 04 12 2012) | 9 lines
  
  Merged revisions 1416766 via svnmerge from 
  https://svn.apache.org/repos/asf/cxf/trunk
  
  ........
    r1416766 | ffang | 2012-12-04 11:54:49 +0800 (二, 04 12 2012) | 1 line
    
    [CXF-4654]cxf:list-buses - Table layout should be aligned if bus name is long
  ........
................

Modified:
    cxf/branches/2.5.x-fixes/   (props changed)
    cxf/branches/2.5.x-fixes/osgi/karaf/commands/src/main/java/org/apache/cxf/karaf/commands/ListBussesCommand.java

Propchange: cxf/branches/2.5.x-fixes/
------------------------------------------------------------------------------
  Merged /cxf/trunk:r1416766
  Merged /cxf/branches/2.6.x-fixes:r1416768

Propchange: cxf/branches/2.5.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.5.x-fixes/osgi/karaf/commands/src/main/java/org/apache/cxf/karaf/commands/ListBussesCommand.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/osgi/karaf/commands/src/main/java/org/apache/cxf/karaf/commands/ListBussesCommand.java?rev=1416771&r1=1416770&r2=1416771&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/osgi/karaf/commands/src/main/java/org/apache/cxf/karaf/commands/ListBussesCommand.java (original)
+++ cxf/branches/2.5.x-fixes/osgi/karaf/commands/src/main/java/org/apache/cxf/karaf/commands/ListBussesCommand.java Tue Dec  4 04:24:48 2012
@@ -31,9 +31,10 @@ import org.apache.karaf.shell.console.Os
  */
 @Command(scope = "cxf", name = "list-busses", description = "Lists all CXF Busses.")
 public class ListBussesCommand extends OsgiCommandSupport {
-    protected static final String HEADER_FORMAT = "%-40s %-20s";
-    protected static final String OUTPUT_FORMAT = "[%-38s] [%-18s]";
-
+    protected static final int DEFAULT_BUSID_LENGTH = 38;
+    protected String headerFormat = "%-40s %-20s";
+    protected String outputFormat = "[%-38s] [%-18s]";
+   
     private CXFController cxfController;
 
     public void setController(CXFController controller) {
@@ -42,15 +43,29 @@ public class ListBussesCommand extends O
 
     protected Object doExecute() throws Exception {
         List<Bus> busses = cxfController.getBusses();
-        System.out.println(String.format(HEADER_FORMAT, "Name", "State"));
+        renderFormat(busses);
+        System.out.println(String.format(headerFormat, "Name", "State"));
 
         for (Bus bus : busses) {
             String state = "";
             if (bus instanceof CXFBusImpl) {
                 state = ((CXFBusImpl)bus).getState().toString();
             }
-            System.out.println(String.format(OUTPUT_FORMAT, bus.getId(), state));
+            System.out.println(String.format(outputFormat, bus.getId(), state));
         }
         return null;
     }
+
+    private void renderFormat(List<Bus> busses) {
+        int longestBusId = DEFAULT_BUSID_LENGTH;
+        for (Bus bus : busses) {
+            if (bus.getId().length() > longestBusId) {
+                longestBusId = bus.getId().length();
+            }
+        }
+        if (longestBusId > DEFAULT_BUSID_LENGTH) {
+            headerFormat = "%-" + (longestBusId + 2) + "s %-20s";
+            outputFormat = "[%-" + longestBusId + "s] [%-18s]";
+        }
+    }
 }