Search in sources :

Example 61 with DummyContainerAdaptor

use of org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor in project rt.equinox.framework by eclipse.

the class TestModuleContainer method getDatabase.

private DummyModuleDatabase getDatabase() throws BundleException {
    BundleContext context = ((BundleReference) getClass().getClassLoader()).getBundle().getBundleContext();
    DummyContainerAdaptor adaptor = createDummyAdaptor();
    final ModuleContainer container = adaptor.getContainer();
    Bundle systemBundle = context.getBundle(0);
    String extraPackages = context.getProperty(Constants.FRAMEWORK_SYSTEMPACKAGES);
    String extraCapabilities = context.getProperty(Constants.FRAMEWORK_SYSTEMCAPABILITIES);
    extraCapabilities = (extraCapabilities == null ? "" : (extraCapabilities + ", "));
    String osName = context.getProperty(OSGI_OS);
    String wsName = context.getProperty(OSGI_WS);
    String archName = context.getProperty(OSGI_ARCH);
    extraCapabilities += EclipsePlatformNamespace.ECLIPSE_PLATFORM_NAMESPACE + "; " + OSGI_OS + "=" + osName + "; " + OSGI_WS + "=" + wsName + "; " + OSGI_ARCH + "=" + archName;
    ModuleRevisionBuilder systembuilder = OSGiManifestBuilderFactory.createBuilder(asMap(systemBundle.getHeaders("")), Constants.SYSTEM_BUNDLE_SYMBOLICNAME, extraPackages, extraCapabilities);
    container.install(null, systemBundle.getLocation(), systembuilder, null);
    final List<Throwable> installErrors = new ArrayList<Throwable>(0);
    // just trying to pound the container with a bunch of installs
    ExecutorService executor = Executors.newFixedThreadPool(10);
    Bundle[] bundles = context.getBundles();
    for (final Bundle bundle : bundles) {
        if (bundle.getBundleId() == 0)
            continue;
        executor.execute(new Runnable() {

            @Override
            public void run() {
                try {
                    ModuleRevisionBuilder builder = OSGiManifestBuilderFactory.createBuilder(asMap(bundle.getHeaders("")));
                    container.install(null, bundle.getLocation(), builder, null);
                } catch (Throwable t) {
                    t.printStackTrace();
                    synchronized (installErrors) {
                        installErrors.add(t);
                    }
                }
            }
        });
    }
    executor.shutdown();
    try {
        executor.awaitTermination(2, TimeUnit.MINUTES);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    synchronized (installErrors) {
        if (!installErrors.isEmpty()) {
            Assert.assertNull("Unexpected install errors.", installErrors);
        }
    }
    container.resolve(new ArrayList<Module>(), false);
    List<Module> modules = container.getModules();
    for (Module module : modules) {
        if (module.getCurrentRevision().getWiring() == null) {
            System.out.println("Could not resolve module: " + module.getCurrentRevision());
        }
    }
    return adaptor.getDatabase();
}
Also used : ModuleContainer(org.eclipse.osgi.container.ModuleContainer) Bundle(org.osgi.framework.Bundle) ArrayList(java.util.ArrayList) DummyContainerAdaptor(org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ExecutorService(java.util.concurrent.ExecutorService) ModuleRevisionBuilder(org.eclipse.osgi.container.ModuleRevisionBuilder) Module(org.eclipse.osgi.container.Module) BundleContext(org.osgi.framework.BundleContext)

Example 62 with DummyContainerAdaptor

use of org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor in project rt.equinox.framework by eclipse.

the class TestModuleContainer method testFragments01.

@Test
public void testFragments01() throws BundleException, IOException {
    DummyContainerAdaptor adaptor = createDummyAdaptor();
    ModuleContainer container = adaptor.getContainer();
    Module systemModule = installDummyModule("system.bundle.MF", Constants.SYSTEM_BUNDLE_LOCATION, container);
    Module c1 = installDummyModule("c1_v1.MF", "c1_v1", container);
    Module h2 = installDummyModule("h2_v1.MF", "h2_v1", container);
    Module f2 = installDummyModule("f2_v1.MF", "f2_v1", container);
    container.resolve(Arrays.asList(systemModule, c1, h2, f2), true);
    ModuleWiring wiring = h2.getCurrentRevision().getWiring();
    List<ModuleWire> requiredWires = wiring.getRequiredModuleWires(null);
    Assert.assertEquals("Wrong number of required wires.", 3, requiredWires.size());
    for (ModuleWire wire : requiredWires) {
        ModuleCapability capability = wire.getCapability();
        Assert.assertEquals("Wrong namespace.", PackageNamespace.PACKAGE_NAMESPACE, capability.getNamespace());
        Assert.assertEquals("Wrong requirer.", h2.getCurrentRevision(), wire.getRequirer());
        String pkgName = (String) capability.getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE);
        Assert.assertNotNull("No package name.", pkgName);
        ModuleRevision expectedReqRevision;
        if (pkgName.equals("org.osgi.framework")) {
            expectedReqRevision = h2.getCurrentRevision();
        } else {
            expectedReqRevision = f2.getCurrentRevision();
        }
        Assert.assertEquals("Wrong requirement revision.", expectedReqRevision, wire.getRequirement().getRevision());
    }
}
Also used : DummyContainerAdaptor(org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor) ModuleWire(org.eclipse.osgi.container.ModuleWire) ModuleContainer(org.eclipse.osgi.container.ModuleContainer) ModuleWiring(org.eclipse.osgi.container.ModuleWiring) ModuleCapability(org.eclipse.osgi.container.ModuleCapability) Module(org.eclipse.osgi.container.Module) ModuleRevision(org.eclipse.osgi.container.ModuleRevision) Test(org.junit.Test)

Example 63 with DummyContainerAdaptor

use of org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor in project rt.equinox.framework by eclipse.

the class TestModuleContainer method testSubstitutableExports04.

@Test
public void testSubstitutableExports04() throws BundleException, IOException {
    DummyContainerAdaptor adaptor = createDummyAdaptor();
    ModuleContainer container = adaptor.getContainer();
    // install order does not really matter
    installDummyModule("sub.h.MF", "h", container);
    Module i = installDummyModule("sub.i.MF", "i", container);
    installDummyModule("sub.j.MF", "j", container);
    Module k = installDummyModule("sub.k.MF", "k", container);
    // resolve order does matter so that transitive dependencies are pulled in
    // and cause substitution to happen in a certain way
    container.resolve(Arrays.asList(k), true);
    ModuleWiring wiringI = i.getCurrentRevision().getWiring();
    ModuleWiring wiringK = k.getCurrentRevision().getWiring();
    List<ModuleWire> requiredWiresK = wiringK.getRequiredModuleWires(PackageNamespace.PACKAGE_NAMESPACE);
    // I should be the provider for all of K
    Assert.assertEquals("Wrong number of required wires: " + requiredWiresK, 2, requiredWiresK.size());
    for (ModuleWire moduleWire : requiredWiresK) {
        Assert.assertEquals("Wrong provider: " + moduleWire.getProviderWiring(), wiringI, moduleWire.getProviderWiring());
    }
}
Also used : DummyContainerAdaptor(org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor) ModuleWire(org.eclipse.osgi.container.ModuleWire) ModuleContainer(org.eclipse.osgi.container.ModuleContainer) ModuleWiring(org.eclipse.osgi.container.ModuleWiring) Module(org.eclipse.osgi.container.Module) Test(org.junit.Test)

Example 64 with DummyContainerAdaptor

use of org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor in project rt.equinox.framework by eclipse.

the class TestModuleContainer method testSingleton03.

@Test
public void testSingleton03() throws BundleException, IOException {
    DummyContainerAdaptor adaptor = createDummyAdaptor();
    ModuleContainer container = adaptor.getContainer();
    Module s1 = installDummyModule("singleton1_v1.MF", "s1_v1", container);
    // Resolve s1 first
    container.resolve(null, false);
    Assert.assertTrue("Singleton v1 is not resolved.", Module.RESOLVED_SET.contains(s1.getState()));
    Module s2 = installDummyModule("singleton1_v2.MF", "s1_v2", container);
    Module s3 = installDummyModule("singleton1_v3.MF", "s1_v3", container);
    container.resolve(Arrays.asList(s2, s3), false);
    // Make sure s1 is the only on resolved because it was first resolved
    Assert.assertTrue("Singleton v1 is not resolved.", Module.RESOLVED_SET.contains(s1.getState()));
    Assert.assertFalse("Singleton v2 is resolved.", Module.RESOLVED_SET.contains(s2.getState()));
    Assert.assertFalse("Singleton v3 is resolved.", Module.RESOLVED_SET.contains(s3.getState()));
}
Also used : DummyContainerAdaptor(org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor) ModuleContainer(org.eclipse.osgi.container.ModuleContainer) Module(org.eclipse.osgi.container.Module) Test(org.junit.Test)

Example 65 with DummyContainerAdaptor

use of org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor in project rt.equinox.framework by eclipse.

the class TestModuleContainer method createContainerWithSystemBundle.

private Module createContainerWithSystemBundle(boolean resolveSystemBundle) throws BundleException, IOException {
    DummyContainerAdaptor adaptor = createDummyAdaptor();
    ModuleContainer container = adaptor.getContainer();
    // install the system.bundle
    String systemCapability = "osgi.ee; osgi.ee=\"JavaSE\"; version:List<Version>=\"1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6\", equinox.test; equinox.test=system, osgi.native; osgi.native.osname=test";
    Module systemBundle = installDummyModule("system.bundle.MF", Constants.SYSTEM_BUNDLE_LOCATION, Constants.SYSTEM_BUNDLE_SYMBOLICNAME, null, systemCapability, container);
    if (resolveSystemBundle) {
        ResolutionReport report = container.resolve(Collections.singleton(systemBundle), true);
        Assert.assertNull("Found resolution exception.", report.getResolutionException());
        Assert.assertEquals("System is not resolved.", State.RESOLVED, systemBundle.getState());
    }
    return systemBundle;
}
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)

