FELIX-5001 : scr:list Gogo command should display component configurations
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1695222 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/scr/src/main/java/org/apache/felix/scr/impl/ScrCommand.java b/scr/src/main/java/org/apache/felix/scr/impl/ScrCommand.java
index 1db0ef7..8a90ea0 100644
--- a/scr/src/main/java/org/apache/felix/scr/impl/ScrCommand.java
+++ b/scr/src/main/java/org/apache/felix/scr/impl/ScrCommand.java
@@ -33,8 +33,8 @@
import java.util.TreeMap;
import java.util.regex.Pattern;
-import org.apache.felix.scr.info.ScrInfo;
import org.apache.felix.scr.impl.config.ScrConfiguration;
+import org.apache.felix.scr.info.ScrInfo;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
@@ -59,7 +59,7 @@
private final BundleContext bundleContext;
private final ServiceComponentRuntime scrService;
private final ScrConfiguration scrConfiguration;
-
+
private ServiceRegistration<ScrInfo> reg;
private ServiceRegistration<?> gogoReg;
private ServiceRegistration<?> shellReg;
@@ -147,7 +147,7 @@
// ---------- Actual implementation
-
+
public void update( boolean infoAsService )
{
if (infoAsService)
@@ -169,26 +169,26 @@
}
}
}
-
+
/* (non-Javadoc)
* @see org.apache.felix.scr.impl.ScrInfo#list(java.lang.String, java.io.PrintStream, java.io.PrintStream)
*/
public void list(final String bundleIdentifier, final PrintWriter out)
{
- List<ComponentDescriptionDTO> components;
+ List<ComponentConfigurationDTO> components;
if (bundleIdentifier != null)
{
Bundle bundle = null;
try
{
- long bundleId = Long.parseLong(bundleIdentifier);
+ final long bundleId = Long.parseLong(bundleIdentifier);
bundle = bundleContext.getBundle(bundleId);
}
- catch (NumberFormatException nfe)
+ catch (final NumberFormatException nfe)
{
// might be a bundle symbolic name
- Bundle[] bundles = bundleContext.getBundles();
+ final Bundle[] bundles = bundleContext.getBundles();
for (int i = 0; i < bundles.length; i++)
{
if (bundleIdentifier.equals(bundles[i].getSymbolicName()))
@@ -205,7 +205,11 @@
}
if (ComponentRegistry.isBundleActive(bundle))
{
- components = new ArrayList<ComponentDescriptionDTO>(scrService.getComponentDescriptionDTOs(bundle));
+ components = new ArrayList<ComponentConfigurationDTO>();
+ for(final ComponentDescriptionDTO cmp : scrService.getComponentDescriptionDTOs(bundle))
+ {
+ components.addAll(scrService.getComponentConfigurationDTOs(cmp));
+ }
if (components.isEmpty())
{
out.println("Bundle " + bundleIdentifier + " declares no components");
@@ -220,7 +224,11 @@
}
else
{
- components = new ArrayList<ComponentDescriptionDTO>(scrService.getComponentDescriptionDTOs());
+ components = new ArrayList<ComponentConfigurationDTO>();
+ for(final ComponentDescriptionDTO cmp : scrService.getComponentDescriptionDTOs())
+ {
+ components.addAll(scrService.getComponentConfigurationDTOs(cmp));
+ }
if (components.isEmpty())
{
out.println("No components registered");
@@ -228,42 +236,42 @@
}
}
- Collections.sort( components, new Comparator<ComponentDescriptionDTO>()
+ Collections.sort( components, new Comparator<ComponentConfigurationDTO>()
{
- public int compare(ComponentDescriptionDTO c1, ComponentDescriptionDTO c2)
+ public int compare(final ComponentConfigurationDTO c1, final ComponentConfigurationDTO c2)
{
- return c1.name.compareTo(c2.name);
+ return Long.signum(c1.id - c2.id);
}
});
- out.println(" Name BundleId DefaultEnabled");
- for ( ComponentDescriptionDTO component : components )
+ out.println(" Id State BundleId Name");
+ for ( final ComponentConfigurationDTO component : components )
{
- out.println( String.format( "[%1$s] [%2$4d] [%3$b]", component.name, component.bundle.id, component.defaultEnabled ) );
+ out.println( String.format( "[%1$4d] [%2$s] [%3$4d] %4$s", component.id, toStateString( component.state ), component.description.bundle.id, component.description.name ) );
}
out.flush();
}
- /* (non-Javadoc)
+ /**
* @see org.apache.felix.scr.impl.ScrInfo#info(java.lang.String, java.io.PrintStream, java.io.PrintStream)
*/
- public void info(final String componentId, PrintWriter out)
+ public void info(final String componentId, final PrintWriter out)
{
- Collection<ComponentDescriptionDTO> components = getComponentFromArg(componentId);
- if (components == null)
+ final Result result = getComponentsFromArg(componentId, false);
+ if (result.components.isEmpty())
{
return;
}
- Collections.sort( new ArrayList<ComponentDescriptionDTO>(components), new Comparator<ComponentDescriptionDTO>()
+ Collections.sort( new ArrayList<ComponentDescriptionDTO>(result.components), new Comparator<ComponentDescriptionDTO>()
{
- public int compare(ComponentDescriptionDTO c1, ComponentDescriptionDTO c2)
+ public int compare(final ComponentDescriptionDTO c1, final ComponentDescriptionDTO c2)
{
- long bundleId1 = c1.bundle.id;
- long bundleId2 = c2.bundle.id;
+ final long bundleId1 = c1.bundle.id;
+ final long bundleId2 = c2.bundle.id;
int result = Long.signum(bundleId1 - bundleId2);
if ( result == 0)
{
@@ -276,7 +284,7 @@
long bundleId = -1;
- for ( ComponentDescriptionDTO component : components )
+ for ( ComponentDescriptionDTO component : result.components )
{
if ( component.bundle.id != bundleId )
{
@@ -367,9 +375,16 @@
Map<String, Object> props = component.properties;
propertyInfo(props, out, "");
- for (ComponentConfigurationDTO cc: scrService.getComponentConfigurationDTOs(component))
+ if ( result.configuration != null )
{
- info(cc, out);
+ info(result.configuration, out);
+ }
+ else
+ {
+ for (final ComponentConfigurationDTO cc: scrService.getComponentConfigurationDTOs(component))
+ {
+ info(cc, out);
+ }
}
}
@@ -468,16 +483,11 @@
propertyInfo( cc.properties, out, " ");
}
- void change(final String componentIdentifier, PrintWriter out, boolean enable)
+ void change(final String componentIdentifier, final PrintWriter out, final boolean enable)
{
- Collection<ComponentDescriptionDTO> components = getComponentFromArg(componentIdentifier);
- ArrayList<String> disposed = new ArrayList<String>();
- if (components == null)
- {
- return;
- }
+ final Result result = getComponentsFromArg(componentIdentifier, true);
- for ( ComponentDescriptionDTO component : components )
+ for ( final ComponentDescriptionDTO component : result.components )
{
if ( enable )
{
@@ -505,17 +515,12 @@
}
}
out.flush();
- if ( !disposed.isEmpty() )
- {
- throw new IllegalArgumentException( "Components " + disposed + " already disposed, cannot change state" );
-
- }
}
- /* (non-Javadoc)
+ /**
* @see org.apache.felix.scr.impl.ScrInfo#config(java.io.PrintStream)
*/
- public void config(PrintWriter out)
+ public void config(final PrintWriter out)
{
out.print("Log Level: ");
out.println(scrConfiguration.getLogLevel());
@@ -531,45 +536,75 @@
out.println(scrConfiguration.globalExtender());
out.print("Info Service registered: ");
out.println(scrConfiguration.infoAsService() ? "Supported" : "Unsupported");
+ out.flush();
}
- private String toStateString(int state)
+ private String toStateString(final int state)
{
- switch (state) {
+ switch (state)
+ {
case (ComponentConfigurationDTO.UNSATISFIED_REFERENCE):
return "unsatisfied reference";
case (ComponentConfigurationDTO.ACTIVE):
return "active ";
case (ComponentConfigurationDTO.SATISFIED):
- return "satisfied ";
+ return "satisfied ";
+ case (ComponentConfigurationDTO.UNSATISFIED_CONFIGURATION):
+ return "unsatisfied config";
default:
return "unkown: " + state;
}
}
- private Collection<ComponentDescriptionDTO> getComponentFromArg(final String componentIdentifier)
+ private static final class Result {
+ public Collection<ComponentDescriptionDTO> components = new ArrayList<ComponentDescriptionDTO>();
+ public ComponentConfigurationDTO configuration;
+ }
+
+ private Result getComponentsFromArg(final String componentIdentifier, final boolean nameMatch)
{
- Collection<ComponentDescriptionDTO> components = scrService.getComponentDescriptionDTOs();
- if (componentIdentifier != null)
+ final Pattern p = (componentIdentifier == null ? null : Pattern.compile(componentIdentifier));
+ final Result result = new Result();
+
+ for(final ComponentDescriptionDTO cmp : scrService.getComponentDescriptionDTOs())
{
- ArrayList<ComponentDescriptionDTO> cs = new ArrayList<ComponentDescriptionDTO>(components.size());
- Pattern p = Pattern.compile(componentIdentifier);
- for (ComponentDescriptionDTO component: components)
+ if (componentIdentifier != null)
{
- if ( p.matcher( component.name).matches() )
+ if ( p.matcher(cmp.name).matches() )
{
- cs.add( component );
+ result.components.add(cmp);
+ }
+ else if ( !nameMatch )
+ {
+ boolean done = false;
+ for (final ComponentConfigurationDTO cfg: scrService.getComponentConfigurationDTOs(cmp))
+ {
+ if ( p.matcher( String.valueOf( cfg.id )).matches() )
+ {
+ result.components.add( cmp );
+ result.configuration = cfg;
+ done = true;
+ break;
+ }
+ }
+ if ( done )
+ {
+ break;
+ }
}
}
- if (cs.isEmpty())
+ else
{
- throw new IllegalArgumentException("No Component with ID or matching " + componentIdentifier);
+ result.components.add(cmp);
}
- components = cs;
+ }
+ if (componentIdentifier != null && result.components.isEmpty())
+ {
+ throw new IllegalArgumentException("No Component with name or configuration with ID matching " + componentIdentifier);
}
- return components;
+ return result;
}
}
diff --git a/scr/src/main/java/org/apache/felix/scr/impl/ScrGogoCommand.java b/scr/src/main/java/org/apache/felix/scr/impl/ScrGogoCommand.java
index 3a12e87..9ecb1f7 100644
--- a/scr/src/main/java/org/apache/felix/scr/impl/ScrGogoCommand.java
+++ b/scr/src/main/java/org/apache/felix/scr/impl/ScrGogoCommand.java
@@ -56,7 +56,7 @@
this.scrCommand = scrCommand;
}
- @Descriptor("List all components")
+ @Descriptor("List all component configurations")
public void list()
{
try
@@ -69,7 +69,7 @@
}
}
- @Descriptor("List components of a specific bundle")
+ @Descriptor("List component configurations of a specific bundle")
public void list(@Descriptor("Symbolic name or ID of the bundle") final String bundleIdentifier)
{
try
@@ -82,8 +82,8 @@
}
}
- @Descriptor("Dump information of a component")
- public void info(@Descriptor("Name or ID of the component") final String componentIdentifier)
+ @Descriptor("Dump information of a component or component configuration")
+ public void info(@Descriptor("Name of the component or ID of the component configuration") final String componentIdentifier)
{
try
{
@@ -96,7 +96,7 @@
}
@Descriptor("Enable a disabled component")
- public void enable(@Descriptor("Name or ID of the component") final String componentIdentifier)
+ public void enable(@Descriptor("Name of the component") final String componentIdentifier)
{
try
{
@@ -109,7 +109,7 @@
}
@Descriptor("Disable an enabled component")
- public void disable(@Descriptor("Name or ID of the component") final String componentIdentifier)
+ public void disable(@Descriptor("Name of the component") final String componentIdentifier)
{
try
{
diff --git a/scr/src/main/java/org/apache/felix/scr/impl/ScrShellCommand.java b/scr/src/main/java/org/apache/felix/scr/impl/ScrShellCommand.java
index 4ee0071..a2e2807 100644
--- a/scr/src/main/java/org/apache/felix/scr/impl/ScrShellCommand.java
+++ b/scr/src/main/java/org/apache/felix/scr/impl/ScrShellCommand.java
@@ -118,8 +118,8 @@
out.println("");
out.println("scr " + LIST_CMD + " [ <bundleId> ]");
out.println("");
- out.println("This command lists registered components. If a bundle ID is\n"
- + "added, only the components of the selected bundles are listed.");
+ out.println("This command lists registered component configurations. If a bundle ID is\n"
+ + "added, only the component configurations of the selected bundles are listed.");
out.println("");
}
else if (INFO_CMD.equals( command ))
@@ -128,23 +128,23 @@
out.println("scr " + INFO_CMD + " <componentId>");
out.println("");
out.println("This command dumps information of the component whose\n"
- + "component ID is given as command argument.");
+ + "component name or component configuration ID is given as command argument.");
out.println("");
}
else if (ENABLE_CMD.equals( command ))
{
out.println("");
- out.println("scr " + ENABLE_CMD + " <componentId>");
+ out.println("scr " + ENABLE_CMD + " <componentName>");
out.println("");
- out.println("This command enables the component whose component ID\n" + "is given as command argument.");
+ out.println("This command enables the component whose component name\n" + "is given as command argument.");
out.println("");
}
else if (DISABLE_CMD.equals( command ))
{
out.println("");
- out.println("scr " + DISABLE_CMD + " <componentId>");
+ out.println("scr " + DISABLE_CMD + " <componentName>");
out.println("");
- out.println("This command disables the component whose component ID\n" + "is given as command argument.");
+ out.println("This command disables the component whose component name\n" + "is given as command argument.");
out.println("");
}
else if (CONFIG_CMD.equals( command ))
@@ -160,8 +160,8 @@
out.println("scr " + HELP_CMD + " [" + LIST_CMD + "]");
out.println("scr " + LIST_CMD + " [ <bundleId> ]");
out.println("scr " + INFO_CMD + " <componentId>");
- out.println("scr " + ENABLE_CMD + " <componentId>");
- out.println("scr " + DISABLE_CMD + " <componentId>");
+ out.println("scr " + ENABLE_CMD + " <componentName>");
+ out.println("scr " + DISABLE_CMD + " <componentName>");
out.println("scr " + CONFIG_CMD);
}
}