Search in sources :

Example 11 with ResolutionReport

use of org.eclipse.osgi.report.resolution.ResolutionReport in project rt.equinox.framework by eclipse.

the class TestModuleContainer method testDynamicWithExport.

@Test
public void testDynamicWithExport() 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 importer
    Map<String, String> optionalImporterManifest = new HashMap<String, String>();
    optionalImporterManifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    optionalImporterManifest.put(Constants.BUNDLE_SYMBOLICNAME, "importer");
    optionalImporterManifest.put(Constants.EXPORT_PACKAGE, "exporter");
    optionalImporterManifest.put(Constants.DYNAMICIMPORT_PACKAGE, "exporter");
    Module optionalImporterModule = installDummyModule(optionalImporterManifest, "optionalImporter", container);
    // unsatisfied optional and dynamic imports do not fail a resolve.
    report = container.resolve(Arrays.asList(optionalImporterModule), true);
    Assert.assertNull("Failed to resolve system.bundle.", report.getResolutionException());
    // dynamic and optional imports are same. Optional import is not satisfied we should only see the dynamic import
    List<BundleRequirement> importReqsList = optionalImporterModule.getCurrentRevision().getWiring().getRequirements(PackageNamespace.PACKAGE_NAMESPACE);
    assertEquals("Wrong number of imports.", 1, importReqsList.size());
    assertEquals("Import was not dynamic", PackageNamespace.RESOLUTION_DYNAMIC, importReqsList.get(0).getDirectives().get(Namespace.REQUIREMENT_RESOLUTION_DIRECTIVE));
    ModuleWire dynamicWire = container.resolveDynamic("exporter", optionalImporterModule.getCurrentRevision());
    Assert.assertNull("Expected no dynamic wire.", dynamicWire);
}
Also used : DummyContainerAdaptor(org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor) ModuleWire(org.eclipse.osgi.container.ModuleWire) ModuleContainer(org.eclipse.osgi.container.ModuleContainer) HashMap(java.util.HashMap) Module(org.eclipse.osgi.container.Module) ResolutionReport(org.eclipse.osgi.report.resolution.ResolutionReport) BundleRequirement(org.osgi.framework.wiring.BundleRequirement) Test(org.junit.Test)

Example 12 with ResolutionReport

use of org.eclipse.osgi.report.resolution.ResolutionReport in project rt.equinox.framework by eclipse.

the class TestModuleContainer method testSystemBundleFragmentRequiresOtherFragment.

