karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbono...@apache.org
Subject karaf git commit: [KARAF-4084] Support multi-options in bundle:list
Date Mon, 06 Jun 2016 12:52:35 GMT
Repository: karaf
Updated Branches:
  refs/heads/karaf-3.0.x b02011ee9 -> 184d37fbf


[KARAF-4084] Support multi-options in bundle:list


Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/184d37fb
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/184d37fb
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/184d37fb

Branch: refs/heads/karaf-3.0.x
Commit: 184d37fbf1745c0a3d7fc515133769285cf6627a
Parents: b02011e
Author: Jean-Baptiste Onofré <jbonofre@apache.org>
Authored: Mon Jun 6 14:51:08 2016 +0200
Committer: Jean-Baptiste Onofré <jbonofre@apache.org>
Committed: Mon Jun 6 14:51:08 2016 +0200

----------------------------------------------------------------------
 .../karaf/bundle/command/ListBundles.java       | 94 +++++++++++---------
 .../java/org/apache/karaf/shell/table/Row.java  |  4 +
 2 files changed, 54 insertions(+), 44 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/184d37fb/bundle/command/src/main/java/org/apache/karaf/bundle/command/ListBundles.java
----------------------------------------------------------------------
diff --git a/bundle/command/src/main/java/org/apache/karaf/bundle/command/ListBundles.java
b/bundle/command/src/main/java/org/apache/karaf/bundle/command/ListBundles.java
index 6b3dc54..9ccdf01 100644
--- a/bundle/command/src/main/java/org/apache/karaf/bundle/command/ListBundles.java
+++ b/bundle/command/src/main/java/org/apache/karaf/bundle/command/ListBundles.java
@@ -22,13 +22,19 @@ import org.apache.karaf.bundle.core.BundleState;
 import org.apache.karaf.shell.commands.Command;
 import org.apache.karaf.shell.commands.Option;
 import org.apache.karaf.shell.console.OsgiCommandSupport;
+import org.apache.karaf.shell.table.Row;
 import org.apache.karaf.shell.table.ShellTable;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.startlevel.FrameworkStartLevel;
 
