Search in sources :

Example 1 with Requirement

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

the class AriesSubsystemTest method testAddRequirementsKeepsEdgesOtherThanParentChild.

/*
	 * The region copy process when adding additional requirements should
	 * keep all edges, not just the ones running between parent and child. This
	 * is of particular concern with regard to the connections all subsystem
	 * regions have with the root region to allow the subsystem services
	 * through. However, it may also be of concern if the region digraph is
	 * modified outside of the subsystems API.
	 */
@Test
public void testAddRequirementsKeepsEdgesOtherThanParentChild() throws Exception {
    AriesSubsystem compositeA = (AriesSubsystem) installSubsystemFromFile(COMPOSITE_A);
    try {
        AriesSubsystem applicationB = (AriesSubsystem) getConstituentAsSubsystem(compositeA, APPLICATION_B, null, SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION);
        Region bRegion = getRegion(applicationB);
        // One edge to parent for import package. One edge to root for subsystem
        // service.
        assertEquals("Wrong number of edges", 2, bRegion.getEdges().size());
        Requirement requirement = new BasicRequirement.Builder().namespace(PackageNamespace.PACKAGE_NAMESPACE).directive(PackageNamespace.REQUIREMENT_FILTER_DIRECTIVE, "(osgi.wiring.package=org.osgi.framework)").resource(EasyMock.createMock(Resource.class)).build();
        applicationB.addRequirements(Collections.singleton(requirement));
        bRegion = getRegion(applicationB);
        // Still one edge to parent for import package. One edge to root for 
        // subsystem service.
        assertEquals("Wrong number of edges", 2, bRegion.getEdges().size());
        Region rootRegion = getRegion(getRootSubsystem());
        // The root region won't be the tail region for any connection unless
        // manually added.
        assertEquals("Wrong number of edges", 0, rootRegion.getEdges().size());
        // Manually add a connection from root to application B.
        rootRegion.connectRegion(bRegion, rootRegion.getRegionDigraph().createRegionFilterBuilder().allow("com.foo", "(bar=b)").build());
        // The root region should now have an edge.
        assertEquals("Wrong number of edges", 1, rootRegion.getEdges().size());
        // Add another requirement to force a copy.
        requirement = new BasicRequirement.Builder().namespace(PackageNamespace.PACKAGE_NAMESPACE).directive(PackageNamespace.REQUIREMENT_FILTER_DIRECTIVE, "(osgi.wiring.package=org.osgi.framework.wiring)").resource(EasyMock.createMock(Resource.class)).build();
        applicationB.addRequirements(Collections.singleton(requirement));
        rootRegion = getRegion(getRootSubsystem());
        // The root region should still have its edge.
        assertEquals("Wrong number of edges", 1, rootRegion.getEdges().size());
        bRegion = getRegion(applicationB);
        // Still one edge to parent for import package. One edge to root for 
        // subsystem service.
        assertEquals("Wrong number of edges", 2, bRegion.getEdges().size());
    } finally {
        uninstallSubsystemSilently(compositeA);
    }
}
Also used : Requirement(org.osgi.resource.Requirement) BasicRequirement(org.apache.aries.subsystem.core.internal.BasicRequirement) BasicRequirement(org.apache.aries.subsystem.core.internal.BasicRequirement) Resource(org.osgi.resource.Resource) Region(org.eclipse.equinox.region.Region) AriesSubsystem(org.apache.aries.subsystem.AriesSubsystem) Test(org.junit.Test)

Example 2 with Requirement

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

the class AriesSubsystemTest method testAddRequirementWithVisibleBundleNamespace.

/*
	 * Aries Subsystems uses Equinox Region Digraph as its isolation engine.
	 * Digraph has a "special" namespace value that tells the region to allow
	 * everything a bundle offers. This test ensures that a correctly formatted
	 * requirement in that namespace works as expected.
	 */
