You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by jb...@apache.org on 2014/02/24 18:23:29 UTC
git commit: [KARAF-52] Use ShellTable in scr commands
Repository: karaf
Updated Branches:
refs/heads/master 898ef9d0c -> d0c4f4108
[KARAF-52] Use ShellTable in scr commands
Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/d0c4f410
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/d0c4f410
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/d0c4f410
Branch: refs/heads/master
Commit: d0c4f41086474bcfb0496ac3dafa7bf5875c42c6
Parents: 898ef9d
Author: Jean-Baptiste Onofré <jb...@apache.org>
Authored: Mon Feb 24 18:22:59 2014 +0100
Committer: Jean-Baptiste Onofré <jb...@apache.org>
Committed: Mon Feb 24 18:22:59 2014 +0100
----------------------------------------------------------------------
scr/command/pom.xml | 5 ++++
.../scr/command/action/ActivateAction.java | 6 ++---
.../scr/command/action/DeactivateAction.java | 6 ++---
.../karaf/scr/command/action/DetailsAction.java | 15 ++++++------
.../karaf/scr/command/action/ListAction.java | 25 ++++++++------------
.../scr/command/action/ScrActionSupport.java | 12 ----------
6 files changed, 27 insertions(+), 42 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf/blob/d0c4f410/scr/command/pom.xml
----------------------------------------------------------------------
diff --git a/scr/command/pom.xml b/scr/command/pom.xml
index 9b6bba2..59cfb7a 100644
--- a/scr/command/pom.xml
+++ b/scr/command/pom.xml
@@ -57,6 +57,11 @@
<scope>provided</scope>
</dependency>
<dependency>
+ <groupId>org.apache.karaf.shell</groupId>
+ <artifactId>org.apache.karaf.shell.table</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
<scope>provided</scope>
http://git-wip-us.apache.org/repos/asf/karaf/blob/d0c4f410/scr/command/src/main/java/org/apache/karaf/scr/command/action/ActivateAction.java
----------------------------------------------------------------------
diff --git a/scr/command/src/main/java/org/apache/karaf/scr/command/action/ActivateAction.java b/scr/command/src/main/java/org/apache/karaf/scr/command/action/ActivateAction.java
index 049488c..22de6e2 100755
--- a/scr/command/src/main/java/org/apache/karaf/scr/command/action/ActivateAction.java
+++ b/scr/command/src/main/java/org/apache/karaf/scr/command/action/ActivateAction.java
@@ -39,10 +39,8 @@ public class ActivateAction extends ScrActionSupport {
@Override
protected Object doScrAction(ScrService scrService) throws Exception {
- if(logger.isDebugEnabled()){
- logger.debug("Activate Action");
- logger.debug(" Activating the Component: " + name);
- }
+ logger.debug("Activate Action");
+ logger.debug(" Activating the Component: " + name);
Component[] components = scrService.getComponents(name);
for (Component component : ScrUtils.emptyIfNull(Component.class, components)) {
component.enable();
http://git-wip-us.apache.org/repos/asf/karaf/blob/d0c4f410/scr/command/src/main/java/org/apache/karaf/scr/command/action/DeactivateAction.java
----------------------------------------------------------------------
diff --git a/scr/command/src/main/java/org/apache/karaf/scr/command/action/DeactivateAction.java b/scr/command/src/main/java/org/apache/karaf/scr/command/action/DeactivateAction.java
index 31eeecc..3c0093e 100755
--- a/scr/command/src/main/java/org/apache/karaf/scr/command/action/DeactivateAction.java
+++ b/scr/command/src/main/java/org/apache/karaf/scr/command/action/DeactivateAction.java
@@ -40,10 +40,8 @@ public class DeactivateAction extends ScrActionSupport {
@Override
protected Object doScrAction(ScrService scrService) throws Exception {
- if (logger.isDebugEnabled()) {
- logger.debug("Deactivate Action");
- logger.debug(" Deactivating the Component: " + name);
- }
+ logger.debug("Deactivate Action");
+ logger.debug(" Deactivating the Component: " + name);
Component[] components = scrService.getComponents(name);
if (components != null && components.length > 0) {
for (int i = 0; i < components.length; i++) {
http://git-wip-us.apache.org/repos/asf/karaf/blob/d0c4f410/scr/command/src/main/java/org/apache/karaf/scr/command/action/DetailsAction.java
----------------------------------------------------------------------
diff --git a/scr/command/src/main/java/org/apache/karaf/scr/command/action/DetailsAction.java b/scr/command/src/main/java/org/apache/karaf/scr/command/action/DetailsAction.java
index a93c722..4c1528a 100644
--- a/scr/command/src/main/java/org/apache/karaf/scr/command/action/DetailsAction.java
+++ b/scr/command/src/main/java/org/apache/karaf/scr/command/action/DetailsAction.java
@@ -26,6 +26,7 @@ import org.apache.karaf.shell.commands.Argument;
import org.apache.karaf.shell.commands.Command;
import org.apache.karaf.shell.commands.Completer;
import org.apache.karaf.shell.inject.Service;
+import org.fusesource.jansi.Ansi;
import org.osgi.framework.Constants;
import org.osgi.framework.ServiceReference;
import org.osgi.service.component.ComponentConstants;
@@ -33,13 +34,13 @@ import org.osgi.service.component.ComponentConstants;
import java.util.Hashtable;
/**
- * Displays the details associated with a given component by supplying its component name.
+ * Display the details associated with a given component by supplying its component name.
*/
-@Command(scope = ScrCommandConstants.SCR_COMMAND, name = ScrCommandConstants.DETAILS_FUNCTION, description = "Displays a list of available components")
+@Command(scope = ScrCommandConstants.SCR_COMMAND, name = ScrCommandConstants.DETAILS_FUNCTION, description = "Display available components")
@Service
public class DetailsAction extends ScrActionSupport {
- @Argument(index = 0, name = "name", description = "The name of the Component to display the details of", required = true, multiValued = false)
+ @Argument(index = 0, name = "name", description = "The component name", required = true, multiValued = false)
@Completer(DetailsCompleter.class)
String name;
@@ -49,7 +50,7 @@ public class DetailsAction extends ScrActionSupport {
if (logger.isDebugEnabled()) {
logger.debug("Executing the Details Action");
}
- System.out.println(getBoldString("Component Details"));
+ System.out.println(Ansi.ansi().a(Ansi.Attribute.INTENSITY_BOLD).a("Component Details").a(Ansi.Attribute.INTENSITY_BOLD_OFF));
Component[] components = scrService.getComponents(name);
for (Component component : ScrUtils.emptyIfNull(Component.class, components)) {
printDetail(" Name : ", component.getName());
@@ -57,14 +58,14 @@ public class DetailsAction extends ScrActionSupport {
Hashtable props = (Hashtable)component.getProperties();
if (!props.isEmpty()) {
- System.out.println(getBoldString(" Properties : "));
+ System.out.println(Ansi.ansi().a(Ansi.Attribute.INTENSITY_BOLD).a(" Properties : ").a(Ansi.Attribute.INTENSITY_BOLD_OFF));
for (Object key : props.keySet()) {
Object value = props.get(key);
printDetail(" ", key + "=" + value);
}
}
Reference[] references = component.getReferences();
- System.out.println(getBoldString("References"));
+ System.out.println(Ansi.ansi().a(Ansi.Attribute.INTENSITY_BOLD).a("References").a(Ansi.Attribute.INTENSITY_BOLD_OFF));
for (Reference reference : ScrUtils.emptyIfNull(Reference.class, references)) {
printDetail(" Reference : ", reference.getName());
@@ -106,7 +107,7 @@ public class DetailsAction extends ScrActionSupport {
}
private void printDetail(String header, String value) {
- System.out.println(getBoldString(header) + value);
+ System.out.println(Ansi.ansi().a(Ansi.Attribute.INTENSITY_BOLD).a(header).a(Ansi.Attribute.INTENSITY_BOLD_OFF).a(value));
}
}
http://git-wip-us.apache.org/repos/asf/karaf/blob/d0c4f410/scr/command/src/main/java/org/apache/karaf/scr/command/action/ListAction.java
----------------------------------------------------------------------
diff --git a/scr/command/src/main/java/org/apache/karaf/scr/command/action/ListAction.java b/scr/command/src/main/java/org/apache/karaf/scr/command/action/ListAction.java
index 26e3ca9..740da35 100755
--- a/scr/command/src/main/java/org/apache/karaf/scr/command/action/ListAction.java
+++ b/scr/command/src/main/java/org/apache/karaf/scr/command/action/ListAction.java
@@ -23,13 +23,14 @@ import org.apache.karaf.scr.command.ScrUtils;
import org.apache.karaf.scr.command.support.IdComparator;
import org.apache.karaf.shell.commands.Command;
import org.apache.karaf.shell.inject.Service;
+import org.apache.karaf.shell.table.ShellTable;
import java.util.Arrays;
/**
- * Lists all the components currently installed.
+ * List all the components currently installed.
*/
-@Command(scope = ScrCommandConstants.SCR_COMMAND, name = ScrCommandConstants.LIST_FUNCTION, description = "Displays a list of available components")
+@Command(scope = ScrCommandConstants.SCR_COMMAND, name = ScrCommandConstants.LIST_FUNCTION, description = "Display available components")
@Service
public class ListAction extends ScrActionSupport {
@@ -37,33 +38,27 @@ public class ListAction extends ScrActionSupport {
@Override
protected Object doScrAction(ScrService scrService) throws Exception {
- if (logger.isDebugEnabled()) {
- logger.debug("Executing the List Action");
- }
- System.out.println(getBoldString(" ID State Component Name"));
+ ShellTable table = new ShellTable();
+ table.column("ID");
+ table.column("State");
+ table.column("Component Name");
+
Component[] components = scrService.getComponents();
Arrays.sort(components, idComparator);
for (Component component : ScrUtils.emptyIfNull(Component.class, components)) {
if (showHidden) {
// we display all because we are overridden
- printComponent(component);
+ table.addRow().addContent(component.getId(), ScrUtils.getState(component.getState()), component.getName());
} else {
if (ScrActionSupport.isHiddenComponent(component)) {
// do nothing
} else {
// we aren't hidden so print it
- printComponent(component);
+ table.addRow().addContent(component.getId(), ScrUtils.getState(component.getState()), component.getName());
}
}
}
return null;
}
- private void printComponent(Component component) {
- String name = component.getName();
- String id = buildLeftPadBracketDisplay(component.getId() + "", 4);
- String state = buildRightPadBracketDisplay(ScrUtils.getState(component.getState()), 16);
- System.out.println("[" + id + "] [" + state + "] " + name);
- }
-
}
http://git-wip-us.apache.org/repos/asf/karaf/blob/d0c4f410/scr/command/src/main/java/org/apache/karaf/scr/command/action/ScrActionSupport.java
----------------------------------------------------------------------
diff --git a/scr/command/src/main/java/org/apache/karaf/scr/command/action/ScrActionSupport.java b/scr/command/src/main/java/org/apache/karaf/scr/command/action/ScrActionSupport.java
index 24c8619..5c85c1b 100755
--- a/scr/command/src/main/java/org/apache/karaf/scr/command/action/ScrActionSupport.java
+++ b/scr/command/src/main/java/org/apache/karaf/scr/command/action/ScrActionSupport.java
@@ -102,18 +102,6 @@ public abstract class ScrActionSupport extends AbstractAction {
return answer;
}
- public String getBoldString(String value) {
- return Ansi.ansi().a(Ansi.Attribute.INTENSITY_BOLD).a(value).a(Ansi.Attribute.INTENSITY_BOLD_OFF).toString();
- }
-
- public String buildRightPadBracketDisplay(String s, int max) {
- return String.format("%1$-" + max + "s", s);
- }
-
- public String buildLeftPadBracketDisplay(String s, int max) {
- return String.format("%1$-" + max + "s", s);
- }
-
/**
* Get the bundleContext Object associated with this instance of
* ScrActionSupport.