Search in sources :

Example 16 with ModuleRevision

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

the class TestModuleContainer method testRemovalPending.

@Test
public void testRemovalPending() throws BundleException, IOException {
    DummyContainerAdaptor adaptor = createDummyAdaptor();
    ModuleContainer container = adaptor.getContainer();
    DummyModuleDatabase database = adaptor.getDatabase();
    Module systemBundle = installDummyModule("system.bundle.MF", Constants.SYSTEM_BUNDLE_LOCATION, container);
    container.resolve(Arrays.asList(systemBundle), true);
    Module c4 = installDummyModule("c4_v1.MF", "c4_v1", container);
    Module c6 = installDummyModule("c6_v1.MF", "c6_v1", container);
    Module c7 = installDummyModule("c7_v1.MF", "c7_v1", container);
    container.resolve(Arrays.asList(c7), true);
    // throw out installed and resolved events
    database.getModuleEvents();
    ModuleRevision c4Revision0 = c4.getCurrentRevision();
    // updating to identical content
    container.update(c4, OSGiManifestBuilderFactory.createBuilder(getManifest("c4_v1.MF")), null);
    container.resolve(Arrays.asList(c4), true);
    Collection<ModuleRevision> removalPending = container.getRemovalPending();
    Assert.assertEquals("Wrong number of removal pending", 1, removalPending.size());
    Assert.assertTrue("Wrong module removalPending: " + removalPending, removalPending.contains(c4Revision0));
    ModuleRevision c6Revision0 = c6.getCurrentRevision();
    // updating to identical content
    container.update(c6, OSGiManifestBuilderFactory.createBuilder(getManifest("c6_v1.MF")), null);
    container.resolve(Arrays.asList(c6), true);
    removalPending = container.getRemovalPending();
    Assert.assertEquals("Wrong number of removal pending", 2, removalPending.size());
    Assert.assertTrue("Wrong module removalPending: " + removalPending, removalPending.containsAll(Arrays.asList(c4Revision0, c6Revision0)));
    // update again with identical content
    container.update(c4, OSGiManifestBuilderFactory.createBuilder(getManifest("c4_v1.MF")), null);
    container.update(c6, OSGiManifestBuilderFactory.createBuilder(getManifest("c6_v1.MF")), null);
    container.resolve(Arrays.asList(c4, c6), true);
    // Again we only have two since the previous current revisions did not have any dependents
    removalPending = container.getRemovalPending();
    Assert.assertEquals("Wrong number of removal pending", 2, removalPending.size());
    Assert.assertTrue("Wrong module removalPending: " + removalPending, removalPending.containsAll(Arrays.asList(c4Revision0, c6Revision0)));
    container.refresh(null);
    removalPending = container.getRemovalPending();
    Assert.assertEquals("Wrong number of removal pending", 0, removalPending.size());
    List<DummyModuleEvent> actual = database.getModuleEvents();
    List<DummyModuleEvent> expected = new ArrayList<DummyModuleEvent>(Arrays.asList(new DummyModuleEvent(c4, ModuleEvent.UNRESOLVED, State.INSTALLED), new DummyModuleEvent(c4, ModuleEvent.UPDATED, State.INSTALLED), new DummyModuleEvent(c4, ModuleEvent.RESOLVED, State.RESOLVED), new DummyModuleEvent(c6, ModuleEvent.UNRESOLVED, State.INSTALLED), new DummyModuleEvent(c6, ModuleEvent.UPDATED, State.INSTALLED), new DummyModuleEvent(c6, ModuleEvent.RESOLVED, State.RESOLVED), new DummyModuleEvent(c4, ModuleEvent.UNRESOLVED, State.INSTALLED), new DummyModuleEvent(c4, ModuleEvent.UPDATED, State.INSTALLED), new DummyModuleEvent(c6, ModuleEvent.UNRESOLVED, State.INSTALLED), new DummyModuleEvent(c6, ModuleEvent.UPDATED, State.INSTALLED), new DummyModuleEvent(c4, ModuleEvent.RESOLVED, State.RESOLVED), new DummyModuleEvent(c6, ModuleEvent.RESOLVED, State.RESOLVED), new DummyModuleEvent(c4, ModuleEvent.UNRESOLVED, State.INSTALLED), new DummyModuleEvent(c6, ModuleEvent.UNRESOLVED, State.INSTALLED), new DummyModuleEvent(c7, ModuleEvent.UNRESOLVED, State.INSTALLED), new DummyModuleEvent(c4, ModuleEvent.RESOLVED, State.RESOLVED), new DummyModuleEvent(c6, ModuleEvent.RESOLVED, State.RESOLVED), new DummyModuleEvent(c7, ModuleEvent.RESOLVED, State.RESOLVED)));
    assertEvents(expected, actual, false);
    // uninstall c4
    c4Revision0 = c4.getCurrentRevision();
    container.uninstall(c4);
    removalPending = container.getRemovalPending();
    Assert.assertEquals("Wrong number of removal pending", 1, removalPending.size());
    Assert.assertTrue("Wrong module removalPending: " + removalPending, removalPending.containsAll(Arrays.asList(c4Revision0)));
    container.refresh(null);
    actual = database.getModuleEvents();
    expected = new ArrayList<DummyModuleEvent>(Arrays.asList(new DummyModuleEvent(c4, ModuleEvent.UNRESOLVED, State.INSTALLED), new DummyModuleEvent(c4, ModuleEvent.UNINSTALLED, State.UNINSTALLED), new DummyModuleEvent(c6, ModuleEvent.UNRESOLVED, State.INSTALLED), new DummyModuleEvent(c7, ModuleEvent.UNRESOLVED, State.INSTALLED)));
    assertEvents(expected, actual, false);
    // Test bug 411833
    // install c4 again and resolve c6
    c4 = installDummyModule("c4_v1.MF", "c4_v1", container);
    container.resolve(Arrays.asList(c6), true);
    // throw out installed and resolved events
    database.getModuleEvents();
    removalPending = container.getRemovalPending();
    Assert.assertEquals("Wrong number of removal pending", 0, removalPending.size());
    c4Revision0 = c4.getCurrentRevision();
    // uninstall c4, but refresh c6 instead
    // this should result in removal pending c4 to be removed.
    container.uninstall(c4);
    removalPending = container.getRemovalPending();
    Assert.assertEquals("Wrong number of removal pending", 1, removalPending.size());
    Assert.assertTrue("Wrong module removalPending: " + removalPending, removalPending.containsAll(Arrays.asList(c4Revision0)));
    container.refresh(Collections.singletonList(c6));
    actual = database.getModuleEvents();
    expected = new ArrayList<DummyModuleEvent>(Arrays.asList(new DummyModuleEvent(c4, ModuleEvent.UNRESOLVED, State.INSTALLED), new DummyModuleEvent(c4, ModuleEvent.UNINSTALLED, State.UNINSTALLED), new DummyModuleEvent(c6, ModuleEvent.UNRESOLVED, State.INSTALLED), new DummyModuleEvent(c7, ModuleEvent.UNRESOLVED, State.INSTALLED)));
    assertEvents(expected, actual, false);
    removalPending = container.getRemovalPending();
    Assert.assertEquals("Wrong number of removal pending", 0, removalPending.size());
}
Also used : DummyContainerAdaptor(org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor) ModuleContainer(org.eclipse.osgi.container.ModuleContainer) ArrayList(java.util.ArrayList) Module(org.eclipse.osgi.container.Module) DummyModuleEvent(org.eclipse.osgi.tests.container.dummys.DummyModuleDatabase.DummyModuleEvent) ModuleRevision(org.eclipse.osgi.container.ModuleRevision) DummyModuleDatabase(org.eclipse.osgi.tests.container.dummys.DummyModuleDatabase) Test(org.junit.Test)

