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