Search in sources :

Example 1 with ModuleWire

use of org.eclipse.osgi.container.ModuleWire 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 ModuleWire

use of org.eclipse.osgi.container.ModuleWire 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 ModuleWire

use of org.eclipse.osgi.container.ModuleWire 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 ModuleWire

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

the class BundleLoader method getImportedSources.

private KeyedHashSet getImportedSources(Collection<BundleLoader> visited) {
    synchronized (importedSources) {
        if (importsInitialized) {
            return importedSources;
        }
        List<ModuleWire> importWires = wiring.getRequiredModuleWires(PackageNamespace.PACKAGE_NAMESPACE);
        if (importWires != null) {
            for (ModuleWire importWire : importWires) {
                PackageSource source = createExportPackageSource(importWire, visited);
                if (source != null) {
                    importedSources.add(source);
                }
            }
        }
        importsInitialized = true;
        return importedSources;
    }
}
Also used : ModuleWire(org.eclipse.osgi.container.ModuleWire) PackageSource(org.eclipse.osgi.internal.loader.sources.PackageSource) NullPackageSource(org.eclipse.osgi.internal.loader.sources.NullPackageSource)

Example 5 with ModuleWire

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

the class BundleLoader method findRequiredSource.

private PackageSource findRequiredSource(String pkgName, Collection<BundleLoader> visited) {
    synchronized (requiredSources) {
        PackageSource result = (PackageSource) requiredSources.getByKey(pkgName);
        if (result != null)
            return result.isNullSource() ? null : result;
    }
    if (visited == null)
        visited = new ArrayList<>();
    if (!visited.contains(this))
        // always add ourselves so we do not recurse back to ourselves
        visited.add(this);
    List<PackageSource> result = new ArrayList<>(3);
    for (ModuleWire bundleWire : requiredBundleWires) {
        BundleLoader loader = (BundleLoader) bundleWire.getProviderWiring().getModuleLoader();
        if (loader != null) {
            loader.addExportedProvidersFor(pkgName, result, visited);
        }
    }
    // found some so cache the result for next time and return
    PackageSource source;
    if (result.size() == 0) {
        // did not find it in our required bundles lets record the failure
        // so we do not have to do the search again for this package.
        source = NullPackageSource.getNullPackageSource(pkgName);
    } else if (result.size() == 1) {
        // if there is just one source, remember just the single source
        source = result.get(0);
    } else {
        // if there was more than one source, build a multisource and cache that.
        PackageSource[] srcs = result.toArray(new PackageSource[result.size()]);
        source = createMultiSource(pkgName, srcs);
    }
    synchronized (requiredSources) {
        requiredSources.add(source);
    }
    return source.isNullSource() ? null : source;
}
Also used : ModuleWire(org.eclipse.osgi.container.ModuleWire) PackageSource(org.eclipse.osgi.internal.loader.sources.PackageSource) NullPackageSource(org.eclipse.osgi.internal.loader.sources.NullPackageSource) ArrayList(java.util.ArrayList)

Aggregations

ModuleWire (org.eclipse.osgi.container.ModuleWire)45 Module (org.eclipse.osgi.container.Module)32 ModuleContainer (org.eclipse.osgi.container.ModuleContainer)31 Test (org.junit.Test)31 DummyContainerAdaptor (org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor)25 ModuleWiring (org.eclipse.osgi.container.ModuleWiring)21 ResolutionReport (org.eclipse.osgi.report.resolution.ResolutionReport)13 HashMap (java.util.HashMap)11 ArrayList (java.util.ArrayList)9 ModuleRevision (org.eclipse.osgi.container.ModuleRevision)9 NullPackageSource (org.eclipse.osgi.internal.loader.sources.NullPackageSource)5 PackageSource (org.eclipse.osgi.internal.loader.sources.PackageSource)5 HashSet (java.util.HashSet)4 BundleRequirement (org.osgi.framework.wiring.BundleRequirement)4 ModuleCapability (org.eclipse.osgi.container.ModuleCapability)3 Generation (org.eclipse.osgi.storage.BundleInfo.Generation)3 DummyModuleDatabase (org.eclipse.osgi.tests.container.dummys.DummyModuleDatabase)3 BundleCapability (org.osgi.framework.wiring.BundleCapability)3 Bundle (org.osgi.framework.Bundle)2 BundleException (org.osgi.framework.BundleException)2