use of org.osgi.framework.wiring.BundleWiring in project knime-core by knime.
the class JavaSnippet method getAdditionalBundlesPaths.
/**
* Get jar files required for compiling with the additional bundles.
*
* @param withDeps Whether to also resolve the dependencies of the bundles.
* @return Array of .jar files.
*/
public File[] getAdditionalBundlesPaths(final boolean withDeps) {
final Set<Bundle> bundles = new LinkedHashSet<>();
final LinkedBlockingQueue<Bundle> pending = new LinkedBlockingQueue<Bundle>();
if (m_settings != null) {
// Resolve bundle names to bundles
Stream.of(m_settings.getBundles()).map(bname -> Platform.getBundle(bname.split(" ")[0])).filter(b -> b != null).collect(Collectors.toCollection(() -> pending));
}
Bundle bundle = null;
while ((bundle = pending.poll()) != null) {
if (!bundles.add(bundle)) {
continue;
}
if (withDeps) {
// resolve dependencies
final BundleWiring wiring = bundle.adapt(BundleWiring.class);
final List<BundleWire> requiredWires = wiring.getRequiredWires(BundleNamespace.BUNDLE_NAMESPACE);
for (final BundleWire w : requiredWires) {
pending.add(w.getProviderWiring().getBundle());
}
}
}
final ArrayList<File> result = new ArrayList<>();
for (final Bundle b : bundles) {
try {
result.add(FileLocator.getBundleFile(b));
} catch (IOException e) {
LOGGER.warn("Failed to get bundle file of \"" + b + "\"");
}
}
return result.toArray(new File[result.size()]);
}
use of org.osgi.framework.wiring.BundleWiring in project rt.equinox.framework by eclipse.
the class StateResolverTest method testResolveFragmentEE01.
public void testResolveFragmentEE01() throws BundleException {
State state = buildEmptyState();
Dictionary[] props = new Dictionary[] { new Hashtable() };
// $NON-NLS-1$ //$NON-NLS-2$
props[0].put("org.osgi.framework.executionenvironment", "test");
state.setPlatformProperties(props);
int bundleID = 0;
Hashtable manifest = new Hashtable();
manifest.clear();
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_SYMBOLICNAME, "org.eclipse.osgi");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
manifest.put(Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT, "test");
BundleDescription a = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME) + manifest.get(Constants.BUNDLE_VERSION), bundleID++);
manifest.clear();
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_SYMBOLICNAME, "b");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
// $NON-NLS-1$
manifest.put(Constants.FRAGMENT_HOST, "org.eclipse.osgi; bundle-version=\"[1.0, 1.1)\"");
manifest.put(Constants.REQUIRE_CAPABILITY, "osgi.ee; filter:=\"(osgi.ee=test)\"");
BundleDescription b = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME) + manifest.get(Constants.BUNDLE_VERSION), bundleID++);
manifest.clear();
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_SYMBOLICNAME, "c");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
// $NON-NLS-1$
manifest.put(Constants.REQUIRE_CAPABILITY, "osgi.identity; filter:=\"(osgi.identity=b)\"");
BundleDescription c = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME) + manifest.get(Constants.BUNDLE_VERSION), bundleID++);
state.addBundle(b);
state.addBundle(a);
state.addBundle(c);
state.resolve();
// $NON-NLS-1$
assertTrue("A is not resolved", a.isResolved());
// $NON-NLS-1$
assertTrue("B is not resolved", b.isResolved());
// $NON-NLS-1$
assertTrue("C is not resolved", c.isResolved());
BundleWiring aWiring = a.getWiring();
List aRequirements = a.getRequirements("osgi.ee");
List aRequiredWires = aWiring.getRequiredWires("osgi.ee");
assertEquals("Wrong number of osgi.ee requirements from system bundle", 1, aRequirements.size());
assertEquals("Wrong number of wires from system bundle", 1, aRequiredWires.size());
BundleWiring bWiring = b.getWiring();
List bRequirements = b.getRequirements("osgi.ee");
List bRequiredWires = bWiring.getRequiredWires("osgi.ee");
assertEquals("Wrong number of osgi.ee requirements from fragment", 1, bRequirements.size());
assertEquals("Wrong number of wires from fragment", 1, bRequiredWires.size());
BundleWiring cWiring = c.getWiring();
List cRequirements = c.getRequirements("osgi.identity");
List cRequiredWires = cWiring.getRequiredWires("osgi.identity");
assertEquals("Wrong number of osgi.identity requirements from c", 1, cRequirements.size());
assertEquals("Wrong number of wires from c", 1, cRequiredWires.size());
manifest.clear();
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_SYMBOLICNAME, "b");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
// $NON-NLS-1$
manifest.put(Constants.FRAGMENT_HOST, "org.eclipse.osgi; bundle-version=\"[1.0, 1.1)\"");
manifest.put(Constants.REQUIRE_CAPABILITY, "osgi.ee; filter:=\"(osgi.ee=fail)\"");
b = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME) + manifest.get(Constants.BUNDLE_VERSION), b.getBundleId());
state.updateBundle(b);
state.resolve(false);
// $NON-NLS-1$
assertTrue("A is not resolved", a.isResolved());
// $NON-NLS-1$
assertFalse("B is not resolved", b.isResolved());
// $NON-NLS-1$
assertFalse("C is not resolved", c.isResolved());
}
use of org.osgi.framework.wiring.BundleWiring in project rt.equinox.framework by eclipse.
the class OSGiCapabilityTest method testOSGiCardinality.
public void testOSGiCardinality() throws BundleException {
State state = buildEmptyState();
long bundleID = 0;
Dictionary manifest;
manifest = loadManifest("p1.osgi.MF");
BundleDescription p1 = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME), bundleID++);
manifest = loadManifest("p2.osgi.MF");
BundleDescription p2 = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME), bundleID++);
manifest = loadManifest("p3.osgi.MF");
BundleDescription p3 = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME), bundleID++);
manifest = loadManifest("c5.osgi.MF");
BundleDescription c5 = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME), bundleID++);
state.addBundle(p1);
state.addBundle(p2);
state.addBundle(p3);
state.addBundle(c5);
state.resolve();
assertTrue("p1", p1.isResolved());
assertTrue("p2", p2.isResolved());
assertTrue("p3", p3.isResolved());
assertTrue("c5", c5.isResolved());
BundleWiring c5Wiring = c5.getWiring();
List requiredWires = c5Wiring.getRequiredWires(null);
assertEquals("Wrong number of required wires.", 3, requiredWires.size());
List expectedCapabilities = new ArrayList();
expectedCapabilities.addAll(p1.getCapabilities("namespace.1"));
expectedCapabilities.addAll(p2.getCapabilities("namespace.1"));
expectedCapabilities.addAll(p3.getCapabilities("namespace.1"));
for (Iterator iWires = requiredWires.iterator(); iWires.hasNext(); ) {
BundleWire wire = (BundleWire) iWires.next();
expectedCapabilities.remove(wire.getCapability());
}
assertTrue("Unexpected capability wire: " + requiredWires, expectedCapabilities.isEmpty());
}
use of org.osgi.framework.wiring.BundleWiring in project rt.equinox.framework by eclipse.
the class ClassLoadingBundleTests method testBootGetResources02.
public void testBootGetResources02() throws Exception {
// This will fail on the IBM VM (see bug 409314)
if (System.getProperty(Constants.FRAMEWORK_BOOTDELEGATION) != null)
// cannot really test this if this property is set
return;
// $NON-NLS-1$
Bundle test = installer.installBundle("test");
installer.resolveBundles(new Bundle[] { test });
BundleWiring wiring = test.adapt(BundleWiring.class);
ClassLoader bcl = wiring.getClassLoader();
URLClassLoader cl = new URLClassLoader(new URL[0], bcl);
// $NON-NLS-1$
Enumeration manifests = cl.getResources("META-INF/MANIFEST.MF");
// $NON-NLS-1$
assertNotNull("manifests", manifests);
ArrayList manifestURLs = new ArrayList();
while (manifests.hasMoreElements()) manifestURLs.add(manifests.nextElement());
// $NON-NLS-1$
assertEquals("manifest number", 1, manifestURLs.size());
URL manifest = (URL) manifestURLs.get(0);
assertEquals("wrong protocol", "bundleresource", manifest.getProtocol());
int dotIndex = manifest.getHost().indexOf('.');
long bundleId = dotIndex >= 0 && dotIndex < manifest.getHost().length() - 1 ? Long.parseLong(manifest.getHost().substring(0, dotIndex)) : Long.parseLong(manifest.getHost());
// $NON-NLS-1$
assertEquals("host id", test.getBundleId(), bundleId);
cl.close();
}
use of org.osgi.framework.wiring.BundleWiring in project rt.equinox.framework by eclipse.
the class ClassLoadingBundleTests method testUninstallInUse01.
public void testUninstallInUse01() throws BundleException {
// $NON-NLS-1$
Bundle exporter1 = installer.installBundle("exporter.importer1");
BundleRevision iExporter1 = exporter1.adapt(BundleRevision.class);
// $NON-NLS-1$
Bundle exporter2 = installer.installBundle("exporter.importer2");
installer.resolveBundles(new Bundle[] { exporter1, exporter2 });
exporter1.uninstall();
// $NON-NLS-1$
Bundle importer = installer.installBundle("exporter.importer4");
installer.resolveBundles(new Bundle[] { importer });
BundleWiring importerWiring = importer.adapt(BundleWiring.class);
assertNotNull("Bundle b has no wiring.", importerWiring);
List<BundleWire> bImports = importerWiring.getRequiredWires(PackageNamespace.PACKAGE_NAMESPACE);
assertEquals("Wrong number of imported packages.", 1, bImports.size());
assertEquals("Wrong exporter.", iExporter1, bImports.get(0).getProvider());
}
Aggregations