camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [1/2] git commit: CAMEL-6982: Nicer Camel Karaf commands output for table data.
Date Tue, 19 Nov 2013 15:27:25 GMT
Updated Branches:
  refs/heads/camel-2.12.x 5612d9a39 -> 88e0a4af0
  refs/heads/master 08ef2a438 -> 4287ee654


CAMEL-6982: Nicer Camel Karaf commands output for table data.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/4287ee65
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/4287ee65
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/4287ee65

Branch: refs/heads/master
Commit: 4287ee654c26aa89638d9a9f3dc89cf24ad1dcbd
Parents: 08ef2a4
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Tue Nov 19 16:28:46 2013 +0100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Tue Nov 19 16:28:46 2013 +0100

----------------------------------------------------------------------
 .../camel/karaf/commands/ContextList.java       | 21 ++++++++++++--------
 .../camel/karaf/commands/EndpointList.java      | 19 +++++++++++-------
 .../apache/camel/karaf/commands/RouteList.java  | 19 +++++++++++-------
 .../camel/karaf/commands/RouteProfile.java      |  4 +---
 4 files changed, 38 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/4287ee65/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/ContextList.java
----------------------------------------------------------------------
diff --git a/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/ContextList.java
b/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/ContextList.java
index 40d5402..1dfe09c 100644
--- a/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/ContextList.java
+++ b/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/ContextList.java
@@ -35,12 +35,13 @@ public class ContextList extends OsgiCommandSupport {
     private static final String STATUS_COLUMN_LABEL = "Status";
     private static final String UPTIME_COLUMN_LABEL = "Uptime";
     private static final int DEFAULT_FORMAT_BUFFER_LENGTH = 24;
-    private static final String DEFAULT_FIELD_PREAMBLE = "[ ";
-    private static final String DEFAULT_FIELD_POSTAMBLE = " ]";
-    private static final String DEFAULT_HEADER_PREAMBLE = "  ";
-    private static final String DEFAULT_HEADER_POSTAMBLE = "  ";
+    private static final String DEFAULT_FIELD_PREAMBLE = " ";
+    private static final String DEFAULT_FIELD_POSTAMBLE = " ";
+    private static final String DEFAULT_HEADER_PREAMBLE = " ";
+    private static final String DEFAULT_HEADER_POSTAMBLE = " ";
     private static final int DEFAULT_COLUMN_WIDTH_INCREMENT = 0;
     private static final int MAX_COLUMN_WIDTH = Integer.MAX_VALUE;
+    private static final int MIN_COLUMN_WIDTH = 12;
 
     private CamelController camelController;
 
@@ -58,6 +59,7 @@ public class ContextList extends OsgiCommandSupport {
 
         if (camelContexts.size() > 0) {
             out.println(String.format(headerFormat, CONTEXT_COLUMN_LABEL, STATUS_COLUMN_LABEL,
UPTIME_COLUMN_LABEL));
+            out.println(String.format(headerFormat, "-------", "------", "------"));
             for (final CamelContext camelContext : camelContexts) {
                 out.println(String.format(rowFormat, camelContext.getName(), camelContext.getStatus(),
camelContext.getUptime()));
             }
@@ -108,12 +110,15 @@ public class ContextList extends OsgiCommandSupport {
         }
         columnWidthIncrement = DEFAULT_COLUMN_WIDTH_INCREMENT;
 
-        final int nameLen = java.lang.Math.min(columnWidths.get(CONTEXT_COLUMN_LABEL) + columnWidthIncrement,
MAX_COLUMN_WIDTH);
-        final int statusLen = java.lang.Math.min(columnWidths.get(STATUS_COLUMN_LABEL) +
columnWidthIncrement, MAX_COLUMN_WIDTH);
-        final int uptimeLen = java.lang.Math.min(columnWidths.get(UPTIME_COLUMN_LABEL) +
columnWidthIncrement, MAX_COLUMN_WIDTH);
+        int contextLen = java.lang.Math.min(columnWidths.get(CONTEXT_COLUMN_LABEL) + columnWidthIncrement,
MAX_COLUMN_WIDTH);
+        int statusLen = java.lang.Math.min(columnWidths.get(STATUS_COLUMN_LABEL) + columnWidthIncrement,
MAX_COLUMN_WIDTH);
+        int uptimeLen = java.lang.Math.min(columnWidths.get(UPTIME_COLUMN_LABEL) + columnWidthIncrement,
MAX_COLUMN_WIDTH);
+        contextLen = Math.max(MIN_COLUMN_WIDTH, contextLen);
+        statusLen = Math.max(MIN_COLUMN_WIDTH, statusLen);
+        // last row does not have min width
 
         final StringBuilder retval = new StringBuilder(DEFAULT_FORMAT_BUFFER_LENGTH);
-        retval.append(fieldPreamble).append("%-").append(nameLen).append('.').append(nameLen).append('s').append(fieldPostamble).append('
');
+        retval.append(fieldPreamble).append("%-").append(contextLen).append('.').append(contextLen).append('s').append(fieldPostamble).append('
');
         retval.append(fieldPreamble).append("%-").append(statusLen).append('.').append(statusLen).append('s').append(fieldPostamble).append('
');
         retval.append(fieldPreamble).append("%-").append(uptimeLen).append('.').append(uptimeLen).append('s').append(fieldPostamble).append('
');
 

http://git-wip-us.apache.org/repos/asf/camel/blob/4287ee65/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/EndpointList.java
----------------------------------------------------------------------
diff --git a/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/EndpointList.java
b/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/EndpointList.java
index bb93842..598c0d4 100644
--- a/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/EndpointList.java
+++ b/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/EndpointList.java
@@ -42,13 +42,14 @@ public class EndpointList extends OsgiCommandSupport {
     private static final String STATUS_COLUMN_LABEL = "Status";
 
     private static final int DEFAULT_COLUMN_WIDTH_INCREMENT = 0;
-    private static final String DEFAULT_FIELD_PREAMBLE = "[ ";
-    private static final String DEFAULT_FIELD_POSTAMBLE = " ]";
-    private static final String DEFAULT_HEADER_PREAMBLE = "  ";
-    private static final String DEFAULT_HEADER_POSTAMBLE = "  ";
+    private static final String DEFAULT_FIELD_PREAMBLE = " ";
+    private static final String DEFAULT_FIELD_POSTAMBLE = " ";
+    private static final String DEFAULT_HEADER_PREAMBLE = " ";
+    private static final String DEFAULT_HEADER_POSTAMBLE = " ";
     private static final int DEFAULT_FORMAT_BUFFER_LENGTH = 24;
     // endpoint uris can be very long so clip by default after 120 chars
     private static final int MAX_COLUMN_WIDTH = 120;
+    private static final int MIN_COLUMN_WIDTH = 12;
 
     @Argument(index = 0, name = "name", description = "The Camel context name where to look
for the endpoints", required = false, multiValued = false)
     String name;
@@ -77,6 +78,7 @@ public class EndpointList extends OsgiCommandSupport {
 
         if (endpoints.size() > 0) {
             out.println(String.format(headerFormat, CONTEXT_COLUMN_LABEL, URI_COLUMN_LABEL,
STATUS_COLUMN_LABEL));
+            out.println(String.format(headerFormat, "-------", "---", "------"));
             for (final Endpoint endpoint : endpoints) {
                 String contextId = endpoint.getCamelContext().getName();
                 String uri = endpoint.getEndpointUri();
@@ -143,9 +145,12 @@ public class EndpointList extends OsgiCommandSupport {
         }
         columnWidthIncrement = DEFAULT_COLUMN_WIDTH_INCREMENT;
 
-        final int contextLen = java.lang.Math.min(columnWidths.get(CONTEXT_COLUMN_LABEL)
+ columnWidthIncrement, getMaxColumnWidth());
-        final int uriLen = java.lang.Math.min(columnWidths.get(URI_COLUMN_LABEL) + columnWidthIncrement,
getMaxColumnWidth());
-        final int statusLen = java.lang.Math.min(columnWidths.get(STATUS_COLUMN_LABEL) +
columnWidthIncrement, getMaxColumnWidth());
+        int contextLen = java.lang.Math.min(columnWidths.get(CONTEXT_COLUMN_LABEL) + columnWidthIncrement,
getMaxColumnWidth());
+        int uriLen = java.lang.Math.min(columnWidths.get(URI_COLUMN_LABEL) + columnWidthIncrement,
getMaxColumnWidth());
+        int statusLen = java.lang.Math.min(columnWidths.get(STATUS_COLUMN_LABEL) + columnWidthIncrement,
getMaxColumnWidth());
+        contextLen = Math.max(MIN_COLUMN_WIDTH, contextLen);
+        uriLen = Math.max(MIN_COLUMN_WIDTH, uriLen);
+        // last row does not have min width
 
         final StringBuilder retval = new StringBuilder(DEFAULT_FORMAT_BUFFER_LENGTH);
         retval.append(fieldPreamble).append("%-").append(contextLen).append('.').append(contextLen).append('s').append(fieldPostamble).append('
');

http://git-wip-us.apache.org/repos/asf/camel/blob/4287ee65/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteList.java
----------------------------------------------------------------------
diff --git a/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteList.java
b/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteList.java
index 76ada1c..df081c1 100644
--- a/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteList.java
+++ b/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteList.java
@@ -38,12 +38,13 @@ public class RouteList extends OsgiCommandSupport {
     private static final String STATUS_COLUMN_LABEL = "Status";
 
     private static final int DEFAULT_COLUMN_WIDTH_INCREMENT = 0;
-    private static final String DEFAULT_FIELD_PREAMBLE = "[ ";
-    private static final String DEFAULT_FIELD_POSTAMBLE = " ]";
-    private static final String DEFAULT_HEADER_PREAMBLE = "  ";
-    private static final String DEFAULT_HEADER_POSTAMBLE = "  ";
+    private static final String DEFAULT_FIELD_PREAMBLE = " ";
+    private static final String DEFAULT_FIELD_POSTAMBLE = " ";
+    private static final String DEFAULT_HEADER_PREAMBLE = " ";
+    private static final String DEFAULT_HEADER_POSTAMBLE = " ";
     private static final int DEFAULT_FORMAT_BUFFER_LENGTH = 24;
     private static final int MAX_COLUMN_WIDTH = Integer.MAX_VALUE;
+    private static final int MIN_COLUMN_WIDTH = 12;
 
     @Argument(index = 0, name = "name", description = "The Camel context name where to look
for the route", required = false, multiValued = false)
     String name;
@@ -64,6 +65,7 @@ public class RouteList extends OsgiCommandSupport {
 
         if (routes.size() > 0) {
             out.println(String.format(headerFormat, CONTEXT_COLUMN_LABEL, ROUTE_COLUMN_LABEL,
STATUS_COLUMN_LABEL));
+            out.println(String.format(headerFormat, "-------", "-----", "------"));
             for (Route route : routes) {
                 String contextId = route.getRouteContext().getCamelContext().getName();
                 String routeId = route.getId();
@@ -117,9 +119,12 @@ public class RouteList extends OsgiCommandSupport {
         }
         columnWidthIncrement = DEFAULT_COLUMN_WIDTH_INCREMENT;
 
-        final int contextLen = java.lang.Math.min(columnWidths.get(CONTEXT_COLUMN_LABEL)
+ columnWidthIncrement, MAX_COLUMN_WIDTH);
-        final int routeLen = java.lang.Math.min(columnWidths.get(ROUTE_COLUMN_LABEL) + columnWidthIncrement,
MAX_COLUMN_WIDTH);
-        final int statusLen = java.lang.Math.min(columnWidths.get(STATUS_COLUMN_LABEL) +
columnWidthIncrement, MAX_COLUMN_WIDTH);
+        int contextLen = Math.min(columnWidths.get(CONTEXT_COLUMN_LABEL) + columnWidthIncrement,
MAX_COLUMN_WIDTH);
+        int routeLen = Math.min(columnWidths.get(ROUTE_COLUMN_LABEL) + columnWidthIncrement,
MAX_COLUMN_WIDTH);
+        int statusLen = Math.min(columnWidths.get(STATUS_COLUMN_LABEL) + columnWidthIncrement,
MAX_COLUMN_WIDTH);
+        contextLen = Math.max(MIN_COLUMN_WIDTH, contextLen);
+        routeLen = Math.max(MIN_COLUMN_WIDTH, routeLen);
+        // last row does not have min width
 
         final StringBuilder retval = new StringBuilder(DEFAULT_FORMAT_BUFFER_LENGTH);
         retval.append(fieldPreamble).append("%-").append(contextLen).append('.').append(contextLen).append('s').append(fieldPostamble).append('
');

http://git-wip-us.apache.org/repos/asf/camel/blob/4287ee65/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteProfile.java
----------------------------------------------------------------------
diff --git a/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteProfile.java
b/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteProfile.java
index c82f812..98c94e4 100644
--- a/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteProfile.java
+++ b/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteProfile.java
@@ -38,7 +38,7 @@ import org.apache.karaf.util.StringEscapeUtils;
 public class RouteProfile extends AbstractRouteCommand {
 
     protected static final String HEADER_FORMAT = "%-30s %10s %12s %12s %12s %12s %12s %12s
%12s";
-    protected static final String OUTPUT_FORMAT = "[%-28s] [%8d] [%10d] [%10d] [%10d] [%10d]
[%10d] [%10d] [%10d]";
+    protected static final String OUTPUT_FORMAT = "%-30s %10d %12d %12d %12d %12d %12d %12d
%12d";
 
     private String previousCamelContextName;
 
@@ -60,8 +60,6 @@ public class RouteProfile extends AbstractRouteCommand {
             System.out.println(StringEscapeUtils.unescapeJava("\tCamel Context: " + camelRoute.getRouteContext().getCamelContext().getName()));
             System.out.println(String.format(HEADER_FORMAT, "Id", "Count", "Last (ms)", "Delta
(ms)", "Mean (ms)", "Min (ms)", "Max (ms)", "Total (ms)", "Self (ms)"));
         }
-//        System.out.println(StringEscapeUtils.unescapeJava("\u001B[1m\u001B[33mCamel Route
" + camelRoute.getId() + "\u001B[0m"));
-//        System.out.println(StringEscapeUtils.unescapeJava("\tEndpoint uri: " + URISupport.sanitizeUri(camelRoute.getEndpoint().getEndpointUri())));
 
         ManagementAgent agent = camelContext.getManagementStrategy().getManagementAgent();
         if (agent != null) {


Mime
View raw message