Example 17 with ModuleRevision

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

the class TestModuleContainer method testSubstitutableExports01.

@Test
public void testSubstitutableExports01() throws BundleException, IOException {
    DummyContainerAdaptor adaptor = createDummyAdaptor();
    ModuleContainer container = adaptor.getContainer();
    Module systemBundle = installDummyModule("system.bundle.MF", Constants.SYSTEM_BUNDLE_LOCATION, container);
    container.resolve(Arrays.asList(systemBundle), true);
    Module sub1 = installDummyModule("sub1_v1.MF", "sub1", container);
    Module sub2 = installDummyModule("sub2_v1.MF", "sub2", container);
    ModuleRevision sub1Revision0 = sub1.getCurrentRevision();
    container.resolve(Arrays.asList(sub2), true);
    container.update(sub1, OSGiManifestBuilderFactory.createBuilder(getManifest("sub1_v2.MF")), null);
    container.resolve(Arrays.asList(sub1), true);
    ModuleWiring sub1Wiring = sub1.getCurrentRevision().getWiring();
    List<BundleCapability> exportedPackages = sub1Wiring.getCapabilities(PackageNamespace.PACKAGE_NAMESPACE);
    Assert.assertEquals("Wrong number of exported packages: " + exportedPackages, 0, exportedPackages.size());
    List<BundleWire> requiredWires = sub1Wiring.getRequiredWires(PackageNamespace.PACKAGE_NAMESPACE);
    Assert.assertEquals("Wrong number of imported packages: ", 2, requiredWires.size());
    Assert.assertEquals("Wrong provider for package: " + requiredWires.get(1).getProvider(), sub1Revision0, requiredWires.get(1).getProvider());
    container.refresh(Arrays.asList(sub1));
    sub1Wiring = sub1.getCurrentRevision().getWiring();
    exportedPackages = sub1Wiring.getCapabilities(PackageNamespace.PACKAGE_NAMESPACE);
    Assert.assertEquals("Wrong number of exported packages: " + exportedPackages, 1, exportedPackages.size());
    requiredWires = sub1Wiring.getRequiredWires(PackageNamespace.PACKAGE_NAMESPACE);
    Assert.assertEquals("Wrong number of imported packages: ", 1, requiredWires.size());
}
Also used : DummyContainerAdaptor(org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor) ModuleContainer(org.eclipse.osgi.container.ModuleContainer) ModuleWiring(org.eclipse.osgi.container.ModuleWiring) Module(org.eclipse.osgi.container.Module) BundleCapability(org.osgi.framework.wiring.BundleCapability) ModuleRevision(org.eclipse.osgi.container.ModuleRevision) BundleWire(org.osgi.framework.wiring.BundleWire) Test(org.junit.Test)

