Search in sources :

Example 6 with RequiredBundle

use of org.osgi.service.packageadmin.RequiredBundle in project aries by apache.

the class FrameworkUtilsTest method testIsBundleRequiredByOthers.

@Test
public void testIsBundleRequiredByOthers() throws Exception {
    Bundle bundle = mock(Bundle.class);
    when(bundle.getSymbolicName()).thenReturn("org.apache.testb");
    RequiredBundle reqBundle = mock(RequiredBundle.class);
    when(reqBundle.getBundle()).thenReturn(bundle);
    when(reqBundle.getRequiringBundles()).thenReturn(new Bundle[0]);
    PackageAdmin admin = mock(PackageAdmin.class);
    when(admin.getRequiredBundles("org.apache.testb")).thenReturn(new RequiredBundle[] { reqBundle });
    assertFalse(isBundleRequiredByOthers(bundle, admin));
    Bundle user = mock(Bundle.class);
    when(reqBundle.getRequiringBundles()).thenReturn(new Bundle[] { user });
    assertTrue(isBundleRequiredByOthers(bundle, admin));
}
Also used : PackageAdmin(org.osgi.service.packageadmin.PackageAdmin) FrameworkUtils.getServicesInUseByBundle(org.apache.aries.jmx.util.FrameworkUtils.getServicesInUseByBundle) Bundle(org.osgi.framework.Bundle) RequiredBundle(org.osgi.service.packageadmin.RequiredBundle) RequiredBundle(org.osgi.service.packageadmin.RequiredBundle) Test(org.junit.Test)

Example 7 with RequiredBundle

use of org.osgi.service.packageadmin.RequiredBundle in project aries by apache.

the class FrameworkUtilsTest method testGetBundleDependencies.

@Test
public void testGetBundleDependencies() throws Exception {
    Bundle bundle = mock(Bundle.class);
    BundleContext context = mock(BundleContext.class);
    Bundle b1 = mock(Bundle.class);
    when(b1.getSymbolicName()).thenReturn("b1");
    when(b1.getBundleId()).thenReturn(new Long(44));
    Bundle b2 = mock(Bundle.class);
    when(b2.getSymbolicName()).thenReturn("b2");
    when(b2.getBundleId()).thenReturn(new Long(55));
    Bundle b3 = mock(Bundle.class);
    when(b3.getSymbolicName()).thenReturn("b3");
    when(b3.getBundleId()).thenReturn(new Long(66));
    when(context.getBundles()).thenReturn(new Bundle[] { bundle, b1, b2, b3 });
    Dictionary<String, String> headers = new Hashtable<String, String>();
    when(bundle.getHeaders()).thenReturn(headers);
    PackageAdmin admin = mock(PackageAdmin.class);
    assertEquals(0, getBundleDependencies(context, bundle, admin).length);
    RequiredBundle rb1 = mock(RequiredBundle.class);
    when(rb1.getBundle()).thenReturn(b1);
    when(rb1.getRequiringBundles()).thenReturn(new Bundle[] { bundle, b2 });
    RequiredBundle rb2 = mock(RequiredBundle.class);
    when(rb2.getBundle()).thenReturn(b2);
    when(rb2.getRequiringBundles()).thenReturn(new Bundle[] { b1 });
    RequiredBundle rb3 = mock(RequiredBundle.class);
    when(rb3.getBundle()).thenReturn(b3);
    when(rb3.getRequiringBundles()).thenReturn(new Bundle[] { bundle, b1, b2 });
    headers.put(Constants.REQUIRE_BUNDLE, "b1;bundle-version=\"1.0.0\",b3;bundle-version=\"2.0.0\"");
    when(admin.getRequiredBundles("b1")).thenReturn(new RequiredBundle[] { rb1 });
    when(admin.getRequiredBundles("b2")).thenReturn(new RequiredBundle[] { rb2 });
    when(admin.getRequiredBundles("b3")).thenReturn(new RequiredBundle[] { rb3 });
    assertEquals(toSet(new long[] { 44, 66 }), toSet(getBundleDependencies(context, bundle, admin)));
}
Also used : PackageAdmin(org.osgi.service.packageadmin.PackageAdmin) FrameworkUtils.getServicesInUseByBundle(org.apache.aries.jmx.util.FrameworkUtils.getServicesInUseByBundle) Bundle(org.osgi.framework.Bundle) RequiredBundle(org.osgi.service.packageadmin.RequiredBundle) Hashtable(java.util.Hashtable) Matchers.anyString(org.mockito.Matchers.anyString) BundleContext(org.osgi.framework.BundleContext) RequiredBundle(org.osgi.service.packageadmin.RequiredBundle) Test(org.junit.Test)

