Search in sources :

Example 1 with ModuleWiring

use of org.eclipse.osgi.container.ModuleWiring in project rt.equinox.framework by eclipse.

the class PackageAdminImpl method getExportedPackages.

public ExportedPackage[] getExportedPackages(String name) {
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$//$NON-NLS-4$
    String filter = "(" + PackageNamespace.PACKAGE_NAMESPACE + "=" + (name == null ? "*" : name) + ")";
    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 packageReq = ModuleContainer.createRequirement(PackageNamespace.PACKAGE_NAMESPACE, directives, attributes);
    Collection<BundleCapability> packageCaps = container.getFrameworkWiring().findProviders(packageReq);
    InternalUtils.filterCapabilityPermissions(packageCaps);
    List<ExportedPackage> result = new ArrayList<>();
    for (BundleCapability capability : packageCaps) {
        ModuleWiring wiring = (ModuleWiring) capability.getRevision().getWiring();
        if (wiring != null) {
            Collection<ModuleWiring> wirings = Collections.emptyList();
            if ((capability.getRevision().getTypes() & BundleRevision.TYPE_FRAGMENT) != 0) {
                // This is a fragment, just get all the host wirings
                List<ModuleWire> hostWires = wiring.getRequiredModuleWires(HostNamespace.HOST_NAMESPACE);
                if (hostWires != null && !hostWires.isEmpty()) {
                    wirings = new ArrayList<>(hostWires.size());
                    for (ModuleWire hostWire : hostWires) {
                        ModuleWiring hostWiring = hostWire.getProviderWiring();
                        if (hostWiring != null) {
                            wirings.add(hostWiring);
                        }
                    }
                }
            } else {
                // just a single host wiring
                wirings = Collections.singletonList(wiring);
            }
            for (ModuleWiring moduleWiring : wirings) {
                if (!moduleWiring.getSubstitutedNames().contains(capability.getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE))) {
                    result.add(new ExportedPackageImpl((ModuleCapability) capability, moduleWiring));
                }
            }
        }
    }
    return (result.size() == 0 ? null : result.toArray(new ExportedPackage[result.size()]));
}
Also used : ModuleWire(org.eclipse.osgi.container.ModuleWire) ArrayList(java.util.ArrayList) ModuleCapability(org.eclipse.osgi.container.ModuleCapability) Requirement(org.osgi.resource.Requirement) ExportedPackage(org.osgi.service.packageadmin.ExportedPackage) ModuleWiring(org.eclipse.osgi.container.ModuleWiring) BundleCapability(org.osgi.framework.wiring.BundleCapability)

Example 2 with ModuleWiring

use of org.eclipse.osgi.container.ModuleWiring in project rt.equinox.framework by eclipse.

the class PackageAdminImpl method getFragments.

public Bundle[] getFragments(Bundle bundle) {
    ModuleWiring wiring = getWiring(bundle);
    if (wiring == null) {
        return null;
    }
    List<ModuleWire> hostWires = wiring.getProvidedModuleWires(HostNamespace.HOST_NAMESPACE);
    if (hostWires == null) {
        // we don't hold locks while checking the graph, just return if no longer valid
        return null;
    }
    Collection<Bundle> fragments = new ArrayList<>(hostWires.size());
    for (ModuleWire wire : hostWires) {
        Bundle fragment = wire.getRequirer().getBundle();
        if (fragment != null) {
            fragments.add(fragment);
        }
    }
    return fragments.isEmpty() ? null : fragments.toArray(new Bundle[fragments.size()]);
}
Also used : ModuleWire(org.eclipse.osgi.container.ModuleWire) Bundle(org.osgi.framework.Bundle) RequiredBundle(org.osgi.service.packageadmin.RequiredBundle) ModuleWiring(org.eclipse.osgi.container.ModuleWiring) ArrayList(java.util.ArrayList)

Example 3 with ModuleWiring

use of org.eclipse.osgi.container.ModuleWiring in project rt.equinox.framework by eclipse.

the class PackageAdminImpl method getHosts.

public Bundle[] getHosts(Bundle bundle) {
    ModuleWiring wiring = getWiring(bundle);
    if (wiring == null) {
        return null;
    }
    List<ModuleWire> hostWires = wiring.getRequiredModuleWires(HostNamespace.HOST_NAMESPACE);
    if (hostWires == null) {
        // we don't hold locks while checking the graph, just return if no longer valid
        return null;
    }
    Collection<Bundle> hosts = new ArrayList<>(hostWires.size());
    for (ModuleWire wire : hostWires) {
        Bundle host = wire.getProvider().getBundle();
        if (host != null) {
            hosts.add(host);
        }
    }
    return hosts.isEmpty() ? null : hosts.toArray(new Bundle[hosts.size()]);
}
Also used : ModuleWire(org.eclipse.osgi.container.ModuleWire) Bundle(org.osgi.framework.Bundle) RequiredBundle(org.osgi.service.packageadmin.RequiredBundle) ModuleWiring(org.eclipse.osgi.container.ModuleWiring) ArrayList(java.util.ArrayList)

Example 4 with ModuleWiring

use of org.eclipse.osgi.container.ModuleWiring in project rt.equinox.framework by eclipse.

