use of org.eclipse.osgi.container.ModuleContainer 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.ModuleContainer in project rt.equinox.framework by eclipse.
the class TestModuleContainer method testDynamicImport03.
@Test
public void testDynamicImport03() 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 dynamic3 = installDummyModule("dynamic2_v1.MF", "dynamic2_v1", container);
container.resolve(Arrays.asList(systemBundle, dynamic3), true);
ModuleWire dynamicWire = container.resolveDynamic("c1.a", dynamic3.getCurrentRevision());
Assert.assertNull("Dynamic wire found.", dynamicWire);
Module c1v1 = installDummyModule("c1_v1.MF", "c1_v1", container);
database.getModuleEvents();
dynamicWire = container.resolveDynamic("c1.a", dynamic3.getCurrentRevision());
Assert.assertNotNull("Dynamic wire not found.", dynamicWire);
Assert.assertEquals("Wrong package found.", "c1.a", dynamicWire.getCapability().getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE));
Assert.assertEquals("Wrong provider for the wire found.", c1v1.getCurrentRevision(), dynamicWire.getProvider());
ModuleWiring c1v1Wiring = c1v1.getCurrentRevision().getWiring();
Assert.assertNotNull("c1 wiring is null.", c1v1Wiring);
Module c1v2 = installDummyModule("c1_v2.MF", "c1_v2", container);
container.resolve(Arrays.asList(c1v2), true);
database.getModuleEvents();
dynamicWire = container.resolveDynamic("c1.b", dynamic3.getCurrentRevision());
Assert.assertNotNull("Dynamic wire not found.", dynamicWire);
Assert.assertEquals("Wrong package found.", "c1.b", dynamicWire.getCapability().getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE));
Assert.assertEquals("Wrong provider.", c1v1.getCurrentRevision(), dynamicWire.getProvider());
}
use of org.eclipse.osgi.container.ModuleContainer in project rt.equinox.framework by eclipse.
the class TestModuleContainer method testSystemBundleFragmentsWithPayloadRequirements.
@Test
public void testSystemBundleFragmentsWithPayloadRequirements() throws BundleException, IOException {
// install the system.bundle
Module systemBundle = createContainerWithSystemBundle(true);
ModuleContainer container = systemBundle.getContainer();
// install an system.bundle fragment that requires a payload requirement from system.bundle
Map<String, String> systemFragManifest = new HashMap<String, String>();
systemFragManifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
systemFragManifest.put(Constants.BUNDLE_SYMBOLICNAME, "systemFrag");
systemFragManifest.put(Constants.FRAGMENT_HOST, Constants.SYSTEM_BUNDLE_SYMBOLICNAME);
systemFragManifest.put(Constants.REQUIRE_CAPABILITY, "equinox.test; filter:=\"(equinox.test=system)\"");
Module systemFrag = installDummyModule(systemFragManifest, "systemFrag", container);
ResolutionReport report = container.resolve(Arrays.asList(systemFrag), true);
Assert.assertNull("Failed to resolve system.bundle.", report.getResolutionException());
List<ModuleWire> hostWires = systemBundle.getCurrentRevision().getWiring().getProvidedModuleWires(HostNamespace.HOST_NAMESPACE);
assertEquals("Wrong number of fragments.", 1, hostWires.size());
Assert.assertEquals("Unexpected fragment revision: " + hostWires, systemFrag.getCurrentRevision(), hostWires.get(0).getRequirer());
List<ModuleWire> systemBundleRequiredWires = systemBundle.getCurrentRevision().getWiring().getRequiredModuleWires(null);
assertEquals("Wrong number of wires.", 1, systemBundleRequiredWires.size());
assertEquals("Wrong requirer.", systemBundle.getCurrentRevision(), systemBundleRequiredWires.get(0).getRequirer());
assertEquals("Wrong requirement.", systemFrag.getCurrentRevision(), systemBundleRequiredWires.get(0).getRequirement().getRevision());
List<ModuleWire> fragRequiredWires = systemFrag.getCurrentRevision().getWiring().getRequiredModuleWires(null);
assertEquals("Wrong number of required wires.", 1, fragRequiredWires.size());
assertWires(fragRequiredWires, hostWires);
}
use of org.eclipse.osgi.container.ModuleContainer in project rt.equinox.framework by eclipse.
the class TestModuleContainer method testPersistence.
@Test
public void testPersistence() throws BundleException, IOException {
DummyContainerAdaptor adaptor = createDummyAdaptor();
ModuleContainer container = adaptor.getContainer();
// install the system.bundle
installDummyModule("system.bundle.MF", Constants.SYSTEM_BUNDLE_LOCATION, Constants.SYSTEM_BUNDLE_SYMBOLICNAME, null, null, container);
Map<String, Object> attrs = new HashMap<String, Object>();
attrs.put("string", "sValue");
attrs.put("string.list1", Arrays.asList("v1", "v2", "v3"));
attrs.put("string.list2", Arrays.asList("v4", "v5", "v6"));
attrs.put("version", Version.valueOf("1.1"));
attrs.put("version.list", Arrays.asList(Version.valueOf("1.0"), Version.valueOf("2.0"), Version.valueOf("3.0")));
attrs.put("long", Long.valueOf(12345));
attrs.put("long.list", Arrays.asList(Long.valueOf(1), Long.valueOf(2), Long.valueOf(3)));
attrs.put("double", Double.valueOf(1.2345));
attrs.put("double.list", Arrays.asList(Double.valueOf(1.1), Double.valueOf(1.2), Double.valueOf(1.3)));
attrs.put("uri", "some.uri");
attrs.put("set", Arrays.asList("s1", "s2", "s3"));
// provider with all supported types
Map<String, String> providerManifest = new HashMap<String, String>();
providerManifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
providerManifest.put(Constants.BUNDLE_SYMBOLICNAME, "provider");
providerManifest.put(Constants.EXPORT_PACKAGE, "provider; version=1.1; attr1=attr1; attr2=attr2; dir1:=dir1; dir2:=dir2");
providerManifest.put(Constants.PROVIDE_CAPABILITY, //
"provider.cap;" + //
" string=sValue;" + //
" string.list1:List=\"v1,v2,v3\";" + //
" string.list2:List<String>=\"v4,v5,v6\";" + //
" version:Version=1.1;" + //
" version.list:List<Version>=\"1.0,2.0,3.0\";" + //
" long:Long=12345;" + //
" long.list:List<Long>=\"1,2,3\";" + //
" double:Double=1.2345;" + //
" double.list:List<Double>=\"1.1,1.2,1.3\";" + //
" uri:uri=some.uri;" + " set:set=\"s1,s2,s3\"");
Module providerModule = installDummyModule(providerManifest, "provider", container);
Map<String, Object> providerAttrs = providerModule.getCurrentRevision().getCapabilities("provider.cap").get(0).getAttributes();
assertEquals("Wrong provider attrs", attrs, providerAttrs);
Map<String, String> requirerManifest = new HashMap<String, String>();
requirerManifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
requirerManifest.put(Constants.BUNDLE_SYMBOLICNAME, "requirer");
requirerManifest.put(Constants.IMPORT_PACKAGE, "provider; version=1.1; attr1=attr1; attr2=attr2; dir1:=dir1; dir2:=dir2");
requirerManifest.put(Constants.REQUIRE_CAPABILITY, //
"optional;" + //
" resolution:=optional; " + //
" string=sValue;" + //
" string.list1:List=\"v1,v2,v3\";" + //
" string.list2:List<String>=\"v4,v5,v6\";" + //
" version:Version=1.1;" + //
" version.list:List<Version>=\"1.0,2.0,3.0\";" + //
" long:Long=12345;" + //
" long.list:List<Long>=\"1,2,3\";" + //
" double:Double=1.2345;" + //
" double.list:List<Double>=\"1.1,1.2,1.3\";" + //
" uri:uri=some.uri;" + //
" set:set=\"s1,s2,s3\"," + //
"provider.cap; filter:=\"(string=sValue)\"," + //
"provider.cap; filter:=\"(string.list1=v2)\"," + //
"provider.cap; filter:=\"(string.list2=v5)\"," + //
"provider.cap; filter:=\"(string.list2=v5)\"," + //
"provider.cap; filter:=\"(&(version>=1.1)(version<=1.1.1))\"," + //
"provider.cap; filter:=\"(&(version.list=1)(version.list=2))\"," + //
"provider.cap; filter:=\"(long>=12344)\"," + //
"provider.cap; filter:=\"(long.list=2)\"," + //
"provider.cap; filter:=\"(double>=1.2)\"," + //
"provider.cap; filter:=\"(double.list=1.2)\"," + //
"provider.cap; filter:=\"(uri=some.uri)\"," + //
"provider.cap; filter:=\"(set=s2)\"" + "");
Module requirerModule = installDummyModule(requirerManifest, "requirer", container);
Map<String, Object> requirerAttrs = requirerModule.getCurrentRevision().getRequirements("optional").get(0).getAttributes();
assertEquals("Wrong requirer attrs", attrs, requirerAttrs);
ResolutionReport report = container.resolve(Collections.singleton(requirerModule), true);
assertNull("Error resolving.", report.getResolutionException());
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
DataOutputStream data = new DataOutputStream(bytes);
adaptor.getDatabase().store(data, true);
// reload into a new container
adaptor = createDummyAdaptor();
container = adaptor.getContainer();
adaptor.getDatabase().load(new DataInputStream(new ByteArrayInputStream(bytes.toByteArray())));
providerModule = container.getModule("provider");
providerAttrs = providerModule.getCurrentRevision().getCapabilities("provider.cap").get(0).getAttributes();
assertEquals("Wrong provider attrs", attrs, providerAttrs);
assertNotNull("No provider found.", providerModule);
requirerModule = container.getModule("requirer");
assertNotNull("No requirer found.", requirerModule);
requirerAttrs = requirerModule.getCurrentRevision().getRequirements("optional").get(0).getAttributes();
assertEquals("Wrong requirer attrs", attrs, requirerAttrs);
}
use of org.eclipse.osgi.container.ModuleContainer in project rt.equinox.framework by eclipse.
the class TestModuleContainer method testDynamicImport01.
@Test
public void testDynamicImport01() 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 dynamic1 = installDummyModule("dynamic1_v1.MF", "dynamic1_v1", container);
container.resolve(Arrays.asList(c1, dynamic1), true);
ModuleWire dynamicWire = container.resolveDynamic("org.osgi.framework", dynamic1.getCurrentRevision());
Assert.assertNotNull("No dynamic wire found.", dynamicWire);
Assert.assertEquals("Wrong package found.", "org.osgi.framework", dynamicWire.getCapability().getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE));
Assert.assertEquals("Wrong provider for the wire found.", systemBundle.getCurrentRevision(), dynamicWire.getProvider());
dynamicWire = container.resolveDynamic("org.osgi.framework.wiring", dynamic1.getCurrentRevision());
Assert.assertNotNull("No dynamic wire found.", dynamicWire);
Assert.assertEquals("Wrong package found.", "org.osgi.framework.wiring", dynamicWire.getCapability().getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE));
Assert.assertEquals("Wrong provider for the wire found.", systemBundle.getCurrentRevision(), dynamicWire.getProvider());
dynamicWire = container.resolveDynamic("c1.b", dynamic1.getCurrentRevision());
Assert.assertNotNull("No dynamic wire found.", dynamicWire);
Assert.assertEquals("Wrong package found.", "c1.b", dynamicWire.getCapability().getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE));
Assert.assertEquals("Wrong provider for the wire found.", c1.getCurrentRevision(), dynamicWire.getProvider());
}
Aggregations