+import java.util.ArrayList;
+
 @Command(scope = "bundle", name = "list", description = "Lists all installed bundles.")
 public class ListBundles extends OsgiCommandSupport {
 
+    @Option(name = "--no-name", description = "Don't show bundle name", required = false,
multiValued = false)
+    boolean dontShowName;
+
     @Option(name = "-l", aliases = {}, description = "Show the locations", required = false,
multiValued = false)
     boolean showLoc;
 
@@ -37,7 +43,7 @@ public class ListBundles extends OsgiCommandSupport {
 
     @Option(name = "-u", description = "Shows the update locations", required = false, multiValued
= false)
     boolean showUpdate;
-    
+
     @Option(name = "-r", description = "Shows the bundle revisions", required = false, multiValued
= false)
     boolean showRevisions;
 
@@ -61,7 +67,7 @@ public class ListBundles extends OsgiCommandSupport {
         }
 
         determineBundleLevelThreshold();
-        
+
         // Display active start level.
         FrameworkStartLevel fsl = getBundleContext().getBundle(0).adapt(FrameworkStartLevel.class);
         if (fsl != null) {
@@ -73,16 +79,52 @@ public class ListBundles extends OsgiCommandSupport {
         table.column("State");
         table.column("Lvl").alignRight();
         table.column("Version");
-        table.column(getNameHeader());
-        
+
+        if (!dontShowName) {
+            table.column("Name");
+        }
+        if (showLoc) {
+            table.column("Location");
+        }
+        if (showSymbolic) {
+            table.column("Symbolic name");
+        }
+        if (showUpdate) {
+            table.column("Update location");
+        }
+        if (showRevisions) {
+            table.column("Revisions");
+        }
+
         for (int i = 0; i < bundles.length; i++) {
             Bundle bundle = bundles[i];
             BundleInfo info = this.bundleService.getInfo(bundle);
             if (info.getStartLevel() >= bundleLevelThreshold) {
-                String name = getNameToShow(info) + printFragments(info) + printHosts(info);
-                String version = info.getVersion();
-                table.addRow().addContent(info.getBundleId(), getStateString(info.getState()),

-                        info.getStartLevel(), version, name);
+                ArrayList<Object> rowData = new ArrayList<Object>();
+                rowData.add(info.getBundleId());
+                rowData.add(getStateString(info.getState()));
+                rowData.add(info.getStartLevel());
+                rowData.add(info.getVersion());
+                if (!dontShowName) {
+                    String bundleName = (info.getName() == null) ? info.getSymbolicName()
: info.getName();
+                    bundleName = (bundleName == null) ? info.getUpdateLocation() : bundleName;
+                    String name = bundleName + printFragments(info) + printHosts(info);
+                    rowData.add(name);
+                }
+                if (showLoc) {
+                    rowData.add(info.getUpdateLocation());
+                }
+                if (showSymbolic) {
+                    rowData.add(info.getSymbolicName() == null ? "<no symbolic name>"
: info.getSymbolicName());
+                }
+                if (showUpdate) {
+                    rowData.add(info.getUpdateLocation());
+                }
+                if (showRevisions) {
+                    rowData.add(info.getRevisions());
+                }
+                Row row = table.addRow();
+                row.addContent(rowData);
             }
         }
         table.print(System.out, !noFormat);
@@ -90,20 +132,6 @@ public class ListBundles extends OsgiCommandSupport {
         return null;
     }
 
-    private String getNameHeader() {
-        String msg = "Name";
-        if (showLoc) {
-            msg = "Location";
-        } else if (showSymbolic) {
-            msg = "Symbolic name";
-        } else if (showUpdate) {
-            msg = "Update location";
-        } else if (showRevisions) {
-            msg = "Revisions";
-        }
-        return msg;
-    }
-
     private void determineBundleLevelThreshold() {
         final String sbslProp = bundleContext.getProperty("karaf.systemBundlesStartLevel");
         if (sbslProp != null) {
@@ -149,26 +177,4 @@ public class ListBundles extends OsgiCommandSupport {
         return (state == null) ? "" : state.toString();
     }
 
-    /**
-     * Overwrite the default value is the user specifically requested to display
-     * one or the other.
-     * 
-     * @param info
-     * @return
-     */
-    private String getNameToShow(BundleInfo info) {
-        if (showLoc) {
-            return info.getUpdateLocation();
-        } else if (showSymbolic) {
-            return info.getSymbolicName() == null ? "<no symbolic name>" : info.getSymbolicName();
-        } else if (showUpdate) {
-            return info.getUpdateLocation();
-        } else if (showRevisions) {
-            return info.getRevisions();
-        } else {
-            String name = (info.getName() == null) ? info.getSymbolicName() : info.getName();
-            return (name == null) ? info.getUpdateLocation() : name;
-        }
-    }
-
 }

http://git-wip-us.apache.org/repos/asf/karaf/blob/184d37fb/shell/table/src/main/java/org/apache/karaf/shell/table/Row.java
----------------------------------------------------------------------
diff --git a/shell/table/src/main/java/org/apache/karaf/shell/table/Row.java b/shell/table/src/main/java/org/apache/karaf/shell/table/Row.java
index 384bc9c..be48497 100644
--- a/shell/table/src/main/java/org/apache/karaf/shell/table/Row.java
+++ b/shell/table/src/main/java/org/apache/karaf/shell/table/Row.java
@@ -38,6 +38,10 @@ public class Row {
     public void addContent(Object ... cellDataAr) {
         data.addAll(Arrays.asList(cellDataAr));
     }
+
+    public void addContent(List<Object> data) {
+        this.data = data;
+    }
     
     void formatContent(List<Col> cols) {
         content.clear();


Mime
View raw message