use of org.osgi.framework.wiring.BundleWiring in project rt.equinox.framework by eclipse.
the class ClassLoadingBundleTests method testMultipleExportFragments01.
public void testMultipleExportFragments01() throws Exception {
// $NON-NLS-1$
Bundle host = installer.installBundle("host.multiple.exports");
// $NON-NLS-1$
Bundle frag = installer.installBundle("frag.multiple.exports");
installer.resolveBundles(new Bundle[] { host, frag });
PackageAdmin packageAdmin = installer.getPackageAdmin();
ExportedPackage[] hostExports = packageAdmin.getExportedPackages(host);
// $NON-NLS-1$
assertEquals("Number host exports", 4, hostExports == null ? 0 : hostExports.length);
BundleWiring hostWiring = host.adapt(BundleWiring.class);
assertNotNull("No host wiring", hostWiring);
List packageCapabilities = hostWiring.getCapabilities(PackageNamespace.PACKAGE_NAMESPACE);
// $NON-NLS-1$
assertEquals("Number host export capabilities", 4, packageCapabilities.size());
// $NON-NLS-1$//$NON-NLS-2$
assertEquals("Check export name", "host.multiple.exports", ((BundleCapability) packageCapabilities.get(0)).getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE));
// $NON-NLS-1$//$NON-NLS-2$
assertEquals("Check include directive", "Public*", ((BundleCapability) packageCapabilities.get(0)).getDirectives().get(PackageNamespace.CAPABILITY_INCLUDE_DIRECTIVE));
// $NON-NLS-1$ //$NON-NLS-2$
assertEquals("Check export name", "host.multiple.exports.onlyone", ((BundleCapability) packageCapabilities.get(1)).getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE));
// $NON-NLS-1$//$NON-NLS-2$
assertEquals("Check export name", "host.multiple.exports", ((BundleCapability) packageCapabilities.get(2)).getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE));
// $NON-NLS-1$//$NON-NLS-2$
assertEquals("Check scope attribute", "private", (String) ((BundleCapability) packageCapabilities.get(2)).getAttributes().get("scope"));
// $NON-NLS-1$ //$NON-NLS-2$
assertEquals("Check export name", "host.multiple.exports.onlyone", ((BundleCapability) packageCapabilities.get(3)).getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE));
}
use of org.osgi.framework.wiring.BundleWiring in project rt.equinox.framework by eclipse.
the class ClassLoadingBundleTests method testListResources.
public void testListResources() throws BundleException {
// $NON-NLS-1$
installer.installBundle("test");
// $NON-NLS-1$
Bundle test2 = installer.installBundle("test2");
assertTrue("Could not resolve test2 bundle", installer.resolveBundles(new Bundle[] { test2 }));
BundleWiring test2Wiring = test2.adapt(BundleWiring.class);
Collection resources = test2Wiring.listResources("/", "*", 0);
assertTrue("could not find resource", resources.contains("resource2"));
resources = test2Wiring.listResources("data/", "resource2", 0);
assertTrue("could not find resource", resources.contains("data/resource2"));
resources = test2Wiring.listResources("/", "resource*", BundleWiring.LISTRESOURCES_RECURSE);
assertTrue("could not find resource", resources.contains("data/resource2"));
}
use of org.osgi.framework.wiring.BundleWiring in project rt.equinox.framework by eclipse.
the class ClassLoadingBundleTests method testMultipleGetResources01a.
public void testMultipleGetResources01a() throws Exception {
// $NON-NLS-1$
Bundle test = installer.installBundle("test");
// test that we can get multiple resources from a bundle
// and use that bundle's class loader as a parent
installer.resolveBundles(new Bundle[] { test });
BundleWiring wiring = test.adapt(BundleWiring.class);
ClassLoader bcl = wiring.getClassLoader();
URLClassLoader cl = new URLClassLoader(new URL[0], bcl);
// $NON-NLS-1$
Enumeration resources = cl.getResources("data/resource1");
// $NON-NLS-1$
assertNotNull("resources", resources);
ArrayList resourceURLs = new ArrayList();
while (resources.hasMoreElements()) resourceURLs.add(resources.nextElement());
// $NON-NLS-1$
assertEquals("resource number", 2, resourceURLs.size());
// $NON-NLS-1$ //$NON-NLS-2$
assertEquals("root resource", "root classpath", readURL((URL) resourceURLs.get(0)));
// $NON-NLS-1$ //$NON-NLS-2$
assertEquals("stuff resource", "stuff classpath", readURL((URL) resourceURLs.get(1)));
cl.close();
}
use of org.osgi.framework.wiring.BundleWiring in project rt.equinox.framework by eclipse.
the class ExtensionBundleTests method testExtensionBundleWithRequireCapabilityOsgiEeInstalls.
public void testExtensionBundleWithRequireCapabilityOsgiEeInstalls() {
Bundle b = null;
try {
b = installer.installBundle("ext.framework.osgiee.b", false);
} catch (BundleException e) {
fail("Extension bundle with Require-Capability only in osgi.ee. namespace failed to install", e);
}
assertTrue("Could not resolve bundle: " + b, installer.resolveBundles(new Bundle[] { b }));
BundleWiring wiring = b.adapt(BundleWiring.class);
assertNotNull("No wiring for bundle: " + b, wiring);
List<BundleWire> allRequired = wiring.getRequiredWires(null);
assertEquals("Wrong number of wires: " + allRequired, 2, allRequired.size());
BundleWire hostWire = wiring.getRequiredWires(HostNamespace.HOST_NAMESPACE).get(0);
assertEquals("Wrong provider for host: " + hostWire.getProvider().getBundle(), 0, hostWire.getProvider().getBundle().getBundleId());
BundleWire eeWire = wiring.getRequiredWires(ExecutionEnvironmentNamespace.EXECUTION_ENVIRONMENT_NAMESPACE).get(0);
assertEquals("Wrong provider for osgi.ee: " + eeWire.getProvider().getBundle(), 0, eeWire.getProvider().getBundle().getBundleId());
}
use of org.osgi.framework.wiring.BundleWiring in project rt.equinox.framework by eclipse.
the class MultiReleaseJarTests method listResources.
private void listResources(String path, Collection<String> expected, Bundle mrBundle, int options) {
BundleWiring wiring = mrBundle.adapt(BundleWiring.class);
Collection<String> found = wiring.listResources(path, "*.txt", options);
assertEquals("Wrong resource listing.", expected.toArray(), found.toArray(), false);
}
Aggregations