Example 18 with ModuleRevision

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

the class TestModuleContainer method testModuleWiringToString.

@Test
public void testModuleWiringToString() throws BundleException {
    DummyContainerAdaptor adaptor = createDummyAdaptor();
    ModuleContainer container = adaptor.getContainer();
    // install a test module
    Map<String, String> testManifest = new HashMap<String, String>();
    testManifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    testManifest.put(Constants.BUNDLE_SYMBOLICNAME, "test.name");
    testManifest.put(Constants.BUNDLE_VERSION, "1.0");
    Module testModule = installDummyModule(testManifest, "host10", container);
    ResolutionReport report = container.resolve(Arrays.asList(testModule), true);
    Assert.assertNull("Failed to resolve test.", report.getResolutionException());
    ModuleRevision revision = testModule.getCurrentRevision();
    ModuleWiring wiring = revision.getWiring();
    Assert.assertEquals("Unexpected wiring.toString()", revision.toString(), wiring.toString());
}
Also used : DummyContainerAdaptor(org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor) ModuleContainer(org.eclipse.osgi.container.ModuleContainer) HashMap(java.util.HashMap) ModuleWiring(org.eclipse.osgi.container.ModuleWiring) Module(org.eclipse.osgi.container.Module) ResolutionReport(org.eclipse.osgi.report.resolution.ResolutionReport) ModuleRevision(org.eclipse.osgi.container.ModuleRevision) Test(org.junit.Test)

