Search in sources :

Example 16 with BundleRequirement

use of org.osgi.framework.wiring.BundleRequirement in project rt.equinox.framework by eclipse.

the class TestModuleContainer method testSubstitutableExport.

@Test
public void testSubstitutableExport() throws BundleException, IOException {
    DummyContainerAdaptor adaptor = createDummyAdaptor();
    ModuleContainer container = adaptor.getContainer();
    // install the system.bundle
    Module systemBundle = installDummyModule("system.bundle.MF", Constants.SYSTEM_BUNDLE_LOCATION, Constants.SYSTEM_BUNDLE_SYMBOLICNAME, null, null, container);
    ResolutionReport report = container.resolve(Arrays.asList(systemBundle), true);
    Assert.assertNull("Failed to resolve system.bundle.", report.getResolutionException());
    // install an exporter with substitutable export.
    Map<String, String> exporterManifest = new HashMap<String, String>();
    exporterManifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    exporterManifest.put(Constants.BUNDLE_SYMBOLICNAME, "exporter");
    exporterManifest.put(Constants.EXPORT_PACKAGE, "exporter");
    exporterManifest.put(Constants.IMPORT_PACKAGE, "exporter");
    Module moduleSubsExport = installDummyModule(exporterManifest, "exporter", container);
    report = container.resolve(Arrays.asList(moduleSubsExport), true);
    Assert.assertNull("Failed to resolve", report.getResolutionException());
    List<BundleRequirement> reqs = moduleSubsExport.getCurrentRevision().getWiring().getRequirements(PackageNamespace.PACKAGE_NAMESPACE);
    assertEquals("Wrong number of imports.", 0, reqs.size());
    container.uninstall(moduleSubsExport);
    exporterManifest = new HashMap<String, String>();
    exporterManifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    exporterManifest.put(Constants.BUNDLE_SYMBOLICNAME, "substitutableExporter");
    exporterManifest.put(Constants.EXPORT_PACKAGE, "exporter");
    exporterManifest.put(Constants.IMPORT_PACKAGE, "exporter; pickme=true");
    moduleSubsExport = installDummyModule(exporterManifest, "substitutableExporter", container);
    exporterManifest = new HashMap<String, String>();
    exporterManifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    exporterManifest.put(Constants.BUNDLE_SYMBOLICNAME, "exporter");
    exporterManifest.put(Constants.EXPORT_PACKAGE, "exporter; pickme=true");
    Module moduleExport = installDummyModule(exporterManifest, "exporter", container);
    report = container.resolve(Arrays.asList(moduleSubsExport), true);
    Assert.assertNull("Failed to resolve", report.getResolutionException());
    List<BundleCapability> caps = moduleSubsExport.getCurrentRevision().getWiring().getCapabilities(PackageNamespace.PACKAGE_NAMESPACE);
    assertEquals("Wrong number of capabilities.", 0, caps.size());
    reqs = moduleSubsExport.getCurrentRevision().getWiring().getRequirements(PackageNamespace.PACKAGE_NAMESPACE);
    assertEquals("Wrong number of imports.", 1, reqs.size());
    ModuleWiring wiring = moduleSubsExport.getCurrentRevision().getWiring();
    List<ModuleWire> packageWires = wiring.getRequiredModuleWires(PackageNamespace.PACKAGE_NAMESPACE);
    Assert.assertEquals("Unexpected number of wires", 1, packageWires.size());
    Assert.assertEquals("Wrong exporter", packageWires.get(0).getProviderWiring().getRevision(), moduleExport.getCurrentRevision());
}
Also used : ModuleWire(org.eclipse.osgi.container.ModuleWire) ModuleContainer(org.eclipse.osgi.container.ModuleContainer) HashMap(java.util.HashMap) ResolutionReport(org.eclipse.osgi.report.resolution.ResolutionReport) BundleRequirement(org.osgi.framework.wiring.BundleRequirement) DummyContainerAdaptor(org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor) ModuleWiring(org.eclipse.osgi.container.ModuleWiring) Module(org.eclipse.osgi.container.Module) BundleCapability(org.osgi.framework.wiring.BundleCapability) Test(org.junit.Test)

Example 17 with BundleRequirement

use of org.osgi.framework.wiring.BundleRequirement in project rt.equinox.framework by eclipse.

the class TestModuleContainer method testSingleton04.

