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