the class MiscTests method testBug251427.

public void testBug251427() {
    Bundle testsBundle = OSGiTestsActivator.getContext().getBundle();
    // $NON-NLS-1$
    assertNotNull("tests bundle is null", testsBundle);
    // $NON-NLS-1$
    Bundle harnessBundle = Platform.getBundle("org.eclipse.core.tests.harness");
    // $NON-NLS-1$
    assertNotNull("harness bundle is null", harnessBundle);
    ModuleWiring testsWiring = (ModuleWiring) testsBundle.adapt(BundleWiring.class);
    ModuleWiring harnessWiring = (ModuleWiring) harnessBundle.adapt(BundleWiring.class);
    // $NON-NLS-1$
    SingleSourcePackage p111 = new SingleSourcePackage("pkg1", (BundleLoader) testsWiring.getModuleLoader());
    // $NON-NLS-1$
    SingleSourcePackage p121 = new SingleSourcePackage("pkg1", (BundleLoader) testsWiring.getModuleLoader());
    // $NON-NLS-1$
    SingleSourcePackage p112 = new SingleSourcePackage("pkg1", (BundleLoader) harnessWiring.getModuleLoader());
    // $NON-NLS-1$
    SingleSourcePackage p212 = new SingleSourcePackage("pkg2", (BundleLoader) harnessWiring.getModuleLoader());
    // $NON-NLS-1$
    SingleSourcePackage p222 = new SingleSourcePackage("pkg2", (BundleLoader) harnessWiring.getModuleLoader());
    // $NON-NLS-1$
    SingleSourcePackage p211 = new SingleSourcePackage("pkg2", (BundleLoader) testsWiring.getModuleLoader());
    // $NON-NLS-1$
    assertEquals("sources not equal", p111, p121);
    // $NON-NLS-1$
    assertEquals("sources hashCode not equal", p111.hashCode(), p121.hashCode());
    // $NON-NLS-1$
    assertEquals("sources not equal", p212, p222);
    // $NON-NLS-1$
    assertEquals("sources hashCode not equal", p212.hashCode(), p222.hashCode());
    // $NON-NLS-1$
    assertFalse("sources are equal", p111.equals(p112));
    // $NON-NLS-1$
    assertFalse("sources are equal", p212.equals(p211));
}
Also used : Bundle(org.osgi.framework.Bundle) BundleWiring(org.osgi.framework.wiring.BundleWiring) ModuleWiring(org.eclipse.osgi.container.ModuleWiring) SingleSourcePackage(org.eclipse.osgi.internal.loader.sources.SingleSourcePackage)

Example 5 with ModuleWiring

use of org.eclipse.osgi.container.ModuleWiring in project rt.equinox.framework by eclipse.

the class BundleContextImpl method loadBundleActivator.

private BundleActivator loadBundleActivator() throws ClassNotFoundException, InstantiationException, IllegalAccessException {
    ModuleWiring wiring = bundle.getModule().getCurrentRevision().getWiring();
    if (wiring == null) {
        return null;
    }
    BundleLoader loader = (BundleLoader) wiring.getModuleLoader();
    if (loader == null) {
        return null;
    }
    List<Capability> metadata = wiring.getRevision().getCapabilities(EquinoxModuleDataNamespace.MODULE_DATA_NAMESPACE);
    if (metadata.isEmpty()) {
        return null;
    }
    String activatorName = (String) metadata.get(0).getAttributes().get(EquinoxModuleDataNamespace.CAPABILITY_ACTIVATOR);
    if (activatorName == null) {
        return null;
    }
    Class<?> activatorClass = loader.findClass(activatorName);
    return (BundleActivator) activatorClass.newInstance();
}
Also used : Capability(org.osgi.resource.Capability) ModuleWiring(org.eclipse.osgi.container.ModuleWiring) BundleLoader(org.eclipse.osgi.internal.loader.BundleLoader)

Aggregations

ModuleWiring (org.eclipse.osgi.container.ModuleWiring)39 Module (org.eclipse.osgi.container.Module)22 ModuleWire (org.eclipse.osgi.container.ModuleWire)21 ModuleContainer (org.eclipse.osgi.container.ModuleContainer)20 DummyContainerAdaptor (org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor)20 Test (org.junit.Test)20 ModuleRevision (org.eclipse.osgi.container.ModuleRevision)12 BundleLoader (org.eclipse.osgi.internal.loader.BundleLoader)8 ArrayList (java.util.ArrayList)7 ResolutionReport (org.eclipse.osgi.report.resolution.ResolutionReport)6 URL (java.net.URL)5 BundleCapability (org.osgi.framework.wiring.BundleCapability)4 HashMap (java.util.HashMap)3 ModuleCapability (org.eclipse.osgi.container.ModuleCapability)3 DummyModuleDatabase (org.eclipse.osgi.tests.container.dummys.DummyModuleDatabase)3 Bundle (org.osgi.framework.Bundle)3 BundleException (org.osgi.framework.BundleException)3 IOException (java.io.IOException)2 ModuleClassLoader (org.eclipse.osgi.internal.loader.ModuleClassLoader)2 BundleRequirement (org.osgi.framework.wiring.BundleRequirement)2