use of org.osgi.framework.wiring.BundleWiring in project rt.equinox.framework by eclipse.
the class StateResolverTest method checkEECapabilities.
private void checkEECapabilities(List eeCapabilities, List bundles) {
assertEquals("Wrong number of ee capabilities.", 8, eeCapabilities.size());
for (int i = 0; i < eeCapabilities.size(); i++) {
Capability eeCap = (Capability) eeCapabilities.get(i);
assertEquals("Wrong namespace: " + eeCap, "osgi.ee", eeCap.getNamespace());
Map attrs = eeCap.getAttributes();
switch(i) {
case 0:
assertEquals("Wrong ee name: " + i, "OSGi/Minimum", attrs.get("osgi.ee"));
List v0 = (List) attrs.get("version");
assertEquals("Wrong number of versions: " + i, 3, v0.size());
assertTrue("Does not contain 1.0.", v0.contains(new Version("1.0")));
assertTrue("Does not contain 1.1.", v0.contains(new Version("1.1")));
assertTrue("Does not contain 1.2.", v0.contains(new Version("1.2")));
break;
case 1:
assertEquals("Wrong ee name: " + i, "CDC/Foundation", attrs.get("osgi.ee"));
List v1 = (List) attrs.get("version");
assertEquals("Wrong number of versions: " + i, 2, v1.size());
assertTrue("Does not contain 1.0.", v1.contains(new Version("1.0")));
assertTrue("Does not contain 1.1.", v1.contains(new Version("1.1")));
break;
case 2:
assertEquals("Wrong ee name: " + i, "JavaSE", attrs.get("osgi.ee"));
List v2 = (List) attrs.get("version");
assertEquals("Wrong number of versions: " + i, 5, v2.size());
assertTrue("Does not contain 1.2.", v2.contains(new Version("1.2")));
assertTrue("Does not contain 1.3.", v2.contains(new Version("1.3")));
assertTrue("Does not contain 1.4.", v2.contains(new Version("1.4")));
assertTrue("Does not contain 1.5.", v2.contains(new Version("1.5")));
assertTrue("Does not contain 1.6.", v2.contains(new Version("1.6")));
break;
case 3:
assertEquals("Wrong ee name: " + i, "AA/BB", attrs.get("osgi.ee"));
List v3 = (List) attrs.get("version");
assertNull("versions is not null", v3);
break;
case 4:
assertEquals("Wrong ee name: " + i, "CC-XX/DD-YY", attrs.get("osgi.ee"));
List v4 = (List) attrs.get("version");
assertNull("versions is not null", v4);
break;
case 5:
assertEquals("Wrong ee name: " + i, "EE/FF-YY", attrs.get("osgi.ee"));
List v5 = (List) attrs.get("version");
assertEquals("Wrong number of versions: " + i, 2, v5.size());
assertTrue("Does not contain 1.0.", v5.contains(new Version("1.0")));
assertTrue("Does not contain 2.0.", v5.contains(new Version("2.0")));
break;
case 6:
assertEquals("Wrong ee name: " + i, "GG-XX/HH", attrs.get("osgi.ee"));
List v6 = (List) attrs.get("version");
assertEquals("Wrong number of versions: " + i, 2, v6.size());
assertTrue("Does not contain 1.0.", v6.contains(new Version("1.0")));
assertTrue("Does not contain 2.0.", v6.contains(new Version("2.0")));
break;
case 7:
assertEquals("Wrong ee name: " + i, "II-1.0/JJ-2.0", attrs.get("osgi.ee"));
List v7 = (List) attrs.get("version");
assertNull("versions is not null", v7);
break;
default:
break;
}
}
assertEquals("Wrong number of bundles.", eeCapabilities.size(), bundles.size());
for (int i = 0; i < bundles.size(); i++) {
BundleDescription bundle = (BundleDescription) bundles.get(i);
assertTrue("The bundle is not resolved: " + bundle, bundle.isResolved());
BundleWiring wiring = bundle.getWiring();
List eeWires = wiring.getRequiredWires("osgi.ee");
assertNotNull("ee wires is null.", eeWires);
assertEquals("Wrong number of ee wires", 1, eeWires.size());
BundleWire wire = (BundleWire) eeWires.get(0);
assertEquals("Wired to wrong ee capability.", eeCapabilities.get(i), wire.getCapability());
}
}
use of org.osgi.framework.wiring.BundleWiring in project rt.equinox.framework by eclipse.
the class XMLParsingServiceFactory method getService.
public Object getService(Bundle bundle, ServiceRegistration<Object> registration) {
if (!setTccl || bundle == null)
return createService();
/*
* Set the TCCL while creating jaxp factory instances to the
* requesting bundles class loader. This is needed to
* work around bug 285505. There are issues if multiple
* xerces implementations are available on the bundles class path
*
* The real issue is that the ContextFinder will only delegate
* to the framework class loader in this case. This class
* loader forces the requesting bundle to be delegated to for
* TCCL loads.
*/
final ClassLoader savedClassLoader = Thread.currentThread().getContextClassLoader();
try {
BundleWiring wiring = bundle.adapt(BundleWiring.class);
ClassLoader cl = wiring == null ? null : wiring.getClassLoader();
if (cl != null)
Thread.currentThread().setContextClassLoader(cl);
return createService();
} finally {
Thread.currentThread().setContextClassLoader(savedClassLoader);
}
}
use of org.osgi.framework.wiring.BundleWiring in project rt.equinox.framework by eclipse.
the class PackageAdminImpl method getRequiredBundles.
public RequiredBundle[] getRequiredBundles(String symbolicName) {
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$//$NON-NLS-4$
String filter = "(" + BundleNamespace.BUNDLE_NAMESPACE + "=" + (symbolicName == null ? "*" : symbolicName) + ")";
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 bundleReq = ModuleContainer.createRequirement(BundleNamespace.BUNDLE_NAMESPACE, directives, attributes);
Collection<BundleCapability> bundleCaps = container.getFrameworkWiring().findProviders(bundleReq);
InternalUtils.filterCapabilityPermissions(bundleCaps);
Collection<RequiredBundle> result = new ArrayList<>();
for (BundleCapability capability : bundleCaps) {
BundleWiring wiring = capability.getRevision().getWiring();
if (wiring != null) {
result.add(new RequiredBundleImpl(capability, wiring));
}
}
return result.isEmpty() ? null : result.toArray(new RequiredBundle[result.size()]);
}
use of org.osgi.framework.wiring.BundleWiring in project rt.equinox.framework by eclipse.
the class StateResolverTest method testEECapabilityRequirement1.
public void testEECapabilityRequirement1() throws BundleException {
State state = buildEmptyState();
int bundleID = 0;
Hashtable manifest = new Hashtable();
// $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");
// $NON-NLS-1$
BundleDescription systemBundle = state.getFactory().createBundleDescription(state, manifest, "org.eclipse.osgi", bundleID++);
manifest.clear();
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_SYMBOLICNAME, "A");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT, "CDC-1.0/Foundation-1.0");
// $NON-NLS-1$
BundleDescription a = state.getFactory().createBundleDescription(state, manifest, "A", 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_REQUIREDEXECUTIONENVIRONMENT, "OSGi/Minimum-1.1");
// $NON-NLS-1$
BundleDescription b = state.getFactory().createBundleDescription(state, manifest, "B", 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_REQUIREDEXECUTIONENVIRONMENT, "J2SE-1.4");
// $NON-NLS-1$
BundleDescription c = state.getFactory().createBundleDescription(state, manifest, "C", bundleID++);
manifest.clear();
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_SYMBOLICNAME, "D");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT, "J2SE-1.4, OSGi/Minimum-1.1");
// $NON-NLS-1$
BundleDescription d = state.getFactory().createBundleDescription(state, manifest, "D", bundleID++);
manifest.clear();
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_SYMBOLICNAME, "D");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT, "AA-BB");
// $NON-NLS-1$
BundleDescription e = state.getFactory().createBundleDescription(state, manifest, "D", bundleID++);
Dictionary[] props = new Dictionary[] { new Hashtable(), new Hashtable(), new Hashtable() };
// $NON-NLS-1$ //$NON-NLS-2$
props[0].put("org.osgi.framework.executionenvironment", "OSGi/Minimum-1.0, OSGi/Minimum-1.1, OSGi/Minimum-1.2, CDC-1.0/Foundation-1.0, CDC-1.1/Foundation-1.1, AA-BB");
// $NON-NLS-1$ //$NON-NLS-2$
props[1].put("org.osgi.framework.executionenvironment", "OSGi/Minimum-1.0, OSGi/Minimum-1.1, OSGi/Minimum-1.2, JRE-1.1, J2SE-1.2, J2SE-1.3, J2SE-1.4");
// $NON-NLS-1$ //$NON-NLS-2$
props[2].put("org.osgi.framework.executionenvironment", "OSGi/Minimum-1.0, OSGi/Minimum-1.1, JRE-1.1, J2SE-1.2, J2SE-1.3");
state.setPlatformProperties(props);
state.addBundle(systemBundle);
state.addBundle(a);
state.addBundle(b);
state.addBundle(c);
state.addBundle(d);
state.addBundle(e);
state.resolve();
// $NON-NLS-1$
assertTrue("1.0", systemBundle.isResolved());
// $NON-NLS-1$
assertTrue("1.1", a.isResolved());
// $NON-NLS-1$
assertTrue("1.2", b.isResolved());
// $NON-NLS-1$
assertTrue("1.3", c.isResolved());
// $NON-NLS-1$
assertTrue("1.4", d.isResolved());
// $NON-NLS-1$
assertTrue("1.5", e.isResolved());
BundleWiring wiringA = a.getWiring();
BundleWiring wiringB = b.getWiring();
BundleWiring wiringC = c.getWiring();
BundleWiring wiringD = d.getWiring();
BundleWiring wiringE = e.getWiring();
List wiresA = wiringA.getRequiredWires("osgi.ee");
assertEquals("2.0", 1, wiresA.size());
List wiresB = wiringB.getRequiredWires("osgi.ee");
assertEquals("2.1", 1, wiresB.size());
List wiresC = wiringC.getRequiredWires("osgi.ee");
assertEquals("2.2", 1, wiresC.size());
List wiresD = wiringD.getRequiredWires("osgi.ee");
assertEquals("2.3", 1, wiresD.size());
List wiresE = wiringE.getRequiredWires("osgi.ee");
assertEquals("2.4", 1, wiresE.size());
// $NON-NLS-1$ //$NON-NLS-2$
props[0].put("org.osgi.framework.system.capabilities", "osgi.ee; osgi.ee=\"OSGi/Minimum\"; version:List<Version>=\"1.0, 1.1, 1.2\", osgi.ee; osgi.ee=\"CDC/Foundation\"; version:List<Version>=\"1.0, 1.1\", osgi.ee; osgi.ee=\"AA-BB\"");
// $NON-NLS-1$ //$NON-NLS-2$
props[1].put("org.osgi.framework.system.capabilities", "osgi.ee; osgi.ee=\"OSGi/Minimum\"; version:List<Version>=\"1.0, 1.1, 1.2\", osgi.ee; osgi.ee=\"JavaSE\"; version:List<Version>=\"1.0, 1.1, 1.2, 1.3, 1.4\"");
// $NON-NLS-1$ //$NON-NLS-2$
props[2].put("org.osgi.framework.system.capabilities", "osgi.ee; osgi.ee=\"OSGi/Minimum\"; version:List<Version>=\"1.0, 1.1\", osgi.ee; osgi.ee=\"JavaSE\"; version:List<Version>=\"1.0, 1.1, 1.2, 1.3\"");
state.setPlatformProperties(props);
state.resolve(false);
// $NON-NLS-1$
assertTrue("1.0", systemBundle.isResolved());
// $NON-NLS-1$
assertTrue("1.1", a.isResolved());
// $NON-NLS-1$
assertTrue("1.2", b.isResolved());
// $NON-NLS-1$
assertTrue("1.3", c.isResolved());
// $NON-NLS-1$
assertTrue("1.4", d.isResolved());
// $NON-NLS-1$
assertTrue("1.5", e.isResolved());
wiringA = a.getWiring();
wiringB = b.getWiring();
wiringC = c.getWiring();
wiringD = d.getWiring();
wiringE = e.getWiring();
wiresA = wiringA.getRequiredWires("osgi.ee");
assertEquals("2.0", 1, wiresA.size());
wiresB = wiringB.getRequiredWires("osgi.ee");
assertEquals("2.1", 1, wiresB.size());
wiresC = wiringC.getRequiredWires("osgi.ee");
assertEquals("2.2", 1, wiresC.size());
wiresD = wiringD.getRequiredWires("osgi.ee");
assertEquals("2.3", 1, wiresD.size());
wiresE = wiringE.getRequiredWires("osgi.ee");
assertEquals("2.4", 1, wiresE.size());
}
use of org.osgi.framework.wiring.BundleWiring in project rt.equinox.framework by eclipse.
the class SystemBundleTests method testSystemBundleLoader.
public void testSystemBundleLoader() {
Bundle systemBundle = OSGiTestsActivator.getContext().getBundle(Constants.SYSTEM_BUNDLE_LOCATION);
BundleWiring wiring = systemBundle.adapt(BundleWiring.class);
ClassLoader cl = wiring.getClassLoader();
assertNotNull("No system bundle class loader.", cl);
}
Aggregations