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 11:57:19 GMT
Repository: karaf
Updated Branches:
  refs/heads/karaf-4.0.x 57ed8c837 -> f98bfd67b


[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/f98bfd67
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/f98bfd67
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/f98bfd67

Branch: refs/heads/karaf-4.0.x
Commit: f98bfd67b9046cbf56bd4abf7c494c9056b3ca7b
Parents: 57ed8c8
Author: Jean-Baptiste Onofré <jbonofre@apache.org>
Authored: Mon Jun 6 13:36:36 2016 +0200
Committer: Jean-Baptiste Onofré <jbonofre@apache.org>
Committed: Mon Jun 6 13:38:01 2016 +0200

----------------------------------------------------------------------
 .../org/apache/karaf/bundle/command/List.java   | 122 ++++++++++---------
 .../apache/karaf/shell/support/table/Row.java   |   4 +
 2 files changed, 69 insertions(+), 57 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/f98bfd67/bundle/core/src/main/java/org/apache/karaf/bundle/command/List.java
----------------------------------------------------------------------
diff --git a/bundle/core/src/main/java/org/apache/karaf/bundle/command/List.java b/bundle/core/src/main/java/org/apache/karaf/bundle/command/List.java
index 8a5c69d..000d3bd 100644
--- a/bundle/core/src/main/java/org/apache/karaf/bundle/command/List.java
+++ b/bundle/core/src/main/java/org/apache/karaf/bundle/command/List.java
@@ -25,15 +25,21 @@ 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.Col;
+import org.apache.karaf.shell.support.table.Row;
 import org.apache.karaf.shell.support.table.ShellTable;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.startlevel.FrameworkStartLevel;
 
+import java.util.ArrayList;
+
 @Command(scope = "bundle", name = "list", description = "Lists all installed bundles.")
 @Service
 public class List extends BundlesCommand {
 
+    @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 showLocation;
 
@@ -90,55 +96,79 @@ public class List extends BundlesCommand {
         table.column("State");
         table.column("Lvl").alignRight();
         table.column("Version");
-        table.column(new Col(getNameHeader()) {
-            @Override
-            protected String cut(String value, int size) {
-                if (showLocation && value.length() > size) {
-                    String[] parts = value.split("/");
-                    String cut = "";
-                    int c = parts[0].length() + 4;
-                    for (int idx = parts.length - 1; idx > 0; idx--) {
-                        if (cut.length() + c + parts[idx].length() + 1 < size) {
-                            cut = "/" + parts[idx] + cut;
-                        } else {
-                            break;
+
+        if (!dontShowName) {
+            table.column("Name");
+        }
+
+        if (showLocation) {
+            table.column(new Col("Location") {
+                @Override
+                protected String cut(String value, int size) {
+                    if (showLocation && value.length() > size) {
+                        String[] parts = value.split("/");
+                        String cut = "";
+                        int c = parts[0].length() + 4;
+                        for (int idx = parts.length - 1; idx > 0; idx--) {
+                            if (cut.length() + c + parts[idx].length() + 1 < size) {
+                                cut = "/" + parts[idx] + cut;
+                            } else {
+                                break;
+                            }
                         }
+                        cut = parts[0] + "/..." + cut;
+                        return cut;
+                    } else {
+                        return super.cut(value, size);
                     }
-                    cut = parts[0] + "/..." + cut;
-                    return cut;
-                } else {
-                    return super.cut(value, size);
                 }
-            }
-        });
+            });
+        }
+        if (showSymbolic) {
+            table.column("Symbolic name");
+        }
+        if (showUpdate) {
+            table.column("Update location");
+        }
+        if (showRevisions) {
+            table.column("Revisions");
+        }
 
         for (Bundle bundle : bundles) {
             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<>();
+                rowData.add(info.getBundleId());
+                rowData.add(getStateString(info.getState()));
+                rowData.add(info.getStartLevel());
+                rowData.add(version);
+                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 (showLocation) {
+                    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);
         return null;
     }
 
-    private String getNameHeader() {
-        String msg = "Name";
-        if (showLocation) {
-            msg = "Location";
-        } else if (showSymbolic) {
-            msg = "Symbolic name";
-        } else if (showUpdate) {
-            msg = "Update location";
-        } else if (showRevisions) {
-            msg = "Revisions";
-        }
-        return msg;
-    }
-
     private void determineBundleLevelThreshold() {
         if (bundleLevelThreshold < 0) {
             bundleLevelThreshold = bundleService.getSystemBundleThreshold();
@@ -177,26 +207,4 @@ public class List extends BundlesCommand {
         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 (showLocation) {
-            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/f98bfd67/shell/core/src/main/java/org/apache/karaf/shell/support/table/Row.java
----------------------------------------------------------------------
diff --git a/shell/core/src/main/java/org/apache/karaf/shell/support/table/Row.java b/shell/core/src/main/java/org/apache/karaf/shell/support/table/Row.java
index 4c07f5b..4a27cec 100644
--- a/shell/core/src/main/java/org/apache/karaf/shell/support/table/Row.java
+++ b/shell/core/src/main/java/org/apache/karaf/shell/support/table/Row.java
@@ -35,6 +35,10 @@ public class Row {
         }
     }
 
+    public void addContent(List<Object> data) {
+        this.data = data;
+    }
+
     public void addContent(Object ... cellDataAr) {
         data.addAll(Arrays.asList(cellDataAr));
     }


Mime
View raw message