use of org.osgi.resource.Capability in project aries by apache.
the class CustomContentHandlerTest method testCustomContentHandler.
@Test
public void testCustomContentHandler() throws Exception {
for (Bundle b : bundleContext.getBundles()) {
if ("org.apache.aries.subsystem.itests.customcontent.bundleA".equals(b.getSymbolicName())) {
fail("Precondition");
}
}
SausagesContentHandler handler = new SausagesContentHandler();
Dictionary<String, Object> props = new Hashtable<String, Object>();
props.put(ContentHandler.CONTENT_TYPE_PROPERTY, "foo.sausages");
ServiceRegistration<ContentHandler> reg = bundleContext.registerService(ContentHandler.class, handler, props);
try {
assertEquals("Precondition", 0, handler.calls.size());
Subsystem subsystem = installSubsystemFromFile("customContent.esa");
try {
assertEquals(Arrays.asList("install:customContent1 sausages = 1"), handler.calls);
Collection<Resource> constituents = subsystem.getConstituents();
assertEquals("The custom content should not show up as a subsystem constituent", 1, constituents.size());
boolean foundBundle = false;
for (Bundle b : bundleContext.getBundles()) {
if ("org.apache.aries.subsystem.itests.customcontent.bundleA".equals(b.getSymbolicName())) {
foundBundle = true;
}
}
assertTrue(foundBundle);
boolean foundBundleInConstituents = false;
for (Resource c : constituents) {
for (Capability idCap : c.getCapabilities(IdentityNamespace.IDENTITY_NAMESPACE)) {
Object name = idCap.getAttributes().get(IdentityNamespace.IDENTITY_NAMESPACE);
if ("org.apache.aries.subsystem.itests.customcontent.bundleA".equals(name))
foundBundleInConstituents = true;
}
}
assertTrue(foundBundleInConstituents);
handler.calls.clear();
assertEquals(Subsystem.State.INSTALLED, subsystem.getState());
subsystem.start();
assertEquals(Arrays.asList("start:customContent1"), handler.calls);
handler.calls.clear();
assertEquals(Subsystem.State.ACTIVE, subsystem.getState());
subsystem.stop();
assertEquals(Arrays.asList("stop:customContent1"), handler.calls);
assertEquals(Subsystem.State.RESOLVED, subsystem.getState());
} finally {
handler.calls.clear();
subsystem.uninstall();
assertEquals(Arrays.asList("uninstall:customContent1"), handler.calls);
assertEquals(Subsystem.State.UNINSTALLED, subsystem.getState());
}
} finally {
reg.unregister();
}
}
use of org.osgi.resource.Capability in project aries by apache.
the class SubsystemManifest method toCapabilities.
public List<Capability> toCapabilities(Resource resource) {
ArrayList<Capability> capabilities = new ArrayList<Capability>();
for (Header<?> header : headers.values()) if (header instanceof CapabilityHeader)
capabilities.addAll(((CapabilityHeader<?>) header).toCapabilities(resource));
capabilities.add(new OsgiIdentityCapability(resource, getSubsystemSymbolicNameHeader().getSymbolicName(), getSubsystemVersionHeader().getVersion(), getSubsystemTypeHeader().getType()));
capabilities.trimToSize();
return capabilities;
}
use of org.osgi.resource.Capability in project aries by apache.
the class CapabilitySetRepository method removeResource.
public void removeResource(Resource resource) {
for (Capability capability : resource.getCapabilities(null)) {
CapabilitySet capabilitySet = namespace2capabilitySet.get(capability.getNamespace());
if (capabilitySet == null) {
continue;
}
// TODO Examine CapabilitySet for thread safety.
capabilitySet.removeCapability(capability);
}
}
use of org.osgi.resource.Capability in project aries by apache.
the class InstallResourceComparator method getResourceType.
private String getResourceType(Resource r) {
List<Capability> cl = r.getCapabilities(IdentityNamespace.IDENTITY_NAMESPACE);
Capability c = cl.get(0);
Object o = c.getAttributes().get(IdentityNamespace.CAPABILITY_TYPE_ATTRIBUTE);
return String.valueOf(o);
}
use of org.osgi.resource.Capability in project aries by apache.
the class PreferredProviderRepository method addProviders.
private boolean addProviders(Requirement requirement, Repository repository, boolean checkValid) {
boolean result = false;
Map<Requirement, Collection<Capability>> map = repository.findProviders(Collections.singleton(requirement));
Collection<Capability> capabilities = map.get(requirement);
for (Capability capability : capabilities) {
if (checkValid ? isValid(capability) : true) {
this.repository.addResource(capability.getResource());
result = true;
}
}
return result;
}
Aggregations