Search in sources :

Example 11 with Module

use of org.eclipse.osgi.container.Module 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 12 with Module

use of org.eclipse.osgi.container.Module in project rt.equinox.framework by eclipse.

the class TestModuleContainer method testCompatOptional.

@Test
public void testCompatOptional() throws BundleException, IOException {
    DummyContainerAdaptor adaptor = createDummyAdaptor();
    ModuleContainer container = adaptor.getContainer();
    Module b1 = installDummyModule("compatOptional1.MF", "b1", container);
    Module b2 = installDummyModule("compatOptional2.MF", "b2", container);
    Module b3 = installDummyModule("compatOptional3.MF", "b3", container);
    String b1BundleResolution = b1.getCurrentRevision().getRequirements(BundleNamespace.BUNDLE_NAMESPACE).iterator().next().getDirectives().get(Namespace.REQUIREMENT_RESOLUTION_DIRECTIVE);
    String b2BundleResolution = b2.getCurrentRevision().getRequirements(BundleNamespace.BUNDLE_NAMESPACE).iterator().next().getDirectives().get(Namespace.REQUIREMENT_RESOLUTION_DIRECTIVE);
    String b3BundleResolution = b3.getCurrentRevision().getRequirements(BundleNamespace.BUNDLE_NAMESPACE).iterator().next().getDirectives().get(Namespace.REQUIREMENT_RESOLUTION_DIRECTIVE);
    String b1PackageResolution = b1.getCurrentRevision().getRequirements(PackageNamespace.PACKAGE_NAMESPACE).iterator().next().getDirectives().get(Namespace.REQUIREMENT_RESOLUTION_DIRECTIVE);
    String b2PackageResolution = b2.getCurrentRevision().getRequirements(PackageNamespace.PACKAGE_NAMESPACE).iterator().next().getDirectives().get(Namespace.REQUIREMENT_RESOLUTION_DIRECTIVE);
    String b3PackageResolution = b3.getCurrentRevision().getRequirements(PackageNamespace.PACKAGE_NAMESPACE).iterator().next().getDirectives().get(Namespace.REQUIREMENT_RESOLUTION_DIRECTIVE);
    Assert.assertEquals("Wrong resolution directive: " + b1, Namespace.RESOLUTION_OPTIONAL, b1BundleResolution);
    Assert.assertNull("Wrong resolution directive: ", b2BundleResolution);
    Assert.assertEquals("Wrong resolution directive: " + b2, Namespace.RESOLUTION_OPTIONAL, b3BundleResolution);
    Assert.assertEquals("Wrong resolution directive: " + b1, Namespace.RESOLUTION_OPTIONAL, b1PackageResolution);
    Assert.assertNull("Wrong resolution directive: ", b2PackageResolution);
    Assert.assertEquals("Wrong resolution directive: " + b2, Namespace.RESOLUTION_OPTIONAL, b3PackageResolution);
}
Also used : DummyContainerAdaptor(org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor) ModuleContainer(org.eclipse.osgi.container.ModuleContainer) Module(org.eclipse.osgi.container.Module) Test(org.junit.Test)

Example 13 with Module

use of org.eclipse.osgi.container.Module in project rt.equinox.framework by eclipse.

the class TestModuleContainer method doTestStartOnResolve.

private void doTestStartOnResolve(boolean enabled) throws BundleException, IOException {
    Map<String, String> configuration = new HashMap<String, String>();
    if (!enabled) {
        configuration.put(EquinoxConfiguration.PROP_MODULE_AUTO_START_ON_RESOLVE, Boolean.toString(false));
    }
    DummyContainerAdaptor adaptor = new DummyContainerAdaptor(new DummyCollisionHook(false), configuration);
    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());
    systemBundle.start();
    // install a bunch of modules
    Map<String, String> manifest = new HashMap<String, String>();
    List<Module> modules = new ArrayList<Module>();
    for (int i = 0; i < 5; i++) {
        manifest.clear();
        manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
        manifest.put(Constants.BUNDLE_SYMBOLICNAME, "module." + i);
        manifest.put(Constants.IMPORT_PACKAGE, "export");
        Module module = installDummyModule(manifest, manifest.get(Constants.BUNDLE_SYMBOLICNAME), container);
        try {
            module.start();
            fail("expected a bundle exception.");
        } catch (BundleException e) {
        // do nothing
        }
        modules.add(module);
    }
    manifest.clear();
    manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    manifest.put(Constants.BUNDLE_SYMBOLICNAME, "exporter");
    manifest.put(Constants.EXPORT_PACKAGE, "export");
    installDummyModule(manifest, manifest.get(Constants.BUNDLE_SYMBOLICNAME), container);
    report = container.resolve(Collections.<Module>emptySet(), false);
    Assert.assertNull("Found a error.", report.getResolutionException());
    State expectedState = enabled ? State.ACTIVE : State.RESOLVED;
    for (Module module : modules) {
        Assert.assertEquals("Wrong state.", expectedState, module.getState());
    }
}
Also used : HashMap(java.util.HashMap) DummyCollisionHook(org.eclipse.osgi.tests.container.dummys.DummyCollisionHook) ModuleContainer(org.eclipse.osgi.container.ModuleContainer) ArrayList(java.util.ArrayList) ResolutionReport(org.eclipse.osgi.report.resolution.ResolutionReport) DummyContainerAdaptor(org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor) State(org.eclipse.osgi.container.Module.State) BundleException(org.osgi.framework.BundleException) Module(org.eclipse.osgi.container.Module)

