Search in sources :

Example 1 with Resource

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

use of org.osgi.resource.Resource 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 3 with Resource

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

the class ProvisionResourceHeader method newInstance.

public static ProvisionResourceHeader newInstance(Collection<Resource> resources) {
    StringBuilder builder = new StringBuilder();
    for (Resource resource : resources) {
        appendResource(resource, builder);
        builder.append(',');
    }
    // Remove the trailing comma.
    // TODO Intentionally letting the exception propagate since there must be at least one resource.
    builder.deleteCharAt(builder.length() - 1);
    return new ProvisionResourceHeader(builder.toString());
}
Also used : Resource(org.osgi.resource.Resource)

Example 4 with Resource

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

the class SubsystemContentHeader method newInstance.

public static SubsystemContentHeader newInstance(Collection<Resource> resources) {
    StringBuilder builder = new StringBuilder();
    for (Resource resource : resources) {
        appendResource(resource, builder);
        builder.append(',');
    }
    // Remove the trailing comma.
    // TODO Intentionally letting the exception propagate since there must be at least one resource.
    builder.deleteCharAt(builder.length() - 1);
    return new SubsystemContentHeader(builder.toString());
}
Also used : Resource(org.osgi.resource.Resource)

Example 5 with Resource

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

the class DeployedContentHeader method newInstance.

public static DeployedContentHeader newInstance(Collection<Resource> resources) {
    StringBuilder builder = new StringBuilder();
    for (Resource resource : resources) {
        appendResource(resource, builder, true);
        builder.append(',');
    }
    // Remove the trailing comma.
    // TODO Intentionally letting the exception propagate since there must
    // be at least one resource.
    builder.deleteCharAt(builder.length() - 1);
    return new DeployedContentHeader(builder.toString());
}
Also used : Resource(org.osgi.resource.Resource)

Aggregations

Resource (org.osgi.resource.Resource)197 Requirement (org.osgi.resource.Requirement)62 Capability (org.osgi.resource.Capability)61 ArrayList (java.util.ArrayList)54 List (java.util.List)37 HashMap (java.util.HashMap)31 File (java.io.File)27 Collection (java.util.Collection)24 ResourceBuilder (aQute.bnd.osgi.resource.ResourceBuilder)23 Wire (org.osgi.resource.Wire)22 Map (java.util.Map)21 CapReqBuilder (aQute.bnd.osgi.resource.CapReqBuilder)18 URI (java.net.URI)18 BndEditModel (aQute.bnd.build.model.BndEditModel)15 HashSet (java.util.HashSet)15 MockRegistry (test.lib.MockRegistry)15 Version (org.osgi.framework.Version)14 BundleRevision (org.osgi.framework.wiring.BundleRevision)14 Repository (org.osgi.service.repository.Repository)14 IdentityCapability (aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability)13