Search in sources :

Example 1 with ModuleCapability

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

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);
        }
    }
}
Also used : ModuleCapability(org.eclipse.osgi.container.ModuleCapability)

Example 3 with ModuleCapability

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()]);
}
Also used : Generation(org.eclipse.osgi.storage.BundleInfo.Generation) ArrayList(java.util.ArrayList) ModuleCapability(org.eclipse.osgi.container.ModuleCapability) File(java.io.File)

Example 4 with ModuleCapability

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);
}
Also used : HashMap(java.util.HashMap) Bundle(org.osgi.framework.Bundle) BundleRevision(org.osgi.framework.wiring.BundleRevision) ModuleCapability(org.eclipse.osgi.container.ModuleCapability) ModuleRevision(org.eclipse.osgi.container.ModuleRevision) Map(java.util.Map) HashMap(java.util.HashMap)

Example 5 with ModuleCapability

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;
    }
}
Also used : DummyContainerAdaptor(org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor) ModuleContainer(org.eclipse.osgi.container.ModuleContainer) ModuleCapability(org.eclipse.osgi.container.ModuleCapability) Module(org.eclipse.osgi.container.Module) ModuleRequirement(org.eclipse.osgi.container.ModuleRequirement) Test(org.junit.Test)

Aggregations

ModuleCapability (org.eclipse.osgi.container.ModuleCapability)11 Module (org.eclipse.osgi.container.Module)6 ModuleContainer (org.eclipse.osgi.container.ModuleContainer)4 ModuleRevision (org.eclipse.osgi.container.ModuleRevision)4 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)3 ModuleWire (org.eclipse.osgi.container.ModuleWire)3 ModuleWiring (org.eclipse.osgi.container.ModuleWiring)3 DummyContainerAdaptor (org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor)3 File (java.io.File)2 HashMap (java.util.HashMap)2 Generation (org.eclipse.osgi.storage.BundleInfo.Generation)2 BundleCapability (org.osgi.framework.wiring.BundleCapability)2 Requirement (org.osgi.resource.Requirement)2 ExportedPackage (org.osgi.service.packageadmin.ExportedPackage)2 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 PrivilegedActionException (java.security.PrivilegedActionException)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1