@Test
public void testSystemBundleFragmentRequiresOtherFragment() throws BundleException, IOException {
    // install the system.bundle
    Module systemBundle = createContainerWithSystemBundle(true);
    ModuleContainer container = systemBundle.getContainer();
    // install an system.bundle fragment that provides a capability
    Map<String, String> systemFragManifest1 = new HashMap<String, String>();
    systemFragManifest1.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    systemFragManifest1.put(Constants.BUNDLE_SYMBOLICNAME, "systemFrag1");
    systemFragManifest1.put(Constants.FRAGMENT_HOST, Constants.SYSTEM_BUNDLE_SYMBOLICNAME);
    systemFragManifest1.put(Constants.PROVIDE_CAPABILITY, "fragment.capability; fragment.capability=test");
    Module systemFrag1 = installDummyModule(systemFragManifest1, "systemFrag1", container);
    // install an system.bundle fragment that requires a fragment capability
    Map<String, String> systemFragManifest2 = new HashMap<String, String>();
    systemFragManifest2.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    systemFragManifest2.put(Constants.BUNDLE_SYMBOLICNAME, "systemFrag2");
    systemFragManifest2.put(Constants.FRAGMENT_HOST, Constants.SYSTEM_BUNDLE_SYMBOLICNAME);
    systemFragManifest2.put(Constants.REQUIRE_CAPABILITY, "fragment.capability; filter:=\"(fragment.capability=test)\"");
    Module systemFrag2 = installDummyModule(systemFragManifest2, "systemFrag2", container);
    ResolutionReport report = container.resolve(Arrays.asList(systemFrag2), 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.", 2, hostWires.size());
    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.", systemFrag2.getCurrentRevision(), systemBundleRequiredWires.get(0).getRequirement().getRevision());
    assertEquals("Wrong provider.", systemBundle.getCurrentRevision(), systemBundleRequiredWires.get(0).getProvider());
    assertEquals("Wrong capability.", systemFrag1.getCurrentRevision(), systemBundleRequiredWires.get(0).getCapability().getRevision());
    List<ModuleWire> fragRequiredWires = systemFrag2.getCurrentRevision().getWiring().getRequiredModuleWires(null);
    assertEquals("Wrong number of required wires.", 1, fragRequiredWires.size());
    assertWires(fragRequiredWires, hostWires);
}
Also used : ModuleWire(org.eclipse.osgi.container.ModuleWire) ModuleContainer(org.eclipse.osgi.container.ModuleContainer) HashMap(java.util.HashMap) Module(org.eclipse.osgi.container.Module) ResolutionReport(org.eclipse.osgi.report.resolution.ResolutionReport) Test(org.junit.Test)

Example 13 with ResolutionReport

use of org.eclipse.osgi.report.resolution.ResolutionReport in project rt.equinox.framework by eclipse.

the class TestModuleContainer method testMultipleSystemBundleFragmentsWithSameName.

@Test
public void testMultipleSystemBundleFragmentsWithSameName() throws BundleException, IOException {
    // install the system.bundle
    Module systemBundle = createContainerWithSystemBundle(true);
    ModuleContainer container = systemBundle.getContainer();
    // install multiple versions of the same fragment
    Map<String, String> systemFragManifest1 = new HashMap<String, String>();
    systemFragManifest1.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    systemFragManifest1.put(Constants.BUNDLE_SYMBOLICNAME, "systemFrag");
    systemFragManifest1.put(Constants.BUNDLE_VERSION, "1.0");
    systemFragManifest1.put(Constants.FRAGMENT_HOST, Constants.SYSTEM_BUNDLE_SYMBOLICNAME);
    Module systemFrag1 = installDummyModule(systemFragManifest1, "systemFrag1", container);
    // first attempt to resolve the lowest version before installing the others
    ResolutionReport report = container.resolve(Arrays.asList(systemFrag1), true);
    Assert.assertNull("Unexpected failure message", report.getResolutionException());
    List<ModuleWire> hostWires = systemBundle.getCurrentRevision().getWiring().getProvidedModuleWires(HostNamespace.HOST_NAMESPACE);
    assertEquals("Wrong number of fragments.", 1, hostWires.size());
    List<ModuleWire> systemFrag1HostWires = systemFrag1.getCurrentRevision().getWiring().getRequiredModuleWires(HostNamespace.HOST_NAMESPACE);
    assertWires(systemFrag1HostWires, hostWires);
    Map<String, String> systemFragManifest2 = new HashMap<String, String>();
    systemFragManifest2.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    systemFragManifest2.put(Constants.BUNDLE_SYMBOLICNAME, "systemFrag");
    systemFragManifest2.put(Constants.BUNDLE_VERSION, "2.0");
    systemFragManifest2.put(Constants.FRAGMENT_HOST, Constants.SYSTEM_BUNDLE_SYMBOLICNAME);
    Module systemFrag2 = installDummyModule(systemFragManifest2, "systemFrag2", container);
    Map<String, String> systemFragManifest3 = new HashMap<String, String>();
    systemFragManifest3.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    systemFragManifest3.put(Constants.BUNDLE_SYMBOLICNAME, "systemFrag");
    systemFragManifest3.put(Constants.BUNDLE_VERSION, "3.0");
    systemFragManifest3.put(Constants.FRAGMENT_HOST, Constants.SYSTEM_BUNDLE_SYMBOLICNAME);
    Module systemFrag3 = installDummyModule(systemFragManifest3, "systemFrag3", container);
    report = container.resolve(Arrays.asList(systemFrag2), true);
    Assert.assertNotNull("Expected failure message", report.getResolutionException());
    report = container.resolve(Arrays.asList(systemFrag3), true);
    Assert.assertNotNull("Expected failure message", report.getResolutionException());
    hostWires = systemBundle.getCurrentRevision().getWiring().getProvidedModuleWires(HostNamespace.HOST_NAMESPACE);
    assertEquals("Wrong number of fragments.", 1, hostWires.size());
    systemFrag1HostWires = systemFrag1.getCurrentRevision().getWiring().getRequiredModuleWires(HostNamespace.HOST_NAMESPACE);
    assertWires(systemFrag1HostWires, hostWires);
    // uninstall the fragments so we can start over
    container.uninstall(systemFrag1);
    container.uninstall(systemFrag2);
    container.uninstall(systemFrag3);
    // refresh the system bundle to get only it resolved
    report = container.refresh(Collections.singleton(systemBundle));
    Assert.assertNull("Unexpected failure message", report.getResolutionException());
    hostWires = systemBundle.getCurrentRevision().getWiring().getProvidedModuleWires(HostNamespace.HOST_NAMESPACE);
    assertEquals("Wrong number of fragments.", 0, hostWires.size());
    // install the fragments again
    systemFrag1 = installDummyModule(systemFragManifest1, "systemFrag1", container);
    systemFrag2 = installDummyModule(systemFragManifest2, "systemFrag2", container);
    systemFrag3 = installDummyModule(systemFragManifest3, "systemFrag3", container);
    report = container.resolve(Arrays.asList(systemFrag1), true);
    Assert.assertNotNull("Expected failure message", report.getResolutionException());
    report = container.resolve(Arrays.asList(systemFrag2), true);
    Assert.assertNotNull("Expected failure message", report.getResolutionException());
    report = container.resolve(Arrays.asList(systemFrag3), true);
    Assert.assertNull("Unexpected failure message", report.getResolutionException());
    hostWires = systemBundle.getCurrentRevision().getWiring().getProvidedModuleWires(HostNamespace.HOST_NAMESPACE);
    List<ModuleWire> systemFrag3HostWires = systemFrag3.getCurrentRevision().getWiring().getRequiredModuleWires(HostNamespace.HOST_NAMESPACE);
    assertWires(systemFrag3HostWires, hostWires);
}
Also used : ModuleWire(org.eclipse.osgi.container.ModuleWire) ModuleContainer(org.eclipse.osgi.container.ModuleContainer) HashMap(java.util.HashMap) Module(org.eclipse.osgi.container.Module) ResolutionReport(org.eclipse.osgi.report.resolution.ResolutionReport) Test(org.junit.Test)

Example 14 with ResolutionReport

use of org.eclipse.osgi.report.resolution.ResolutionReport in project rt.equinox.framework by eclipse.

the class TestModuleContainer method testUnresolvedHostWithFragmentCycle.

@Test
public void testUnresolvedHostWithFragmentCycle() throws BundleException {
    DummyContainerAdaptor adaptor = createDummyAdaptor();
    ModuleContainer container = adaptor.getContainer();
    // install a host
    Map<String, String> hostManifest = new HashMap<String, String>();
    hostManifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    hostManifest.put(Constants.BUNDLE_SYMBOLICNAME, "host");
    hostManifest.put(Constants.BUNDLE_VERSION, "1.0");
    hostManifest.put(Constants.EXPORT_PACKAGE, "host");
    hostManifest.put(Constants.IMPORT_PACKAGE, "host.impl");
    installDummyModule(hostManifest, "host10", container);
    hostManifest.put(Constants.BUNDLE_VERSION, "1.1");
    installDummyModule(hostManifest, "host11", container);
    hostManifest.put(Constants.BUNDLE_VERSION, "1.2");
    installDummyModule(hostManifest, "host12", container);
    // hostManifest.put(Constants.BUNDLE_VERSION, "1.3");
    // installDummyModule(hostManifest, "host13", container);
    // install a host.impl fragment
    Map<String, String> hostImplManifest = new HashMap<String, String>();
    hostImplManifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    hostImplManifest.put(Constants.BUNDLE_SYMBOLICNAME, "host.impl");
    hostImplManifest.put(Constants.EXPORT_PACKAGE, "host.impl");
    hostImplManifest.put(Constants.IMPORT_PACKAGE, "host");
    hostImplManifest.put(Constants.FRAGMENT_HOST, "host");
    installDummyModule(hostImplManifest, "hostImpl", container);
    // install an importer of host package
    Map<String, String> hostImporterManifest = new HashMap<String, String>();
    hostImporterManifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    hostImporterManifest.put(Constants.BUNDLE_SYMBOLICNAME, "host.importer");
    hostImporterManifest.put(Constants.IMPORT_PACKAGE, "host");
    Module hostImporter = installDummyModule(hostImporterManifest, "hostImporter", container);
    ResolutionReport report = container.resolve(Arrays.asList(hostImporter), true);
    Assert.assertNull("Failed to resolve test.", report.getResolutionException());
}
Also used : DummyContainerAdaptor(org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor) ModuleContainer(org.eclipse.osgi.container.ModuleContainer) HashMap(java.util.HashMap) Module(org.eclipse.osgi.container.Module) ResolutionReport(org.eclipse.osgi.report.resolution.ResolutionReport) Test(org.junit.Test)

Example 15 with ResolutionReport

use of org.eclipse.osgi.report.resolution.ResolutionReport in project rt.equinox.framework by eclipse.

the class TestModuleContainer method testSystemBundleFragmentsPackageImport.

@Test
public void testSystemBundleFragmentsPackageImport() throws BundleException, IOException {
    // install the system.bundle
    Module systemBundle = createContainerWithSystemBundle(true);
    ModuleContainer container = systemBundle.getContainer();
    // install an system.bundle fragment that imports framework package
    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.IMPORT_PACKAGE, "org.osgi.framework");
    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("No required wires expected.", 0, systemBundleRequiredWires.size());
}
Also used : ModuleWire(org.eclipse.osgi.container.ModuleWire) ModuleContainer(org.eclipse.osgi.container.ModuleContainer) HashMap(java.util.HashMap) Module(org.eclipse.osgi.container.Module) ResolutionReport(org.eclipse.osgi.report.resolution.ResolutionReport) Test(org.junit.Test)

Aggregations

ResolutionReport (org.eclipse.osgi.report.resolution.ResolutionReport)42 Module (org.eclipse.osgi.container.Module)37 ModuleContainer (org.eclipse.osgi.container.ModuleContainer)36 Test (org.junit.Test)33 DummyContainerAdaptor (org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor)23 HashMap (java.util.HashMap)22 ModuleWire (org.eclipse.osgi.container.ModuleWire)13 ModuleWiring (org.eclipse.osgi.container.ModuleWiring)6 ArrayList (java.util.ArrayList)4 BundleRequirement (org.osgi.framework.wiring.BundleRequirement)4 BundleException (org.osgi.framework.BundleException)3 HashSet (java.util.HashSet)2 ExecutorService (java.util.concurrent.ExecutorService)2 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)2 ModuleRevision (org.eclipse.osgi.container.ModuleRevision)2 DummyCollisionHook (org.eclipse.osgi.tests.container.dummys.DummyCollisionHook)2 DummyContainerEvent (org.eclipse.osgi.tests.container.dummys.DummyModuleDatabase.DummyContainerEvent)2 BundleCapability (org.osgi.framework.wiring.BundleCapability)2 ResolutionException (org.osgi.service.resolver.ResolutionException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1