use of org.eclipse.osgi.container.ModuleCapability 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.ModuleCapability in project rt.equinox.framework by eclipse.
the class BundleLoader method initializeExports.
private static void initializeExports(List<ModuleCapability> exports, BundleLoaderSources sources, Collection<String> exportNames) {
if (exports != null) {
for (ModuleCapability export : exports) {
String name = (String) export.getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE);
if (sources.forceSourceCreation(export)) {
if (!exportNames.contains(name)) {
// must force filtered and reexport sources to be created early
// to prevent lazy normal package source creation.
// We only do this for the first export of a package name.
sources.createPackageSource(export, true);
}
}
exportNames.add(name);
}
}
}
use of org.eclipse.osgi.container.ModuleCapability in project rt.equinox.framework by eclipse.
the class FrameworkExtensionInstaller method getExtensionFiles.
/**
* Returns a list of classpath files for an extension bundle
* @param revision revision for the extension bundle
* @return a list of classpath files for an extension bundle
*/
private File[] getExtensionFiles(ModuleRevision revision) {
List<ModuleCapability> metaDatas = revision.getModuleCapabilities(EquinoxModuleDataNamespace.MODULE_DATA_NAMESPACE);
@SuppressWarnings("unchecked") List<String> paths = metaDatas.isEmpty() ? null : (List<String>) metaDatas.get(0).getAttributes().get(EquinoxModuleDataNamespace.CAPABILITY_CLASSPATH);
if (paths == null) {
paths = new ArrayList<>(1);
// $NON-NLS-1$
paths.add(".");
}
if (configuration.inDevelopmentMode()) {
String[] devPaths = configuration.getDevClassPath(revision.getSymbolicName());
for (String devPath : devPaths) {
paths.add(devPath);
}
}
List<File> results = new ArrayList<>(paths.size());
for (String path : paths) {
if (".".equals(path)) {
// $NON-NLS-1$
results.add(((Generation) revision.getRevisionInfo()).getBundleFile().getBaseFile());
} else {
File result = ((Generation) revision.getRevisionInfo()).getBundleFile().getFile(path, false);
if (result != null)
results.add(result);
}
}
return results.toArray(new File[results.size()]);
}
use of org.eclipse.osgi.container.ModuleCapability in project rt.equinox.framework by eclipse.
the class NativeCodeBundleTests method setNativeAttribute.
private void setNativeAttribute(String key, String value) {
Bundle systemBundle = OSGiTestsActivator.getContext().getBundle(0);
ModuleRevision systemRevision = (ModuleRevision) systemBundle.adapt(BundleRevision.class);
ModuleCapability nativeCapability = systemRevision.getModuleCapabilities(NativeNamespace.NATIVE_NAMESPACE).get(0);
Map attrs = new HashMap(nativeCapability.getAttributes());
attrs.put(key, value);
nativeCapability.setTransientAttrs(attrs);
}
use of org.eclipse.osgi.container.ModuleCapability in project rt.equinox.framework by eclipse.
the class TestModuleContainer method testUTF8LineContinuation.
@Test
public void testUTF8LineContinuation() throws BundleException, IOException {
DummyContainerAdaptor adaptor = createDummyAdaptor();
ModuleContainer container = adaptor.getContainer();
String utfString = "a.with.�.multibyte";
while (utfString.getBytes("UTF8").length < 500) {
Map<String, String> manifest = getUTFManifest(utfString);
Module testModule = installDummyModule(manifest, manifest.get(Constants.BUNDLE_SYMBOLICNAME), container);
Assert.assertEquals("Wrong bns for the bundle.", utfString, testModule.getCurrentRevision().getSymbolicName());
ModuleCapability exportPackage = testModule.getCurrentRevision().getModuleCapabilities(PackageNamespace.PACKAGE_NAMESPACE).get(0);
ModuleRequirement importPackage = testModule.getCurrentRevision().getModuleRequirements(PackageNamespace.PACKAGE_NAMESPACE).get(0);
String actualPackageName = (String) exportPackage.getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE);
Assert.assertEquals("Wrong exported package name.", utfString, actualPackageName);
Assert.assertTrue("import does not match export: " + importPackage, importPackage.matches(exportPackage));
utfString = "a" + utfString;
}
}
Aggregations