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));
}
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)));
}
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));
}
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()]);
}
Aggregations