Example 8 with RequiredBundle

use of org.osgi.service.packageadmin.RequiredBundle in project aries by apache.

the class FrameworkUtilsTest method testIsBundlePendingRemoval.

@Test
public void testIsBundlePendingRemoval() throws Exception {
    Bundle bundle = mock(Bundle.class);
    when(bundle.getSymbolicName()).thenReturn("org.apache.testb");
    RequiredBundle reqBundle = mock(RequiredBundle.class);
    when(reqBundle.getBundle()).thenReturn(bundle);
    when(reqBundle.isRemovalPending()).thenReturn(true);
    PackageAdmin admin = mock(PackageAdmin.class);
    when(admin.getRequiredBundles("org.apache.testb")).thenReturn(new RequiredBundle[] { reqBundle });
    assertTrue(isBundlePendingRemoval(bundle, admin));
}
Also used : PackageAdmin(org.osgi.service.packageadmin.PackageAdmin) FrameworkUtils.getServicesInUseByBundle(org.apache.aries.jmx.util.FrameworkUtils.getServicesInUseByBundle) Bundle(org.osgi.framework.Bundle) RequiredBundle(org.osgi.service.packageadmin.RequiredBundle) RequiredBundle(org.osgi.service.packageadmin.RequiredBundle) Test(org.junit.Test)

Example 9 with RequiredBundle

use of org.osgi.service.packageadmin.RequiredBundle in project rt.equinox.framework by eclipse.

the class PackageAdminImpl method getRequiredBundles.

public RequiredBundle[] getRequiredBundles(String symbolicName) {
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$//$NON-NLS-4$
    String filter = "(" + BundleNamespace.BUNDLE_NAMESPACE + "=" + (symbolicName == null ? "*" : symbolicName) + ")";
    Map<String, String> directives = Collections.<String, String>singletonMap(Namespace.REQUIREMENT_FILTER_DIRECTIVE, filter);
    Map<String, Boolean> attributes = Collections.singletonMap(Capabilities.SYNTHETIC_REQUIREMENT, Boolean.TRUE);
    Requirement bundleReq = ModuleContainer.createRequirement(BundleNamespace.BUNDLE_NAMESPACE, directives, attributes);
    Collection<BundleCapability> bundleCaps = container.getFrameworkWiring().findProviders(bundleReq);
    InternalUtils.filterCapabilityPermissions(bundleCaps);
    Collection<RequiredBundle> result = new ArrayList<>();
    for (BundleCapability capability : bundleCaps) {
        BundleWiring wiring = capability.getRevision().getWiring();
        if (wiring != null) {
            result.add(new RequiredBundleImpl(capability, wiring));
        }
    }
    return result.isEmpty() ? null : result.toArray(new RequiredBundle[result.size()]);
}
Also used : Requirement(org.osgi.resource.Requirement) BundleWiring(org.osgi.framework.wiring.BundleWiring) ArrayList(java.util.ArrayList) BundleCapability(org.osgi.framework.wiring.BundleCapability) RequiredBundle(org.osgi.service.packageadmin.RequiredBundle)

Aggregations

RequiredBundle (org.osgi.service.packageadmin.RequiredBundle)9 Bundle (org.osgi.framework.Bundle)8 ExportedPackage (org.osgi.service.packageadmin.ExportedPackage)5 Test (org.junit.Test)4 PackageAdmin (org.osgi.service.packageadmin.PackageAdmin)4 FrameworkUtils.getServicesInUseByBundle (org.apache.aries.jmx.util.FrameworkUtils.getServicesInUseByBundle)3 HashSet (java.util.HashSet)2 Hashtable (java.util.Hashtable)2 BundleContext (org.osgi.framework.BundleContext)2 ArrayList (java.util.ArrayList)1 CompositeData (javax.management.openmbean.CompositeData)1 TabularData (javax.management.openmbean.TabularData)1 TabularDataSupport (javax.management.openmbean.TabularDataSupport)1 Matchers.anyString (org.mockito.Matchers.anyString)1 ServiceReference (org.osgi.framework.ServiceReference)1 Version (org.osgi.framework.Version)1 BundleCapability (org.osgi.framework.wiring.BundleCapability)1 BundleWiring (org.osgi.framework.wiring.BundleWiring)1 Requirement (org.osgi.resource.Requirement)1 StartLevel (org.osgi.service.startlevel.StartLevel)1