Add support for parameter aliases. (FELIX-2363)
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@948941 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/gogo/command/src/main/java/org/apache/felix/gogo/command/Basic.java b/gogo/command/src/main/java/org/apache/felix/gogo/command/Basic.java
index 16d2659..ab1b72f 100644
--- a/gogo/command/src/main/java/org/apache/felix/gogo/command/Basic.java
+++ b/gogo/command/src/main/java/org/apache/felix/gogo/command/Basic.java
@@ -88,9 +88,9 @@
@Descriptor("set bundle start level or initial bundle start level")
public void bundlelevel(
- @Parameter(name="-s", description="set the specified bundle's start level",
+ @Parameter(names={ "-s", "--setlevel" }, description="set the bundle's start level",
presentValue="true", absentValue="false") boolean set,
- @Parameter(name="-i", description="set the initial bundle start level",
+ @Parameter(names={ "-i", "--setinitial" }, description="set the initial bundle start level",
presentValue="true", absentValue="false") boolean initial,
@Descriptor("target level") int level,
@Descriptor("target identifiers") Bundle[] bundles)
@@ -276,11 +276,11 @@
Parameter p = (Parameter) ann;
if (p.presentValue().equals(Parameter.UNSPECIFIED))
{
- options.put(p.name(), p);
+ options.put(p.names()[0], p);
}
else
{
- flags.put(p.name(), p);
+ flags.put(p.names()[0], p);
}
found = true;
}
@@ -304,10 +304,14 @@
System.out.println(" flags:");
for (Entry<String, Parameter> entry : flags.entrySet())
{
- System.out.println(" "
- + entry.getValue().name()
- + " "
- + entry.getValue().description());
+ // Print all aliases.
+ String[] names = entry.getValue().names();
+ System.out.print(" " + names[0]);
+ for (int aliasIdx = 1; aliasIdx < names.length; aliasIdx++)
+ {
+ System.out.print(", " + names[aliasIdx]);
+ }
+ System.out.println(" " + entry.getValue().description());
}
}
if (options.size() > 0)
@@ -315,9 +319,14 @@
System.out.println(" options:");
for (Entry<String, Parameter> entry : options.entrySet())
{
- System.out.println(" "
- + entry.getValue().name()
- + " "
+ // Print all aliases.
+ String[] names = entry.getValue().names();
+ System.out.print(" " + names[0]);
+ for (int aliasIdx = 1; aliasIdx < names.length; aliasIdx++)
+ {
+ System.out.print(", " + names[aliasIdx]);
+ }
+ System.out.println(" "
+ entry.getValue().description()
+ ((entry.getValue().absentValue() == null) ? "" : " [optional]"));
}
@@ -452,11 +461,11 @@
@Descriptor("list all installed bundles")
public void lb(
- @Parameter(name="-l", description="show location",
+ @Parameter(names={ "-l", "--location" }, description="show location",
presentValue="true", absentValue="false") boolean showLoc,
- @Parameter(name="-s", description="show symbolic name",
+ @Parameter(names={ "-s", "--symbolicname" }, description="show symbolic name",
presentValue="true", absentValue="false") boolean showSymbolic,
- @Parameter(name="-u", description="show update location",
+ @Parameter(names={ "-u", "--updatelocation" }, description="show update location",
presentValue="true", absentValue="false") boolean showUpdate)
{
lb(showLoc, showSymbolic, showUpdate, null);
@@ -464,11 +473,11 @@
@Descriptor("list installed bundles matching a substring")
public void lb(
- @Parameter(name="-l", description="show location",
+ @Parameter(names={ "-l", "--location" }, description="show location",
presentValue="true", absentValue="false") boolean showLoc,
- @Parameter(name="-s", description="show symbolic name",
+ @Parameter(names={ "-s", "--symbolicname" }, description="show symbolic name",
presentValue="true", absentValue="false") boolean showSymbolic,
- @Parameter(name="-u", description="show update location",
+ @Parameter(names={ "-u", "--updatelocation" }, description="show update location",
presentValue="true", absentValue="false") boolean showUpdate,
@Descriptor("subtring matched against name or symbolic name") String pattern)
{
@@ -676,9 +685,9 @@
@Descriptor("start bundles")
public void start(
- @Parameter(name="-t", description="transient",
+ @Parameter(names={ "-t", "--transient" }, description="start bundle transiently",
presentValue="true", absentValue="false") boolean trans,
- @Parameter(name="-p", description="use declared activation policy",
+ @Parameter(names={ "-p", "--policy" }, description="use declared activation policy",
presentValue="true", absentValue="false") boolean policy,
@Descriptor("target bundle identifiers or URLs") String[] ss)
{
@@ -757,7 +766,7 @@
@Descriptor("stop bundles")
public void stop(
- @Parameter(name="-t", description="transient",
+ @Parameter(names={ "-t", "--transient" }, description="stop bundle transiently",
presentValue="true", absentValue="false") boolean trans,
@Descriptor("target bundles") Bundle[] bundles)
{
@@ -1073,36 +1082,4 @@
return "Unknown ";
}
}
-
- private static Bundle getBundle(BundleContext bc, Long id)
- {
- Bundle bundle = bc.getBundle(id);
- if (bundle == null)
- {
- System.err.println("Bundle ID " + id + " is invalid");
- }
- return bundle;
- }
-
- private static List<Bundle> getBundles(BundleContext bc, Long[] ids)
- {
- List<Bundle> bundles = new ArrayList<Bundle>();
- if ((ids != null) && (ids.length > 0))
- {
- for (long id : ids)
- {
- Bundle bundle = getBundle(bc, id);
- if (bundle != null)
- {
- bundles.add(bundle);
- }
- }
- }
- else
- {
- bundles = null;
- }
-
- return bundles;
- }
}
\ No newline at end of file
diff --git a/gogo/command/src/main/java/org/apache/felix/gogo/command/OBR.java b/gogo/command/src/main/java/org/apache/felix/gogo/command/OBR.java
index 8fc52db..2fd208c 100644
--- a/gogo/command/src/main/java/org/apache/felix/gogo/command/OBR.java
+++ b/gogo/command/src/main/java/org/apache/felix/gogo/command/OBR.java
@@ -133,7 +133,7 @@
@Descriptor("list repository resources")
public void list(
- @Parameter(name="-v", description="verbose",
+ @Parameter(names={ "-v", "--verbose" }, description="verbose",
presentValue="true", absentValue="false") boolean verbose,
@Descriptor("optional strings used for name matching") String[] args)
throws IOException, InvalidSyntaxException
@@ -291,7 +291,7 @@
@Descriptor("deploy resource from repository")
public void deploy(
- @Parameter(name="-s", description="start deployed bundles",
+ @Parameter(names={ "-s", "--start" }, description="start deployed bundles",
presentValue="true", absentValue="false") boolean start,
@Descriptor("( <bundle-name> | <symbolic-name> | <bundle-id> )[@<version>] ...")
String[] args)
@@ -398,7 +398,7 @@
@Descriptor("retrieve resource source code from repository")
public void source(
- @Parameter(name="-x", description="extract",
+ @Parameter(names={ "-x", "--extract" }, description="extract",
presentValue="true", absentValue="false") boolean extract,
@Descriptor("local target directory") File localDir,
@Descriptor("( <bundle-name> | <symbolic-name> | <bundle-id> )[@<version>] ...")
@@ -448,7 +448,7 @@
@Descriptor("retrieve resource JavaDoc from repository")
public void javadoc(
- @Parameter(name="-x", description="extract",
+ @Parameter(names={"-x", "--extract" }, description="extract",
presentValue="true", absentValue="false") boolean extract,
@Descriptor("local target directory") File localDir,
@Descriptor("( <bundle-name> | <symbolic-name> | <bundle-id> )[@<version>] ...")
diff --git a/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/Reflective.java b/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/Reflective.java
index 61d9575..9f86804 100644
--- a/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/Reflective.java
+++ b/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/Reflective.java
@@ -227,8 +227,7 @@
Object item = itArgs.next();
if (item instanceof String)
{
- String option = (String) item;
- if (option.startsWith("-"))
+ if (((String) item).startsWith("-"))
{
for (int argIndex = 0; argIndex < pas.length; argIndex++)
{
@@ -237,21 +236,28 @@
{
if (as[a] instanceof Parameter)
{
- Parameter o = (Parameter) as[a];
- if (o.name().equals(option) && o.presentValue() == null)
+ Parameter param = (Parameter) as[a];
+ for (String name : param.names())
{
- itArgs.remove();
- assert itArgs.hasNext();
- Object value = itArgs.next();
- itArgs.remove();
- out[argIndex] = coerce(session, target,
- types[argIndex], value);
- }
- else if (o.name().equals(option) && o.presentValue() != null)
- {
- itArgs.remove();
- out[argIndex] = coerce(session, target,
- types[argIndex], o.presentValue());
+ if (name.equals(item))
+ {
+ if (param.presentValue() == null)
+ {
+ itArgs.remove();
+ assert itArgs.hasNext();
+ Object value = itArgs.next();
+ itArgs.remove();
+ out[argIndex] = coerce(session, target,
+ types[argIndex], value);
+ }
+ else if (param.presentValue() != null)
+ {
+ itArgs.remove();
+ out[argIndex] = coerce(session, target,
+ types[argIndex], param.presentValue());
+ }
+ break;
+ }
}
}
}
diff --git a/gogo/runtime/src/main/java/org/osgi/service/command/Parameter.java b/gogo/runtime/src/main/java/org/osgi/service/command/Parameter.java
index 13239c0..d9dc63c 100644
--- a/gogo/runtime/src/main/java/org/osgi/service/command/Parameter.java
+++ b/gogo/runtime/src/main/java/org/osgi/service/command/Parameter.java
@@ -30,10 +30,10 @@
static final String UNSPECIFIED = "org.osgi.service.command.unspecified.parameter";
/**
- * Parameter name, which must start with the hyphen character.
- * @return parameter name.
+ * Parameter name and aliases which must start with the hyphen character.
+ * @return parameter names.
**/
- String name();
+ String[] names();
/**
* Optional parameter description.