use of org.eclipse.osgi.container.ModuleContainer 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());
}
use of org.eclipse.osgi.container.ModuleContainer 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);
}
use of org.eclipse.osgi.container.ModuleContainer 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());
}
}
use of org.eclipse.osgi.container.ModuleContainer 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()));
}
use of org.eclipse.osgi.container.ModuleContainer in project rt.equinox.framework by eclipse.
the class TestModuleContainer method testInstallCollision02.
@Test
public void testInstallCollision02() throws BundleException, IOException {
DummyContainerAdaptor adaptor = new DummyContainerAdaptor(new DummyCollisionHook(true), Collections.<String, String>emptyMap());
ModuleContainer container = adaptor.getContainer();
installDummyModule("system.bundle.MF", Constants.SYSTEM_BUNDLE_LOCATION, container);
installDummyModule("b1_v1.MF", "b1_a", container);
installDummyModule("b1_v1.MF", "b1_b", container);
}
Aggregations