@Test
public void testAddRequirementWithVisibleBundleNamespace() throws Exception {
    Requirement requirement = new BasicRequirement.Builder().namespace(RegionFilter.VISIBLE_BUNDLE_NAMESPACE).directive(Namespace.REQUIREMENT_FILTER_DIRECTIVE, "(id=0)").resource(EasyMock.createMock(Resource.class)).build();
    AriesSubsystem compositeA = (AriesSubsystem) installSubsystemFromFile(COMPOSITE_A);
    try {
        startSubsystem(compositeA);
        // Test that the installation of applicationA fails.
        try {
            installSubsystemFromFile(compositeA, APPLICATION_A);
            fail("Subsystem should not have installed due to unresolved org.osgi.framework package requirement");
        } catch (SubsystemException e) {
        // Okay.
        }
        // Add the requirement with the region digraph specific namespace.
        compositeA.addRequirements(Collections.singleton(requirement));
        // Test that the installation and startup of applicationA succeeds.
        AriesSubsystem applicationA;
        try {
            applicationA = (AriesSubsystem) installSubsystemFromFile(compositeA, APPLICATION_A);
            startSubsystem(applicationA);
        } catch (SubsystemException e) {
            fail("Subsystem should have installed and started");
        }
        assertCompositeAAfter(compositeA);
    } finally {
        stopAndUninstallSubsystemSilently(compositeA);
    }
}
Also used : Requirement(org.osgi.resource.Requirement) BasicRequirement(org.apache.aries.subsystem.core.internal.BasicRequirement) SubsystemException(org.osgi.service.subsystem.SubsystemException) AriesSubsystem(org.apache.aries.subsystem.AriesSubsystem) Test(org.junit.Test)

Example 3 with Requirement

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

the class BundleResource method getRequirements.

public List<Requirement> getRequirements(String namespace) {
    if (namespace == null)
        return Collections.unmodifiableList(requirements);
    ArrayList<Requirement> result = new ArrayList<Requirement>(requirements.size());
    for (Requirement requirement : requirements) if (namespace.equals(requirement.getNamespace()))
        result.add(requirement);
    result.trimToSize();
    return Collections.unmodifiableList(result);
}
Also used : Requirement(org.osgi.resource.Requirement) RequireBundleRequirement(org.apache.aries.subsystem.core.archive.RequireBundleRequirement) FragmentHostRequirement(org.apache.aries.subsystem.core.archive.FragmentHostRequirement) RequireCapabilityRequirement(org.apache.aries.subsystem.core.archive.RequireCapabilityRequirement) ArrayList(java.util.ArrayList)

Example 4 with Requirement

use of org.osgi.resource.Requirement 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)

Example 5 with Requirement

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

the class RegionUpdater method addRequirements.

private void addRequirements(Collection<? extends Requirement> requirements, RegionFilterBuilder builder) throws InvalidSyntaxException {
    for (Requirement requirement : requirements) {
        String namespace = requirement.getNamespace();
        // The osgi.service namespace requires translation.
        if (ServiceNamespace.SERVICE_NAMESPACE.equals(namespace))
            namespace = RegionFilter.VISIBLE_SERVICE_NAMESPACE;
        String filter = requirement.getDirectives().get(IdentityNamespace.REQUIREMENT_FILTER_DIRECTIVE);
        // A null filter means import everything from that namespace.
        if (filter == null)
            builder.allowAll(namespace);
        else
            builder.allow(namespace, filter);
    }
}
Also used : Requirement(org.osgi.resource.Requirement)

Aggregations

Requirement (org.osgi.resource.Requirement)193 Capability (org.osgi.resource.Capability)102 Resource (org.osgi.resource.Resource)59 CapReqBuilder (aQute.bnd.osgi.resource.CapReqBuilder)53 ArrayList (java.util.ArrayList)46 Collection (java.util.Collection)44 BndEditModel (aQute.bnd.build.model.BndEditModel)35 IdentityCapability (aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability)34 HashMap (java.util.HashMap)34 MockRegistry (test.lib.MockRegistry)32 List (java.util.List)19 Repository (org.osgi.service.repository.Repository)19 Test (org.junit.Test)18 File (java.io.File)14 Map (java.util.Map)12 Resolver (org.osgi.service.resolver.Resolver)11 LinkedHashSet (java.util.LinkedHashSet)10 LinkedList (java.util.LinkedList)10 Wire (org.osgi.resource.Wire)10 Parameters (aQute.bnd.header.Parameters)9