Search in sources :

Example 1 with Capability

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();
    }
}
Also used : Capability(org.osgi.resource.Capability) Bundle(org.osgi.framework.Bundle) Hashtable(java.util.Hashtable) Resource(org.osgi.resource.Resource) ContentHandler(org.apache.aries.subsystem.ContentHandler) Subsystem(org.osgi.service.subsystem.Subsystem) Test(org.junit.Test)

Example 2 with Capability

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;
}
Also used : Capability(org.osgi.resource.Capability) OsgiIdentityCapability(org.apache.aries.subsystem.core.internal.OsgiIdentityCapability) ArrayList(java.util.ArrayList) OsgiIdentityCapability(org.apache.aries.subsystem.core.internal.OsgiIdentityCapability)

Example 3 with Capability

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);
    }
}
Also used : Capability(org.osgi.resource.Capability)

Example 4 with 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);
}
Also used : Capability(org.osgi.resource.Capability)

Example 5 with Capability

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;
}
Also used : Requirement(org.osgi.resource.Requirement) PreferredProviderRequirement(org.apache.aries.subsystem.core.archive.PreferredProviderRequirement) Capability(org.osgi.resource.Capability) Collection(java.util.Collection)

Aggregations

Capability (org.osgi.resource.Capability)189 Requirement (org.osgi.resource.Requirement)103 Resource (org.osgi.resource.Resource)60 ArrayList (java.util.ArrayList)38 IdentityCapability (aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability)37 HashMap (java.util.HashMap)37 CapReqBuilder (aQute.bnd.osgi.resource.CapReqBuilder)35 Collection (java.util.Collection)32 MockRegistry (test.lib.MockRegistry)26 BndEditModel (aQute.bnd.build.model.BndEditModel)25 Version (org.osgi.framework.Version)19 List (java.util.List)18 Repository (org.osgi.service.repository.Repository)17 Test (org.junit.Test)16 File (java.io.File)14 HostedCapability (org.osgi.service.resolver.HostedCapability)12 HashSet (java.util.HashSet)11 LinkedList (java.util.LinkedList)11 Map (java.util.Map)11 RequirementBuilder (aQute.bnd.osgi.resource.RequirementBuilder)8