Modified 'ps' so that it displays reasonable defaults if headers are missing.
Also added ability to display symbolic name.
git-svn-id: https://svn.apache.org/repos/asf/incubator/felix/trunk@534862 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/shell/src/main/java/org/apache/felix/shell/impl/PsCommandImpl.java b/shell/src/main/java/org/apache/felix/shell/impl/PsCommandImpl.java
index 0be3219..43e424c 100644
--- a/shell/src/main/java/org/apache/felix/shell/impl/PsCommandImpl.java
+++ b/shell/src/main/java/org/apache/felix/shell/impl/PsCommandImpl.java
@@ -42,7 +42,7 @@
public String getUsage()
{
- return "ps [-l | -u]";
+ return "ps [-l | -s | -u]";
}
public String getShortDescription()
@@ -74,6 +74,7 @@
// Check for optional argument.
boolean showLoc = false;
+ boolean showSymbolic = false;
boolean showUpdate = false;
if (st.countTokens() >= 1)
{
@@ -84,6 +85,10 @@
{
showLoc = true;
}
+ else if (token.equals("-s"))
+ {
+ showSymbolic = true;
+ }
else if (token.equals("-u"))
{
showUpdate = true;
@@ -105,6 +110,10 @@
{
msg = " Location";
}
+ else if (showSymbolic)
+ {
+ msg = " Symbolic name";
+ }
else if (showUpdate)
{
msg = " Update location";
@@ -116,18 +125,29 @@
// Get the bundle name or location.
String name = (String)
bundles[i].getHeaders().get(Constants.BUNDLE_NAME);
+ // If there is no name, then default to symbolic name.
+ name = (name == null) ? bundles[i].getSymbolicName() : name;
+ // If there is no symbolic name, resort to location.
+ name = (name == null) ? bundles[i].getLocation() : name;
+
+ // Overwrite the default value is the user specifically
+ // requested to display one or the other.
if (showLoc)
{
name = bundles[i].getLocation();
}
+ else if (showSymbolic)
+ {
+ name = bundles[i].getSymbolicName();
+ name = (name == null)
+ ? "<no symbolic name>" : name;
+ }
else if (showUpdate)
{
- Dictionary dict = bundles[i].getHeaders();
- name = (String) dict.get(Constants.BUNDLE_UPDATELOCATION);
- if (name == null)
- {
- name = bundles[i].getLocation();
- }
+ name = (String)
+ bundles[i].getHeaders().get(Constants.BUNDLE_UPDATELOCATION);
+ name = (name == null)
+ ? bundles[i].getLocation() : name;
}
// Show bundle version if not showing location.
String version = (String)