Example 19 with ModuleRevision

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

the class TestModuleContainer method testSimpleResolve.

@Test
public void testSimpleResolve() throws BundleException, IOException {
    DummyContainerAdaptor adaptor = createDummyAdaptor();
    ModuleContainer container = adaptor.getContainer();
    Module systemBundle = installDummyModule("system.bundle.MF", Constants.SYSTEM_BUNDLE_LOCATION, container);
    ModuleRevision systemRevision = systemBundle.getCurrentRevision();
    container.resolve(Arrays.asList(systemBundle), true);
    ModuleWiring systemWiring = systemRevision.getWiring();
    Assert.assertNotNull("system wiring is null", systemWiring);
    Module b1 = installDummyModule("b1_v1.MF", "b1", container);
    ModuleRevision b1Revision = b1.getCurrentRevision();
    container.resolve(Arrays.asList(b1), true);
    ModuleWiring b1Wiring = b1Revision.getWiring();
    Assert.assertNotNull("b1 wiring is null", b1Wiring);
}
Also used : DummyContainerAdaptor(org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor) ModuleContainer(org.eclipse.osgi.container.ModuleContainer) ModuleWiring(org.eclipse.osgi.container.ModuleWiring) Module(org.eclipse.osgi.container.Module) ModuleRevision(org.eclipse.osgi.container.ModuleRevision) Test(org.junit.Test)

Example 20 with ModuleRevision

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

the class Storage method installExtensions.

private void installExtensions() {
    Module systemModule = moduleContainer.getModule(0);
    ModuleRevision systemRevision = systemModule == null ? null : systemModule.getCurrentRevision();
    ModuleWiring systemWiring = systemRevision == null ? null : systemRevision.getWiring();
    if (systemWiring == null) {
        return;
    }
    Collection<ModuleRevision> fragments = new ArrayList<>();
    for (ModuleWire hostWire : systemWiring.getProvidedModuleWires(HostNamespace.HOST_NAMESPACE)) {
        fragments.add(hostWire.getRequirer());
    }
    try {
        getExtensionInstaller().addExtensionContent(fragments, null);
    } catch (BundleException e) {
        getLogServices().log(EquinoxContainer.NAME, FrameworkLogEntry.ERROR, e.getMessage(), e);
    }
}
Also used : ModuleWire(org.eclipse.osgi.container.ModuleWire) ModuleWiring(org.eclipse.osgi.container.ModuleWiring) ArrayList(java.util.ArrayList) BundleException(org.osgi.framework.BundleException) Module(org.eclipse.osgi.container.Module) ModuleRevision(org.eclipse.osgi.container.ModuleRevision)

Aggregations

ModuleRevision (org.eclipse.osgi.container.ModuleRevision)35 Module (org.eclipse.osgi.container.Module)21 Generation (org.eclipse.osgi.storage.BundleInfo.Generation)15 ModuleWiring (org.eclipse.osgi.container.ModuleWiring)12 ArrayList (java.util.ArrayList)9 ModuleContainer (org.eclipse.osgi.container.ModuleContainer)9 ModuleWire (org.eclipse.osgi.container.ModuleWire)9 DummyContainerAdaptor (org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor)8 Test (org.junit.Test)8 BundleException (org.osgi.framework.BundleException)5 IOException (java.io.IOException)4 ModuleCapability (org.eclipse.osgi.container.ModuleCapability)4 File (java.io.File)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 SystemModule (org.eclipse.osgi.container.SystemModule)3 BundleFile (org.eclipse.osgi.storage.bundlefile.BundleFile)3 DirBundleFile (org.eclipse.osgi.storage.bundlefile.DirBundleFile)3 NestedDirBundleFile (org.eclipse.osgi.storage.bundlefile.NestedDirBundleFile)3 ZipBundleFile (org.eclipse.osgi.storage.bundlefile.ZipBundleFile)3