Search in sources :

Example 6 with ResolutionReport

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

the class TestModuleContainer method testStartLevelDeadlock.

@Test
public void testStartLevelDeadlock() throws BundleException, IOException {
    DummyContainerAdaptor adaptor = createDummyAdaptor();
    ModuleContainer container = adaptor.getContainer();
    container.getFrameworkStartLevel().setInitialBundleStartLevel(2);
    // 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 module
    Map<String, String> manifest = new HashMap<String, String>();
    manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    manifest.put(Constants.BUNDLE_SYMBOLICNAME, "module.test");
    Module module = installDummyModule(manifest, manifest.get(Constants.BUNDLE_SYMBOLICNAME), container);
    adaptor.setSlowdownEvents(true);
    module.setStartLevel(1);
    module.start();
    List<DummyContainerEvent> events = adaptor.getDatabase().getContainerEvents();
    for (DummyContainerEvent event : events) {
        Assert.assertNotEquals("Found an error: " + event.error, ContainerEvent.ERROR, event.type);
    }
}
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) DummyContainerEvent(org.eclipse.osgi.tests.container.dummys.DummyModuleDatabase.DummyContainerEvent) Test(org.junit.Test)

Example 7 with ResolutionReport

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

the class TestModuleContainer method testDynamicWithOptionalImport.

@Test
public void testDynamicWithOptionalImport() 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.IMPORT_PACKAGE, "exporter; resolution:=optional");
    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));
    // install a exporter to satisfy existing optional import
    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");
    installDummyModule(exporterManifest, "exporter", container);
    ModuleWire dynamicWire = container.resolveDynamic("exporter", optionalImporterModule.getCurrentRevision());
    Assert.assertNotNull("Expected to find a dynamic wire.", dynamicWire);
    // re-resolve importer
    container.refresh(Collections.singleton(optionalImporterModule));
    report = container.resolve(Arrays.asList(optionalImporterModule), true);
    Assert.assertNull("Failed to resolve system.bundle.", report.getResolutionException());
    importReqsList = optionalImporterModule.getCurrentRevision().getWiring().getRequirements(PackageNamespace.PACKAGE_NAMESPACE);
    assertEquals("Wrong number of imports.", 2, importReqsList.size());
}
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 8 with ResolutionReport

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

the class TestModuleContainer method testNativeWithFilterChars.

@Test
public void testNativeWithFilterChars() throws BundleException, IOException {
    DummyContainerAdaptor adaptor = createDummyAdaptor();
    ModuleContainer container = adaptor.getContainer();
    // install the system.bundle
    String extraCapabilities = "osgi.native; osgi.native.osname=\"Windows NT (unknown)\"";
    Module systemBundle = installDummyModule("system.bundle.MF", Constants.SYSTEM_BUNDLE_LOCATION, Constants.SYSTEM_BUNDLE_SYMBOLICNAME, null, extraCapabilities, container);
    ResolutionReport report = container.resolve(Arrays.asList(systemBundle), true);
    Assert.assertNull("Failed to resolve system.bundle.", report.getResolutionException());
    // install bundle with Bundle-NativeCode
    Map<String, String> nativeCodeManifest = new HashMap<String, String>();
    nativeCodeManifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    nativeCodeManifest.put(Constants.BUNDLE_SYMBOLICNAME, "importer");
    // 
    nativeCodeManifest.put(// 
    Constants.BUNDLE_NATIVECODE, // 
    "/lib/mylib.dll; osname=\"win32\"; osname=\"Windows NT (unknown)\"," + "/lib/mylib.lib; osname=\"Linux\"");
    Module nativeCodeModule = installDummyModule(nativeCodeManifest, "nativeCodeBundle", container);
    // unsatisfied optional and dynamic imports do not fail a resolve.
    report = container.resolve(Arrays.asList(nativeCodeModule), true);
    Assert.assertNull("Failed to resolve nativeCodeBundle.", 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 9 with ResolutionReport

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

the class TestModuleContainer method testSystemBundleOnDemandFragments.

@Test
public void testSystemBundleOnDemandFragments() 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);
    // install an equinox fragment
    Map<String, String> equinoxFragManifest = new HashMap<String, String>();
    equinoxFragManifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    equinoxFragManifest.put(Constants.BUNDLE_SYMBOLICNAME, "equinoxFrag");
    equinoxFragManifest.put(Constants.FRAGMENT_HOST, "org.eclipse.osgi");
    Module equinoxFrag = installDummyModule(equinoxFragManifest, "equinoxFrag", container);
    // install a system.bundle fragment
    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, "system.bundle");
    Module systemFrag = installDummyModule(systemFragManifest, "systemFrag", container);
    ResolutionReport report = container.resolve(Arrays.asList(systemBundle), 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());
    Set<ModuleRevision> fragmentRevisions = new HashSet(Arrays.asList(equinoxFrag.getCurrentRevision(), systemFrag.getCurrentRevision()));
    for (ModuleWire hostWire : hostWires) {
        if (!fragmentRevisions.remove(hostWire.getRequirer())) {
            Assert.fail("Unexpected fragment revision: " + hostWire.getRequirer());
        }
    }
}
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) ModuleRevision(org.eclipse.osgi.container.ModuleRevision) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 10 with ResolutionReport

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

the class TestModuleContainer method testMultiHost.

@Test
public void testMultiHost() throws BundleException, IOException {
    DummyContainerAdaptor adaptor = createDummyAdaptor();
    ModuleContainer container = adaptor.getContainer();
    installDummyModule("system.bundle.MF", Constants.SYSTEM_BUNDLE_LOCATION, container);
    Module h1v1 = installDummyModule("h1_v1.MF", "h1_v1", container);
    Module h1v2 = installDummyModule("h1_v2.MF", "h1_v2", container);
    Module f1v1 = installDummyModule("f1_v1.MF", "f1_v1", container);
    Module b3 = installDummyModule("b3_v1.MF", "b3_v1", container);
    ResolutionReport report = container.resolve(Arrays.asList(h1v1, h1v2, f1v1, b3), true);
    Assert.assertNull("Expected no resolution exception.", report.getResolutionException());
}
Also used : DummyContainerAdaptor(org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor) ModuleContainer(org.eclipse.osgi.container.ModuleContainer) 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