@Test
public void testSingleton04() throws BundleException, IOException {
    final Collection<BundleRevision> disabled = new ArrayList<BundleRevision>();
    ResolverHookFactory resolverHookFactory = new ResolverHookFactory() {

        @Override
        public ResolverHook begin(Collection<BundleRevision> triggers) {
            return new ResolverHook() {

                @Override
                public void filterSingletonCollisions(BundleCapability singleton, Collection<BundleCapability> collisionCandidates) {
                // nothing
                }

                @Override
                public void filterResolvable(Collection<BundleRevision> candidates) {
                    candidates.removeAll(disabled);
                }

                @Override
                public void filterMatches(BundleRequirement requirement, Collection<BundleCapability> candidates) {
                // nothing
                }

                @Override
                public void end() {
                // nothing
                }
            };
        }
    };
    DummyContainerAdaptor adaptor = new DummyContainerAdaptor(new DummyCollisionHook(false), Collections.<String, String>emptyMap(), resolverHookFactory);
    ModuleContainer container = adaptor.getContainer();
    Module s1_v1 = installDummyModule("singleton1_v1.MF", "s1_v1", container);
    Module s1_v2 = installDummyModule("singleton1_v2.MF", "s1_v2", container);
    Module s1_v3 = installDummyModule("singleton1_v3.MF", "s1_v3", container);
    Module s2_v1 = installDummyModule("singleton2_v1.MF", "s1_v1", container);
    Module s2_v2 = installDummyModule("singleton2_v2.MF", "s1_v2", container);
    Module s2_v3 = installDummyModule("singleton2_v3.MF", "s1_v3", container);
    container.resolve(null, false);
    Assert.assertFalse("Singleton v1 is resolved.", Module.RESOLVED_SET.contains(s1_v1.getState()));
    Assert.assertFalse("Singleton v2 is resolved.", Module.RESOLVED_SET.contains(s1_v2.getState()));
    Assert.assertTrue("Singleton v3 is not resolved.", Module.RESOLVED_SET.contains(s1_v3.getState()));
    Assert.assertFalse("client v1 is resolved.", Module.RESOLVED_SET.contains(s2_v1.getState()));
    Assert.assertFalse("client v2 is resolved.", Module.RESOLVED_SET.contains(s2_v2.getState()));
    Assert.assertTrue("client v3 is not resolved.", Module.RESOLVED_SET.contains(s2_v3.getState()));
    // now disable s1_v3
    disabled.add(s1_v3.getCurrentRevision());
    container.refresh(Arrays.asList(s1_v3));
    Assert.assertFalse("Singleton v1 is resolved.", Module.RESOLVED_SET.contains(s1_v1.getState()));
    Assert.assertTrue("Singleton v2 is not resolved.", Module.RESOLVED_SET.contains(s1_v2.getState()));
    Assert.assertFalse("Singleton v3 is resolved.", Module.RESOLVED_SET.contains(s1_v3.getState()));
    Assert.assertFalse("client v1 is resolved.", Module.RESOLVED_SET.contains(s2_v1.getState()));
    Assert.assertTrue("client v2 is not resolved.", Module.RESOLVED_SET.contains(s2_v2.getState()));
    Assert.assertFalse("client v3 is resolved.", Module.RESOLVED_SET.contains(s2_v3.getState()));
    // now disable s1_v2
    disabled.add(s1_v2.getCurrentRevision());
    container.refresh(Arrays.asList(s1_v2));
    Assert.assertTrue("Singleton v1 is not resolved.", Module.RESOLVED_SET.contains(s1_v1.getState()));
    Assert.assertFalse("Singleton v2 is resolved.", Module.RESOLVED_SET.contains(s1_v2.getState()));
    Assert.assertFalse("Singleton v3 is resolved.", Module.RESOLVED_SET.contains(s1_v3.getState()));
    Assert.assertTrue("client v1 is not resolved.", Module.RESOLVED_SET.contains(s2_v1.getState()));
    Assert.assertFalse("client v2 is resolved.", Module.RESOLVED_SET.contains(s2_v2.getState()));
    Assert.assertFalse("client v3 is resolved.", Module.RESOLVED_SET.contains(s2_v3.getState()));
}
Also used : ResolverHookFactory(org.osgi.framework.hooks.resolver.ResolverHookFactory) DummyResolverHookFactory(org.eclipse.osgi.tests.container.dummys.DummyResolverHookFactory) DummyContainerAdaptor(org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor) DummyResolverHook(org.eclipse.osgi.tests.container.dummys.DummyResolverHook) ResolverHook(org.osgi.framework.hooks.resolver.ResolverHook) DummyCollisionHook(org.eclipse.osgi.tests.container.dummys.DummyCollisionHook) ModuleContainer(org.eclipse.osgi.container.ModuleContainer) BundleRevision(org.osgi.framework.wiring.BundleRevision) ArrayList(java.util.ArrayList) Collection(java.util.Collection) BundleCapability(org.osgi.framework.wiring.BundleCapability) Module(org.eclipse.osgi.container.Module) BundleRequirement(org.osgi.framework.wiring.BundleRequirement) Test(org.junit.Test)