Aggregations

DummyContainerAdaptor (org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor)85 ModuleContainer (org.eclipse.osgi.container.ModuleContainer)80 Module (org.eclipse.osgi.container.Module)79 Test (org.junit.Test)73 ModuleWire (org.eclipse.osgi.container.ModuleWire)25 ResolutionReport (org.eclipse.osgi.report.resolution.ResolutionReport)23 ModuleWiring (org.eclipse.osgi.container.ModuleWiring)20 HashMap (java.util.HashMap)18 ArrayList (java.util.ArrayList)15 DummyModuleDatabase (org.eclipse.osgi.tests.container.dummys.DummyModuleDatabase)12 ByteArrayOutputStream (java.io.ByteArrayOutputStream)9 DummyModuleEvent (org.eclipse.osgi.tests.container.dummys.DummyModuleDatabase.DummyModuleEvent)9 ByteArrayInputStream (java.io.ByteArrayInputStream)8 DataInputStream (java.io.DataInputStream)8 DataOutputStream (java.io.DataOutputStream)8 ModuleRevision (org.eclipse.osgi.container.ModuleRevision)8 DummyCollisionHook (org.eclipse.osgi.tests.container.dummys.DummyCollisionHook)7 BundleException (org.osgi.framework.BundleException)7 BundleRequirement (org.osgi.framework.wiring.BundleRequirement)6 DummyContainerEvent (org.eclipse.osgi.tests.container.dummys.DummyModuleDatabase.DummyContainerEvent)5