You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by gn...@apache.org on 2016/09/20 13:55:34 UTC
cxf git commit: [CXF-7060] Leverage karaf shell tables support
Repository: cxf
Updated Branches:
refs/heads/master d8a0a04d9 -> c1e2c973f
[CXF-7060] Leverage karaf shell tables support
Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/c1e2c973
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/c1e2c973
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/c1e2c973
Branch: refs/heads/master
Commit: c1e2c973fc42ba7027fdd0ff1964bcbf8e61dbd6
Parents: d8a0a04
Author: Guillaume Nodet <gn...@apache.org>
Authored: Tue Sep 20 15:31:18 2016 +0200
Committer: Guillaume Nodet <gn...@apache.org>
Committed: Tue Sep 20 15:33:01 2016 +0200
----------------------------------------------------------------------
.../cxf/karaf/commands/ListBussesCommand.java | 38 ++++++++++----------
.../karaf/commands/ListEndpointsCommand.java | 24 ++++++++++---
2 files changed, 40 insertions(+), 22 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cxf/blob/c1e2c973/osgi/karaf4/commands/src/main/java/org/apache/cxf/karaf/commands/ListBussesCommand.java
----------------------------------------------------------------------
diff --git a/osgi/karaf4/commands/src/main/java/org/apache/cxf/karaf/commands/ListBussesCommand.java b/osgi/karaf4/commands/src/main/java/org/apache/cxf/karaf/commands/ListBussesCommand.java
index 820f065..5ea70a8 100644
--- a/osgi/karaf4/commands/src/main/java/org/apache/cxf/karaf/commands/ListBussesCommand.java
+++ b/osgi/karaf4/commands/src/main/java/org/apache/cxf/karaf/commands/ListBussesCommand.java
@@ -25,7 +25,11 @@ import org.apache.cxf.Bus;
import org.apache.cxf.karaf.commands.internal.CXFController;
import org.apache.karaf.shell.api.action.Action;
import org.apache.karaf.shell.api.action.Command;
+import org.apache.karaf.shell.api.action.Option;
+import org.apache.karaf.shell.api.action.lifecycle.Reference;
import org.apache.karaf.shell.api.action.lifecycle.Service;
+import org.apache.karaf.shell.api.console.Terminal;
+import org.apache.karaf.shell.support.table.ShellTable;
/**
*
@@ -33,33 +37,31 @@ import org.apache.karaf.shell.api.action.lifecycle.Service;
@Command(scope = "cxf", name = "list-busses", description = "Lists all CXF Busses.")
@Service
public class ListBussesCommand extends CXFController implements Action {
- protected static final int DEFAULT_BUSID_LENGTH = 38;
- protected String headerFormat = "%-40s %-20s";
- protected String outputFormat = "[%-38s] [%-18s]";
+
+ @Reference(optional = true)
+ Terminal terminal;
+
+ @Option(name = "--no-format", description = "Disable table rendered output", required = false, multiValued = false)
+ boolean noFormat;
@Override
public Object execute() throws Exception {
List<Bus> busses = getBusses();
- renderFormat(busses);
- System.out.println(String.format(headerFormat, "Name", "State"));
+
+ ShellTable table = new ShellTable();
+ if (terminal != null && terminal.getWidth() > 0) {
+ table.size(terminal.getWidth());
+ }
+ table.column("Name");
+ table.column("State");
for (Bus bus : busses) {
+ String name = bus.getId();
String state = bus.getState().toString();
- System.out.println(String.format(outputFormat, bus.getId(), state));
+ table.addRow().addContent(name, state);
}
+ table.print(System.out, !noFormat);
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]";
- }
- }
}
http://git-wip-us.apache.org/repos/asf/cxf/blob/c1e2c973/osgi/karaf4/commands/src/main/java/org/apache/cxf/karaf/commands/ListEndpointsCommand.java
----------------------------------------------------------------------
diff --git a/osgi/karaf4/commands/src/main/java/org/apache/cxf/karaf/commands/ListEndpointsCommand.java b/osgi/karaf4/commands/src/main/java/org/apache/cxf/karaf/commands/ListEndpointsCommand.java
index 1e4f7fa..3fb3323 100644
--- a/osgi/karaf4/commands/src/main/java/org/apache/cxf/karaf/commands/ListEndpointsCommand.java
+++ b/osgi/karaf4/commands/src/main/java/org/apache/cxf/karaf/commands/ListEndpointsCommand.java
@@ -34,7 +34,10 @@ import org.apache.karaf.shell.api.action.Argument;
import org.apache.karaf.shell.api.action.Command;
import org.apache.karaf.shell.api.action.Completion;
import org.apache.karaf.shell.api.action.Option;
+import org.apache.karaf.shell.api.action.lifecycle.Reference;
import org.apache.karaf.shell.api.action.lifecycle.Service;
+import org.apache.karaf.shell.api.console.Terminal;
+import org.apache.karaf.shell.support.table.ShellTable;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceReference;
import org.osgi.service.cm.Configuration;
@@ -60,6 +63,12 @@ public class ListEndpointsCommand extends CXFController implements Action {
description = "Display full address of an endpoint ", required = false, multiValued = false)
boolean fullAddress;
+ @Option(name = "--no-format", description = "Disable table rendered output", required = false, multiValued = false)
+ boolean noFormat;
+
+ @Reference(optional = true)
+ Terminal terminal;
+
@Override
public Object execute() throws Exception {
List<Bus> busses;
@@ -73,12 +82,18 @@ public class ListEndpointsCommand extends CXFController implements Action {
busses = Collections.emptyList();
}
}
- System.out.println(String.format(HEADER_FORMAT,
- "Name", "State", "Address", "BusID"));
+
+ ShellTable table = new ShellTable();
+ if (terminal != null && terminal.getWidth() > 0) {
+ table.size(terminal.getWidth());
+ }
+ table.column("Name");
+ table.column("State");
+ table.column("Address");
+ table.column("BusID");
for (Bus b : busses) {
ServerRegistry reg = b.getExtension(ServerRegistry.class);
List<Server> servers = reg.getServers();
-
for (Server serv : servers) {
String qname = serv.getEndpoint().getEndpointInfo().getName().getLocalPart();
String started = serv.isStarted() ? "Started" : "Stopped";
@@ -87,9 +102,10 @@ public class ListEndpointsCommand extends CXFController implements Action {
address = toFullAddress(address);
}
String busId = b.getId();
- System.out.println(String.format(OUTPUT_FORMAT, qname, started, address, busId));
+ table.addRow().addContent(qname, started, address, busId);
}
}
+ table.print(System.out, !noFormat);
return null;
}