Example 18 with BundleRequirement

use of org.osgi.framework.wiring.BundleRequirement in project rt.equinox.framework by eclipse.

the class TestModuleContainer method testDynamicWithOptionalImport.

@Test
public void testDynamicWithOptionalImport() throws BundleException, IOException {
    DummyContainerAdaptor adaptor = createDummyAdaptor();
    ModuleContainer container = adaptor.getContainer();
    // install the system.bundle
    Module systemBundle = installDummyModule("system.bundle.MF", Constants.SYSTEM_BUNDLE_LOCATION, Constants.SYSTEM_BUNDLE_SYMBOLICNAME, null, null, container);
    ResolutionReport report = container.resolve(Arrays.asList(systemBundle), true);
    Assert.assertNull("Failed to resolve system.bundle.", report.getResolutionException());
    // install an importer
    Map<String, String> optionalImporterManifest = new HashMap<String, String>();
    optionalImporterManifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    optionalImporterManifest.put(Constants.BUNDLE_SYMBOLICNAME, "importer");
    optionalImporterManifest.put(Constants.IMPORT_PACKAGE, "exporter; resolution:=optional");
    optionalImporterManifest.put(Constants.DYNAMICIMPORT_PACKAGE, "exporter");
    Module optionalImporterModule = installDummyModule(optionalImporterManifest, "optionalImporter", container);
    // unsatisfied optional and dynamic imports do not fail a resolve.
    report = container.resolve(Arrays.asList(optionalImporterModule), true);
    Assert.assertNull("Failed to resolve system.bundle.", report.getResolutionException());
    // dynamic and optional imports are same. Optional import is not satisfied we should only see the dynamic import
    List<BundleRequirement> importReqsList = optionalImporterModule.getCurrentRevision().getWiring().getRequirements(PackageNamespace.PACKAGE_NAMESPACE);
    assertEquals("Wrong number of imports.", 1, importReqsList.size());
    assertEquals("Import was not dynamic", PackageNamespace.RESOLUTION_DYNAMIC, importReqsList.get(0).getDirectives().get(Namespace.REQUIREMENT_RESOLUTION_DIRECTIVE));
    // install a exporter to satisfy existing optional import
    Map<String, String> exporterManifest = new HashMap<String, String>();
    exporterManifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    exporterManifest.put(Constants.BUNDLE_SYMBOLICNAME, "exporter");
    exporterManifest.put(Constants.EXPORT_PACKAGE, "exporter");
    installDummyModule(exporterManifest, "exporter", container);
    ModuleWire dynamicWire = container.resolveDynamic("exporter", optionalImporterModule.getCurrentRevision());
    Assert.assertNotNull("Expected to find a dynamic wire.", dynamicWire);
    // re-resolve importer
    container.refresh(Collections.singleton(optionalImporterModule));
    report = container.resolve(Arrays.asList(optionalImporterModule), true);
    Assert.assertNull("Failed to resolve system.bundle.", report.getResolutionException());
    importReqsList = optionalImporterModule.getCurrentRevision().getWiring().getRequirements(PackageNamespace.PACKAGE_NAMESPACE);
    assertEquals("Wrong number of imports.", 2, importReqsList.size());
}
Also used : DummyContainerAdaptor(org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor) ModuleWire(org.eclipse.osgi.container.ModuleWire) ModuleContainer(org.eclipse.osgi.container.ModuleContainer) HashMap(java.util.HashMap) Module(org.eclipse.osgi.container.Module) ResolutionReport(org.eclipse.osgi.report.resolution.ResolutionReport) BundleRequirement(org.osgi.framework.wiring.BundleRequirement) Test(org.junit.Test)

Example 19 with BundleRequirement

use of org.osgi.framework.wiring.BundleRequirement in project rt.equinox.framework by eclipse.

the class TestModuleContainer method testDynamicWithExport.

