Search in sources :

Example 1 with OsgiIdentityCapability

use of org.apache.aries.subsystem.core.internal.OsgiIdentityCapability 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 2 with OsgiIdentityCapability

use of org.apache.aries.subsystem.core.internal.OsgiIdentityCapability in project aries by apache.

the class Aries1425Test method testToRequirement.

@Test
public void testToRequirement() {
    SubsystemContentHeader header = new SubsystemContentHeader(HEADER_1);
    Collection<SubsystemContentHeader.Clause> clauses = header.getClauses();
    assertEquals("Wrong size", 3, clauses.size());
    Map<String, SubsystemContentHeader.Clause> map = new HashMap<String, SubsystemContentHeader.Clause>(3);
    for (SubsystemContentHeader.Clause clause : clauses) {
        map.put(clause.toString(), clause);
    }
    Resource resource = new Resource() {

        @Override
        public List<Capability> getCapabilities(String namespace) {
            return Collections.emptyList();
        }

        @Override
        public List<Requirement> getRequirements(String namespace) {
            return Collections.emptyList();
        }
    };
    SubsystemContentHeader.Clause clause = map.get(BUNDLE_A);
    Requirement requirement = clause.toRequirement(resource);
    assertTrue("Wrong requirement", ResourceHelper.matches(requirement, new OsgiIdentityCapability(resource, BUNDLE_A, Version.emptyVersion, IdentityNamespace.TYPE_FRAGMENT)));
    assertTrue("Wrong requirement", ResourceHelper.matches(requirement, new OsgiIdentityCapability(resource, BUNDLE_A, Version.emptyVersion, IdentityNamespace.TYPE_BUNDLE)));
    clause = map.get(BUNDLE_B);
    requirement = clause.toRequirement(resource);
    assertFalse("Wrong requirement", ResourceHelper.matches(requirement, new OsgiIdentityCapability(resource, "bundle.b", Version.emptyVersion, IdentityNamespace.TYPE_FRAGMENT)));
    assertTrue("Wrong requirement", ResourceHelper.matches(requirement, new OsgiIdentityCapability(resource, "bundle.b", Version.emptyVersion, IdentityNamespace.TYPE_BUNDLE)));
    clause = map.get(BUNDLE_C);
    requirement = clause.toRequirement(resource);
    assertTrue("Wrong requirement", ResourceHelper.matches(requirement, new OsgiIdentityCapability(resource, "bundle.c", Version.emptyVersion, IdentityNamespace.TYPE_FRAGMENT)));
    assertFalse("Wrong requirement", ResourceHelper.matches(requirement, new OsgiIdentityCapability(resource, "bundle.c", Version.emptyVersion, IdentityNamespace.TYPE_BUNDLE)));
}
Also used : Requirement(org.osgi.resource.Requirement) Capability(org.osgi.resource.Capability) OsgiIdentityCapability(org.apache.aries.subsystem.core.internal.OsgiIdentityCapability) HashMap(java.util.HashMap) Resource(org.osgi.resource.Resource) OsgiIdentityCapability(org.apache.aries.subsystem.core.internal.OsgiIdentityCapability) Test(org.junit.Test)

Aggregations

OsgiIdentityCapability (org.apache.aries.subsystem.core.internal.OsgiIdentityCapability)2 Capability (org.osgi.resource.Capability)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Test (org.junit.Test)1 Requirement (org.osgi.resource.Requirement)1 Resource (org.osgi.resource.Resource)1