Search in sources :

Example 11 with Capability

use of org.osgi.resource.Capability in project aries by apache.

the class RawSubsystemResource method getCapabilities.

@Override
public List<Capability> getCapabilities(String namespace) {
    if (namespace == null)
        return Collections.unmodifiableList(capabilities);
    ArrayList<Capability> result = new ArrayList<Capability>(capabilities.size());
    for (Capability capability : capabilities) if (namespace.equals(capability.getNamespace()))
        result.add(capability);
    result.trimToSize();
    return Collections.unmodifiableList(result);
}
Also used : Capability(org.osgi.resource.Capability) ArrayList(java.util.ArrayList)

Example 12 with Capability

use of org.osgi.resource.Capability in project aries by apache.

the class RawSubsystemResource method computeRequirements.

private List<Requirement> computeRequirements(SubsystemManifest manifest) throws ResolutionException {
    if (isComposite(manifest)) {
        // Composites determine their own requirements.
        return manifest.toRequirements(this);
    }
    // Gather up all of the content resources for the subsystem.
    SubsystemContentHeader header = manifest.getSubsystemContentHeader();
    if (header == null) {
        // Empty subsystems (i.e. subsystems with no content) are allowed.
        return Collections.emptyList();
    }
    List<Requirement> requirements = header.toRequirements(this);
    List<Resource> resources = new ArrayList<Resource>(requirements.size());
    // TODO Do we need the system repository in here (e.g., for features)?
    // What about the preferred provider repository?
    // Search the local repository and service repositories for content.
    RepositoryServiceRepository serviceRepo = new RepositoryServiceRepository();
    // TODO Should we search the service repositories first, the assumption
    // being they will contain more current content than the subsystem
    // archive?
    CompositeRepository compositeRepo = new CompositeRepository(localRepository, serviceRepo);
    for (Requirement requirement : requirements) {
        Collection<Capability> capabilities = compositeRepo.findProviders(requirement);
        if (!capabilities.isEmpty()) {
            resources.add(capabilities.iterator().next().getResource());
        }
    }
    if (fakeImportServiceResource != null) {
        // Add the fake resource so the dependency calculator knows not to
        // return service requirements that are included in 
        // Application-ImportService.
        resources.add(fakeImportServiceResource);
    }
    // dependencies not satisfied by the content resources themselves.
    return new DependencyCalculator(resources).calculateDependencies();
}
Also used : SubsystemContentHeader(org.apache.aries.subsystem.core.archive.SubsystemContentHeader) Requirement(org.osgi.resource.Requirement) Capability(org.osgi.resource.Capability) ArrayList(java.util.ArrayList) Resource(org.osgi.resource.Resource)

Example 13 with Capability

use of org.osgi.resource.Capability in project aries by apache.

the class RawSubsystemResource method computeFileCapabilities.

private List<Capability> computeFileCapabilities(FileResource resource, IFile file, SubsystemManifest manifest) {
    SubsystemContentHeader ssch = manifest.getSubsystemContentHeader();
    if (ssch == null)
        return Collections.emptyList();
    for (Clause c : ssch.getClauses()) {
        Attribute er = c.getAttribute(ContentHandler.EMBEDDED_RESOURCE_ATTRIBUTE);
        if (er != null) {
            if (file.getName().equals(er.getValue())) {
                Map<String, Object> attrs = new HashMap<String, Object>();
                attrs.put(ContentHandler.EMBEDDED_RESOURCE_ATTRIBUTE, er.getValue());
                return Collections.<Capability>singletonList(new OsgiIdentityCapability(resource, c.getSymbolicName(), c.getVersionRange().getLeft(), c.getType(), attrs));
            }
        }
    }
    return Collections.emptyList();
}
Also used : SubsystemContentHeader(org.apache.aries.subsystem.core.archive.SubsystemContentHeader) Capability(org.osgi.resource.Capability) Attribute(org.apache.aries.subsystem.core.archive.Attribute) HashMap(java.util.HashMap) Clause(org.apache.aries.subsystem.core.archive.SubsystemContentHeader.Clause)

Example 14 with Capability

use of org.osgi.resource.Capability in project aries by apache.

the class FileResource method setCapabilities.

public void setCapabilities(List<Capability> capabilities) {
    Map<String, List<Capability>> m = new HashMap<String, List<Capability>>();
    for (Capability c : capabilities) {
        List<Capability> l = m.get(c.getNamespace());
        if (l == null) {
            l = new ArrayList<Capability>();
            m.put(c.getNamespace(), l);
        }
        l.add(c);
    }
    this.capabilities = m;
}
Also used : Capability(org.osgi.resource.Capability) HashMap(java.util.HashMap) List(java.util.List) ArrayList(java.util.ArrayList)

Example 15 with Capability

use of org.osgi.resource.Capability in project aries by apache.

the class Aries1368Test method testApplicationWithFragmentInArchiveWithSubsystemContentHeaderWithType.

@Test
public void testApplicationWithFragmentInArchiveWithSubsystemContentHeaderWithType() throws Exception {
    Subsystem applicationA = installSubsystemFromFile(APPLICATION_A);
    try {
        assertConstituents(3, applicationA);
        startSubsystem(applicationA);
        assertBundleState(Bundle.ACTIVE, BUNDLE_A, applicationA);
        assertBundleState(Bundle.RESOLVED, FRAGMENT_A, applicationA);
        Bundle bundle = context(applicationA).getBundleByName(FRAGMENT_A);
        assertNotNull("Bundle not found: " + FRAGMENT_A, bundle);
        Resource resource = bundle.adapt(BundleRevision.class);
        Capability capability = resource.getCapabilities(IdentityNamespace.IDENTITY_NAMESPACE).get(0);
        assertEquals("Wrong type", IdentityNamespace.TYPE_FRAGMENT, capability.getAttributes().get(IdentityNamespace.CAPABILITY_TYPE_ATTRIBUTE));
    } finally {
        stopAndUninstallSubsystemSilently(applicationA);
    }
}
Also used : Capability(org.osgi.resource.Capability) TestCapability(org.apache.aries.subsystem.itests.util.TestCapability) Bundle(org.osgi.framework.Bundle) Subsystem(org.osgi.service.subsystem.Subsystem) Resource(org.osgi.resource.Resource) SubsystemTest(org.apache.aries.subsystem.itests.SubsystemTest) Test(org.junit.Test)

Aggregations

Capability (org.osgi.resource.Capability)197 Requirement (org.osgi.resource.Requirement)104 Resource (org.osgi.resource.Resource)61 ArrayList (java.util.ArrayList)40 HashMap (java.util.HashMap)39 IdentityCapability (aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability)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)20 List (java.util.List)19 Repository (org.osgi.service.repository.Repository)17 Test (org.junit.Test)16 File (java.io.File)15 HostedCapability (org.osgi.service.resolver.HostedCapability)13 HashSet (java.util.HashSet)12 Map (java.util.Map)12 LinkedList (java.util.LinkedList)11 RequirementBuilder (aQute.bnd.osgi.resource.RequirementBuilder)8