Search in sources :

Example 41 with BundleRequirement

use of org.osgi.framework.wiring.BundleRequirement in project rt.equinox.framework by eclipse.

the class ClassLoadingBundleTests method testBug370258_endException.

public void testBug370258_endException() {
    final boolean[] endCalled = { false };
    ResolverHookFactory endHook = new ResolverHookFactory() {

        public ResolverHook begin(Collection triggers) {
            return new ResolverHook() {

                public void filterSingletonCollisions(BundleCapability singleton, Collection collisionCandidates) {
                // Nothing
                }

                public void filterResolvable(Collection candidates) {
                    throw new RuntimeException("Error");
                }

                public void filterMatches(BundleRequirement requirement, Collection candidates) {
                // Nothing
                }

                public void end() {
                    endCalled[0] = true;
                }
            };
        }
    };
    ResolverHookFactory error = new ResolverHookFactory() {

        public ResolverHook begin(Collection triggers) {
            return new ResolverHook() {

                public void filterSingletonCollisions(BundleCapability singleton, Collection collisionCandidates) {
                // Nothing
                }

                public void filterResolvable(Collection candidates) {
                // Nothing
                }

                public void filterMatches(BundleRequirement requirement, Collection candidates) {
                // Nothing
                }

                public void end() {
                    throw new RuntimeException("Error");
                }
            };
        }
    };
    ServiceRegistration errorReg = OSGiTestsActivator.getContext().registerService(ResolverHookFactory.class, error, null);
    ServiceRegistration endReg = OSGiTestsActivator.getContext().registerService(ResolverHookFactory.class, endHook, null);
    try {
        // $NON-NLS-1$
        Bundle test = installer.installBundle("test");
        try {
            test.start();
            fail("Should not be able to start this bundle");
        } catch (BundleException e) {
            // expected
            assertEquals("Wrong exception type.", BundleException.REJECTED_BY_HOOK, e.getType());
        }
    } catch (BundleException e) {
        fail("Unexpected install fail", e);
    } finally {
        errorReg.unregister();
        endReg.unregister();
    }
    assertTrue("end is not called", endCalled[0]);
}
Also used : ResolverHookFactory(org.osgi.framework.hooks.resolver.ResolverHookFactory) ResolverHook(org.osgi.framework.hooks.resolver.ResolverHook) Bundle(org.osgi.framework.Bundle) Collection(java.util.Collection) BundleException(org.osgi.framework.BundleException) BundleCapability(org.osgi.framework.wiring.BundleCapability) BundleRequirement(org.osgi.framework.wiring.BundleRequirement) ServiceRegistration(org.osgi.framework.ServiceRegistration)

Example 42 with BundleRequirement

use of org.osgi.framework.wiring.BundleRequirement in project rt.equinox.framework by eclipse.

the class ClassLoadingBundleTests method testBug348806.

public void testBug348806() {
    ResolverHookFactory error = new ResolverHookFactory() {

        public ResolverHook begin(Collection triggers) {
            return new ResolverHook() {

                public void filterSingletonCollisions(BundleCapability singleton, Collection collisionCandidates) {
                // Nothing
                }

                public void filterResolvable(Collection candidates) {
                // Nothing
                }

                public void filterMatches(BundleRequirement requirement, Collection candidates) {
                // Nothing
                }

                public void end() {
                    throw new RuntimeException("Error");
                }
            };
        }
    };
    ServiceRegistration reg = OSGiTestsActivator.getContext().registerService(ResolverHookFactory.class, error, null);
    try {
        // $NON-NLS-1$
        Bundle test = installer.installBundle("test");
        try {
            test.start();
            fail("Should not be able to start this bundle");
        } catch (BundleException e) {
            // expected
            assertEquals("Wrong exception type.", BundleException.REJECTED_BY_HOOK, e.getType());
        }
    } catch (BundleException e) {
        fail("Unexpected install fail", e);
    } finally {
        reg.unregister();
    }
}
Also used : ResolverHookFactory(org.osgi.framework.hooks.resolver.ResolverHookFactory) ResolverHook(org.osgi.framework.hooks.resolver.ResolverHook) Bundle(org.osgi.framework.Bundle) Collection(java.util.Collection) BundleException(org.osgi.framework.BundleException) BundleCapability(org.osgi.framework.wiring.BundleCapability) BundleRequirement(org.osgi.framework.wiring.BundleRequirement) ServiceRegistration(org.osgi.framework.ServiceRegistration)

