Search in sources :

Example 41 with BundleWiring

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));
}
Also used : PackageAdmin(org.osgi.service.packageadmin.PackageAdmin) Bundle(org.osgi.framework.Bundle) ExportedPackage(org.osgi.service.packageadmin.ExportedPackage) BundleWiring(org.osgi.framework.wiring.BundleWiring) List(java.util.List) ArrayList(java.util.ArrayList) BundleCapability(org.osgi.framework.wiring.BundleCapability)

Example 42 with BundleWiring

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"));
}
Also used : Bundle(org.osgi.framework.Bundle) BundleWiring(org.osgi.framework.wiring.BundleWiring) Collection(java.util.Collection)

Example 43 with BundleWiring

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();
}
Also used : Enumeration(java.util.Enumeration) Bundle(org.osgi.framework.Bundle) BundleWiring(org.osgi.framework.wiring.BundleWiring) URLClassLoader(java.net.URLClassLoader) ArrayList(java.util.ArrayList) ModuleClassLoader(org.eclipse.osgi.internal.loader.ModuleClassLoader) URLClassLoader(java.net.URLClassLoader) URL(java.net.URL)

Example 44 with BundleWiring

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());
}
Also used : Bundle(org.osgi.framework.Bundle) BundleWiring(org.osgi.framework.wiring.BundleWiring) BundleException(org.osgi.framework.BundleException) BundleWire(org.osgi.framework.wiring.BundleWire)

Example 45 with BundleWiring

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);
}
Also used : BundleWiring(org.osgi.framework.wiring.BundleWiring)

Aggregations

BundleWiring (org.osgi.framework.wiring.BundleWiring)82 Bundle (org.osgi.framework.Bundle)48 BundleWire (org.osgi.framework.wiring.BundleWire)27 ArrayList (java.util.ArrayList)20 Test (org.junit.Test)14 BundleCapability (org.osgi.framework.wiring.BundleCapability)13 BundleRevision (org.osgi.framework.wiring.BundleRevision)13 Hashtable (java.util.Hashtable)12 Dictionary (java.util.Dictionary)10 List (java.util.List)10 HashMap (java.util.HashMap)9 URL (java.net.URL)8 BundleContext (org.osgi.framework.BundleContext)8 LinkedHashMap (java.util.LinkedHashMap)6 AbstractIntegrationTest (org.apache.aries.jmx.AbstractIntegrationTest)6 IAnswer (org.easymock.IAnswer)6 ServiceReference (org.osgi.framework.ServiceReference)6 ServiceRegistration (org.osgi.framework.ServiceRegistration)6 Version (org.osgi.framework.Version)6 File (java.io.File)5