Example 14 with Module

use of org.eclipse.osgi.container.Module 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 15 with Module

use of org.eclipse.osgi.container.Module in project rt.equinox.framework by eclipse.

the class TestModuleContainer method testDynamicImport05.

@Test
public void testDynamicImport05() throws BundleException, IOException {
    DummyContainerAdaptor adaptor = createDummyAdaptor();
    ModuleContainer container = adaptor.getContainer();
    Module systemBundle = installDummyModule("system.bundle.MF", Constants.SYSTEM_BUNDLE_LOCATION, null, null, "osgi.ee; osgi.ee=JavaSE; version:Version=\"1.5.0\"", container);
    container.resolve(Arrays.asList(systemBundle), true);
    Module c1 = installDummyModule("c1_v1.MF", "c1_v1", container);
    Module c4 = installDummyModule("c4_v1.MF", "c4_v1", container);
    Module dynamic3 = installDummyModule("dynamic3_v1.MF", "dynamic3_v1", container);
    Module dynamic3Frag = installDummyModule("dynamic3.frag_v1.MF", "dynamic3.frag_v1", container);
    container.resolve(Arrays.asList(c1, c4, dynamic3, dynamic3Frag), true);
    ModuleWire dynamicWire = container.resolveDynamic("c4.a", dynamic3.getCurrentRevision());
    Assert.assertNotNull("No dynamic wire found.", dynamicWire);
    Assert.assertEquals("Wrong package found.", "c4.a", dynamicWire.getCapability().getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE));
    Assert.assertEquals("Wrong provider for the wire found.", c4.getCurrentRevision(), dynamicWire.getProvider());
    dynamicWire = container.resolveDynamic("c4.b", dynamic3.getCurrentRevision());
    Assert.assertNotNull("No dynamic wire found.", dynamicWire);
    Assert.assertEquals("Wrong package found.", "c4.b", dynamicWire.getCapability().getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE));
    Assert.assertEquals("Wrong provider for the wire found.", c4.getCurrentRevision(), dynamicWire.getProvider());
}
Also used : DummyContainerAdaptor(org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor) ModuleWire(org.eclipse.osgi.container.ModuleWire) ModuleContainer(org.eclipse.osgi.container.ModuleContainer) Module(org.eclipse.osgi.container.Module) Test(org.junit.Test)

Aggregations

Module (org.eclipse.osgi.container.Module)119 ModuleContainer (org.eclipse.osgi.container.ModuleContainer)92 Test (org.junit.Test)84 DummyContainerAdaptor (org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor)79 ResolutionReport (org.eclipse.osgi.report.resolution.ResolutionReport)36 ModuleWire (org.eclipse.osgi.container.ModuleWire)32 HashMap (java.util.HashMap)23 ArrayList (java.util.ArrayList)22 ModuleWiring (org.eclipse.osgi.container.ModuleWiring)22 ModuleRevision (org.eclipse.osgi.container.ModuleRevision)21 DummyModuleDatabase (org.eclipse.osgi.tests.container.dummys.DummyModuleDatabase)12 Generation (org.eclipse.osgi.storage.BundleInfo.Generation)10 BundleException (org.osgi.framework.BundleException)10 DummyModuleEvent (org.eclipse.osgi.tests.container.dummys.DummyModuleDatabase.DummyModuleEvent)9 ModuleRevisionBuilder (org.eclipse.osgi.container.ModuleRevisionBuilder)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 DataInputStream (java.io.DataInputStream)6 ModuleCapability (org.eclipse.osgi.container.ModuleCapability)6 DummyCollisionHook (org.eclipse.osgi.tests.container.dummys.DummyCollisionHook)6