Example 43 with BundleRequirement

use of org.osgi.framework.wiring.BundleRequirement in project rt.equinox.framework by eclipse.

the class ClassLoadingBundleTests method testBug370258_beginException.

public void testBug370258_beginException() {
    final boolean[] endCalled = { false };
    ResolverHookFactory endHook = new ResolverHookFactory() {

        public ResolverHook begin(Collection triggers) {
            return new ResolverHook() {

                public void filterSingletonCollisions(BundleCapability singleton, Collection collisionCandidates) {
                // Nothing
                }

                public void filterResolvable(Collection candidates) {
                    throw new RuntimeException("Error");
                }

                public void filterMatches(BundleRequirement requirement, Collection candidates) {
                // Nothing
                }

                public void end() {
                    endCalled[0] = true;
                }
            };
        }
    };
    ResolverHookFactory error = new ResolverHookFactory() {

        public ResolverHook begin(Collection triggers) {
            throw new RuntimeException("Error");
        }
    };
    ServiceRegistration endReg = OSGiTestsActivator.getContext().registerService(ResolverHookFactory.class, endHook, null);
    ServiceRegistration errorReg = OSGiTestsActivator.getContext().registerService(ResolverHookFactory.class, error, null);
    try {
        // $NON-NLS-1$
        Bundle test = installer.installBundle("test");
        try {
            test.start();
            fail("Should not be able to start this bundle");
        } catch (BundleException e) {
            // expected
            assertEquals("Wrong exception type.", BundleException.REJECTED_BY_HOOK, e.getType());
        }
    } catch (BundleException e) {
        fail("Unexpected install fail", e);
    } finally {
        errorReg.unregister();
        endReg.unregister();
    }
    assertTrue("end is not called", endCalled[0]);
}
Also used : ResolverHookFactory(org.osgi.framework.hooks.resolver.ResolverHookFactory) ResolverHook(org.osgi.framework.hooks.resolver.ResolverHook) Bundle(org.osgi.framework.Bundle) Collection(java.util.Collection) BundleException(org.osgi.framework.BundleException) BundleCapability(org.osgi.framework.wiring.BundleCapability) BundleRequirement(org.osgi.framework.wiring.BundleRequirement) ServiceRegistration(org.osgi.framework.ServiceRegistration)

Example 44 with BundleRequirement

use of org.osgi.framework.wiring.BundleRequirement in project rt.equinox.framework by eclipse.

the class MultiReleaseJarTests method doTestMultiReleaseBundleManifest.

private void doTestMultiReleaseBundleManifest(int rv) throws Exception {
    if (rv < 9) {
        System.setProperty("java.specification.version", "1." + rv);
    } else {
        System.setProperty("java.specification.version", Integer.toString(rv));
    }
    String expectedCap;
    String expectedPkg;
    if (rv < 9) {
        expectedCap = "capbase";
        expectedPkg = "pkgbase";
    } else {
        expectedCap = "cap" + rv;
        expectedPkg = "pkg" + rv;
    }
    // $NON-NLS-1$
    File config = OSGiTestsActivator.getContext().getDataFile(getName());
    Equinox equinox = new Equinox(Collections.singletonMap(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath()));
    try {
        equinox.start();
        BundleContext systemContext = equinox.getBundleContext();
        Bundle mrBundle = systemContext.installBundle(mrJarBundle.toURI().toString());
        mrBundle.start();
        List<BundleWire> capWires = mrBundle.adapt(BundleWiring.class).getRequiredWires(expectedCap);
        assertEquals("Wrong number of capability wires.", 1, capWires.size());
        List<BundleRequirement> pkgReqs = mrBundle.adapt(BundleRevision.class).getDeclaredRequirements(PackageNamespace.PACKAGE_NAMESPACE);
        assertEquals("Wrong number of package requiremens.", 1, pkgReqs.size());
        String filter = pkgReqs.get(0).getDirectives().get(Namespace.REQUIREMENT_FILTER_DIRECTIVE);
        assertTrue("Wrong package filter: " + filter, filter.contains(expectedPkg));
    } finally {
        try {
            equinox.stop();
            equinox.waitForStop(10000);
        } catch (Exception e) {
        // ignore;
        }
    }
}
Also used : Equinox(org.eclipse.osgi.launch.Equinox) Bundle(org.osgi.framework.Bundle) BundleWiring(org.osgi.framework.wiring.BundleWiring) BundleRevision(org.osgi.framework.wiring.BundleRevision) File(java.io.File) BundleWire(org.osgi.framework.wiring.BundleWire) BundleRequirement(org.osgi.framework.wiring.BundleRequirement) BundleException(org.osgi.framework.BundleException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) BundleContext(org.osgi.framework.BundleContext)

