use of org.osgi.service.component.runtime.dto.ComponentConfigurationDTO in project felix by apache.
the class ComponentFieldActivationTest method test_field_activator_failure.
@Test
public void test_field_activator_failure() throws Exception {
final String componentname = "FieldActivatorComponent.unsatisfied";
ComponentConfigurationDTO cc = getDisabledConfigurationAndEnable(componentname, ComponentConfigurationDTO.SATISFIED);
assertEquals(1, cc.description.activationFields.length);
assertTrue(Arrays.asList(cc.description.activationFields).contains("foo"));
// we get the component, although the field does not exist!
FieldActivatorComponent cmp = this.getServiceFromConfiguration(cc, FieldActivatorComponent.class);
assertTrue(cmp.isActivateCalled());
assertTrue(cmp.setBeforeActivate().isEmpty());
assertEquals(4, cmp.notSetBeforeActivate().size());
assertNull(cmp.additionalError());
disableAndCheck(cc);
}
use of org.osgi.service.component.runtime.dto.ComponentConfigurationDTO in project felix by apache.
the class ComponentCommands method format.
CharSequence format(ComponentDescriptionDTO dto, int level) throws Exception {
final StringBuilder builder = new StringBuilder();
// Get the child ComponentConfigurationDTOs and sort by id field.
final List<ComponentConfigurationDTO> children;
Collection<ComponentConfigurationDTO> childrenTmp = scr.getComponentConfigurationDTOs(dto);
if (childrenTmp == null) {
children = Collections.emptyList();
} else {
children = new ArrayList<>(childrenTmp);
Collections.sort(children, configDtoComparator);
}
switch(level) {
case Converter.LINE:
builder.append(MessageFormat.format("{0} in bundle {1} ({2}:{3}) {4}, {5,choice,0#0 instances|1#1 instance|1<{5} instances}.", dto.name, dto.bundle.id, dto.bundle.symbolicName, dto.bundle.version, dto.defaultEnabled ? "enabled" : "disabled", children.size()));
for (ComponentConfigurationDTO child : children) builder.append("\n").append(INDENT_2).append(format(child, Converter.LINE));
break;
case Converter.INSPECT:
printComponentDescriptionAndConfigs(dto, children.toArray(new ComponentConfigurationDTO[0]), builder);
break;
case Converter.PART:
break;
}
return builder;
}
use of org.osgi.service.component.runtime.dto.ComponentConfigurationDTO in project felix by apache.
the class ComponentConfigurationPrinter method printComponentsJson.
private final void printComponentsJson(final PrintWriter pw, final List<ComponentDescriptionDTO> disabled, final List<ComponentConfigurationDTO> configurations, final boolean details) throws IOException {
final JSONWriter jw = new JSONWriter(pw);
jw.object();
// $NON-NLS-1$
jw.key("components");
jw.array();
// render disabled descriptions
for (final ComponentDescriptionDTO cd : disabled) {
plugin.component(jw, cd, null, details);
}
// render configurations
for (final ComponentConfigurationDTO cfg : configurations) {
plugin.component(jw, cfg.description, cfg, details);
}
jw.endArray();
jw.endObject();
}
use of org.osgi.service.component.runtime.dto.ComponentConfigurationDTO in project felix by apache.
the class ComponentConfigurationPrinter method printComponentsText.
private static final void printComponentsText(final PrintWriter pw, final List<ComponentDescriptionDTO> disabled, final List<ComponentDescriptionDTO> noConfig, final List<ComponentConfigurationDTO> configurations) {
if (!disabled.isEmpty()) {
pw.println(SEP);
pw.println("Disabled components:");
pw.println(SEP);
for (final ComponentDescriptionDTO cd : disabled) {
disabledComponent(pw, cd);
}
pw.println();
}
if (!noConfig.isEmpty()) {
pw.println(SEP);
pw.println("Components with missing configuration in Config Admin:");
pw.println(SEP);
for (final ComponentDescriptionDTO cd : noConfig) {
disabledComponent(pw, cd);
}
pw.println();
}
pw.println(SEP);
if (configurations.isEmpty()) {
pw.println("Status: No Component Configurations");
pw.println(SEP);
} else {
pw.println("Component Configurations:");
pw.println(SEP);
// order components by id
TreeMap<Long, ComponentConfigurationDTO> componentMap = new TreeMap<Long, ComponentConfigurationDTO>();
for (final ComponentConfigurationDTO cfg : configurations) {
componentMap.put(new Long(cfg.id), cfg);
}
// render components
for (final ComponentConfigurationDTO cfg : componentMap.values()) {
component(pw, cfg);
}
}
}
use of org.osgi.service.component.runtime.dto.ComponentConfigurationDTO in project felix by apache.
the class ComponentConfigurationPrinter method print.
/**
* @see org.apache.felix.inventory.InventoryPrinter#print(java.io.PrintWriter, org.apache.felix.inventory.Format, boolean)
*/
public void print(PrintWriter pw, Format format, boolean isZip) {
final List<ComponentDescriptionDTO> noConfig = new ArrayList<ComponentDescriptionDTO>();
final List<ComponentDescriptionDTO> disabled = new ArrayList<ComponentDescriptionDTO>();
final List<ComponentConfigurationDTO> configurations = new ArrayList<ComponentConfigurationDTO>();
final Collection<ComponentDescriptionDTO> descs = scrService.getComponentDescriptionDTOs();
for (final ComponentDescriptionDTO d : descs) {
if (!scrService.isComponentEnabled(d)) {
disabled.add(d);
} else {
final Collection<ComponentConfigurationDTO> configs = scrService.getComponentConfigurationDTOs(d);
if (configs.isEmpty()) {
noConfig.add(d);
} else {
configurations.addAll(configs);
}
}
}
Collections.sort(configurations, Util.COMPONENT_COMPARATOR);
if (Format.JSON.equals(format)) {
disabled.addAll(noConfig);
try {
printComponentsJson(pw, disabled, configurations, isZip);
} catch (IOException ignore) {
// ignore
}
} else {
printComponentsText(pw, disabled, noConfig, configurations);
}
}
Aggregations