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());
}
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());
}
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());
}
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);
}
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);
}
}
Aggregations