Example 45 with BundleRequirement

use of org.osgi.framework.wiring.BundleRequirement in project rt.equinox.framework by eclipse.

the class MultiReleaseJarTests method doTestMultiReleaseBundleManifestChangeRuntime.

private void doTestMultiReleaseBundleManifestChangeRuntime(int rv, Map<String, String> configMap, String location) throws BundleException {
    if (rv < 9) {
        System.setProperty("java.specification.version", "1." + rv);
    } else {
        System.setProperty("java.specification.version", Integer.toString(rv));
    }
    String expectedCap;
    String expectedPkg;
    if (rv < 9) {
        expectedCap = "capbase";
        expectedPkg = "pkgbase";
    } else {
        expectedCap = "cap" + rv;
        expectedPkg = "pkg" + rv;
    }
    Equinox equinox = new Equinox(configMap);
    try {
        equinox.start();
        BundleContext systemContext = equinox.getBundleContext();
        Bundle mrBundle = systemContext.getBundle(location);
        assertNotNull("No mrBundle found: " + rv, mrBundle);
        assertEquals("Wrong state of mrBundle: " + rv, Bundle.ACTIVE, mrBundle.getState());
        List<BundleWire> capWires = mrBundle.adapt(BundleWiring.class).getRequiredWires(expectedCap);
        assertEquals("Wrong number of capability wires: " + rv, 1, capWires.size());
        List<BundleRequirement> pkgReqs = mrBundle.adapt(BundleRevision.class).getDeclaredRequirements(PackageNamespace.PACKAGE_NAMESPACE);
        assertEquals("Wrong number of package requiremens: " + rv, 1, pkgReqs.size());
        String filter = pkgReqs.get(0).getDirectives().get(Namespace.REQUIREMENT_FILTER_DIRECTIVE);
        assertTrue("Wrong package filter: " + rv + " " + filter, filter.contains(expectedPkg));
    } finally {
        try {
            equinox.stop();
            equinox.waitForStop(10000);
        } catch (Exception e) {
        // ignore;
        }
    }
}
Also used : Equinox(org.eclipse.osgi.launch.Equinox) Bundle(org.osgi.framework.Bundle) BundleWiring(org.osgi.framework.wiring.BundleWiring) BundleRevision(org.osgi.framework.wiring.BundleRevision) BundleWire(org.osgi.framework.wiring.BundleWire) BundleRequirement(org.osgi.framework.wiring.BundleRequirement) BundleException(org.osgi.framework.BundleException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) BundleContext(org.osgi.framework.BundleContext)

Aggregations

BundleRequirement (org.osgi.framework.wiring.BundleRequirement)55 BundleCapability (org.osgi.framework.wiring.BundleCapability)23 ArrayList (java.util.ArrayList)20 BundleWire (org.osgi.framework.wiring.BundleWire)18 BundleRevision (org.osgi.framework.wiring.BundleRevision)17 HashMap (java.util.HashMap)15 Bundle (org.osgi.framework.Bundle)15 Test (org.junit.Test)14 BundleException (org.osgi.framework.BundleException)11 ResolverHook (org.osgi.framework.hooks.resolver.ResolverHook)10 BundleWiring (org.osgi.framework.wiring.BundleWiring)10 List (java.util.List)9 Collection (java.util.Collection)8 BundleRequirementImpl (org.apache.felix.framework.wiring.BundleRequirementImpl)8 ResolverHookFactory (org.osgi.framework.hooks.resolver.ResolverHookFactory)8 CompositeData (javax.management.openmbean.CompositeData)6 Module (org.eclipse.osgi.container.Module)6 ModuleContainer (org.eclipse.osgi.container.ModuleContainer)6 DummyContainerAdaptor (org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor)6 SimpleFilter (org.apache.felix.framework.capabilityset.SimpleFilter)5