@Test
public void testDynamicWithExport() throws BundleException, IOException {
    DummyContainerAdaptor adaptor = createDummyAdaptor();
    ModuleContainer container = adaptor.getContainer();
    // install the system.bundle
    Module systemBundle = installDummyModule("system.bundle.MF", Constants.SYSTEM_BUNDLE_LOCATION, Constants.SYSTEM_BUNDLE_SYMBOLICNAME, null, null, container);
    ResolutionReport report = container.resolve(Arrays.asList(systemBundle), true);
    Assert.assertNull("Failed to resolve system.bundle.", report.getResolutionException());
    // install an importer
    Map<String, String> optionalImporterManifest = new HashMap<String, String>();
    optionalImporterManifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    optionalImporterManifest.put(Constants.BUNDLE_SYMBOLICNAME, "importer");
    optionalImporterManifest.put(Constants.EXPORT_PACKAGE, "exporter");
    optionalImporterManifest.put(Constants.DYNAMICIMPORT_PACKAGE, "exporter");
    Module optionalImporterModule = installDummyModule(optionalImporterManifest, "optionalImporter", container);
    // unsatisfied optional and dynamic imports do not fail a resolve.
    report = container.resolve(Arrays.asList(optionalImporterModule), true);
    Assert.assertNull("Failed to resolve system.bundle.", report.getResolutionException());
    // dynamic and optional imports are same. Optional import is not satisfied we should only see the dynamic import
    List<BundleRequirement> importReqsList = optionalImporterModule.getCurrentRevision().getWiring().getRequirements(PackageNamespace.PACKAGE_NAMESPACE);
    assertEquals("Wrong number of imports.", 1, importReqsList.size());
    assertEquals("Import was not dynamic", PackageNamespace.RESOLUTION_DYNAMIC, importReqsList.get(0).getDirectives().get(Namespace.REQUIREMENT_RESOLUTION_DIRECTIVE));
    ModuleWire dynamicWire = container.resolveDynamic("exporter", optionalImporterModule.getCurrentRevision());
    Assert.assertNull("Expected no dynamic wire.", dynamicWire);
}
Also used : DummyContainerAdaptor(org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor) ModuleWire(org.eclipse.osgi.container.ModuleWire) ModuleContainer(org.eclipse.osgi.container.ModuleContainer) HashMap(java.util.HashMap) Module(org.eclipse.osgi.container.Module) ResolutionReport(org.eclipse.osgi.report.resolution.ResolutionReport) BundleRequirement(org.osgi.framework.wiring.BundleRequirement) Test(org.junit.Test)

Example 20 with BundleRequirement

use of org.osgi.framework.wiring.BundleRequirement in project aries by apache.

the class BundleWiringStateMBeanTest method testGetCurrentRevisionDeclaredRequirements.

@Test
public void testGetCurrentRevisionDeclaredRequirements() throws Exception {
    Bundle a = getBundleByName("org.apache.aries.jmx.test.bundlea");
    BundleRevision br = (BundleRevision) a.adapt(BundleRevision.class);
    List<BundleRequirement> requirements = br.getDeclaredRequirements(BundleRevision.PACKAGE_NAMESPACE);
    CompositeData[] jmxRequirements = brsMBean.getCurrentRevisionDeclaredRequirements(a.getBundleId(), BundleRevision.PACKAGE_NAMESPACE);
    Assert.assertEquals(requirements.size(), jmxRequirements.length);
    Map<Map<String, Object>, Map<String, String>> expectedRequirements = requirementsToMap(requirements);
    Map<Map<String, Object>, Map<String, String>> actualRequirements = jmxCapReqToMap(jmxRequirements);
    Assert.assertEquals(expectedRequirements, actualRequirements);
}
Also used : Bundle(org.osgi.framework.Bundle) CompositeData(javax.management.openmbean.CompositeData) BundleRevision(org.osgi.framework.wiring.BundleRevision) HashMap(java.util.HashMap) Map(java.util.Map) BundleRequirement(org.osgi.framework.wiring.BundleRequirement) Test(org.junit.Test) AbstractIntegrationTest(org.apache.aries.jmx.AbstractIntegrationTest)

Aggregations

BundleRequirement (org.osgi.framework.wiring.BundleRequirement)55 BundleCapability (org.osgi.framework.wiring.BundleCapability)23 ArrayList (java.util.ArrayList)20 BundleWire (org.osgi.framework.wiring.BundleWire)18 BundleRevision (org.osgi.framework.wiring.BundleRevision)17 HashMap (java.util.HashMap)15 Bundle (org.osgi.framework.Bundle)15 Test (org.junit.Test)14 BundleException (org.osgi.framework.BundleException)11 ResolverHook (org.osgi.framework.hooks.resolver.ResolverHook)10 BundleWiring (org.osgi.framework.wiring.BundleWiring)10 List (java.util.List)9 Collection (java.util.Collection)8 BundleRequirementImpl (org.apache.felix.framework.wiring.BundleRequirementImpl)8 ResolverHookFactory (org.osgi.framework.hooks.resolver.ResolverHookFactory)8 CompositeData (javax.management.openmbean.CompositeData)6 Module (org.eclipse.osgi.container.Module)6 ModuleContainer (org.eclipse.osgi.container.ModuleContainer)6 DummyContainerAdaptor (org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor)6 SimpleFilter (org.apache.felix.framework.capabilityset.SimpleFilter)5