use of org.osgi.framework.wiring.BundleRequirement in project aries by apache.
the class ProviderBundleTrackerCustomizerGenericCapabilityTest method testCapReqHeadersInFragment.
@Test
public void testCapReqHeadersInFragment() throws Exception {
Bundle mediatorBundle = EasyMock.createMock(Bundle.class);
EasyMock.expect(mediatorBundle.getBundleId()).andReturn(42l).anyTimes();
EasyMock.replay(mediatorBundle);
BaseActivator activator = new BaseActivator() {
@Override
public void start(BundleContext context) throws Exception {
}
};
ProviderBundleTrackerCustomizer customizer = new ProviderBundleTrackerCustomizer(activator, mediatorBundle);
ServiceRegistration<?> sreg = EasyMock.createNiceMock(ServiceRegistration.class);
EasyMock.replay(sreg);
BundleContext implBC = mockSPIBundleContext(sreg);
Dictionary<String, String> headers = new Hashtable<String, String>();
// A typical requirement that is not for us...
headers.put(SpiFlyConstants.REQUIRE_CAPABILITY, "osgi.ee;filter:=\"(&(osgi.ee=JavaSE)(version=1.6))\"");
List<BundleWire> wires = new ArrayList<BundleWire>();
BundleWire wire = EasyMock.createMock(BundleWire.class);
Bundle fragment = EasyMock.createMock(Bundle.class);
BundleRevision frev = EasyMock.createMock(BundleRevision.class);
EasyMock.expect(frev.getBundle()).andReturn(fragment).anyTimes();
EasyMock.replay(frev);
BundleRequirement req = EasyMock.createMock(BundleRequirement.class);
EasyMock.expect(req.getRevision()).andReturn(frev).anyTimes();
EasyMock.replay(req);
EasyMock.expect(wire.getRequirement()).andReturn(req).anyTimes();
EasyMock.replay(wire);
wires.add(wire);
BundleWiring bw = EasyMock.createMock(BundleWiring.class);
EasyMock.expect(bw.getProvidedWires("osgi.wiring.host")).andReturn(wires).anyTimes();
EasyMock.replay(bw);
BundleRevision rev = EasyMock.createMock(BundleRevision.class);
EasyMock.expect(rev.getWiring()).andReturn(bw).anyTimes();
EasyMock.expect(rev.getTypes()).andReturn(0).anyTimes();
EasyMock.replay(rev);
Bundle implBundle = mockSPIBundle(implBC, headers, rev);
Dictionary<String, String> fheaders = new Hashtable<String, String>();
fheaders.put(SpiFlyConstants.REQUIRE_CAPABILITY, SpiFlyConstants.PROVIDER_REQUIREMENT);
fheaders.put(SpiFlyConstants.PROVIDE_CAPABILITY, SpiFlyConstants.SERVICELOADER_CAPABILITY_NAMESPACE + "; " + SpiFlyConstants.SERVICELOADER_CAPABILITY_NAMESPACE + "=org.apache.aries.mytest.MySPI");
EasyMock.expect(fragment.getHeaders()).andReturn(fheaders).anyTimes();
EasyMock.replay(fragment);
assertEquals("Precondition", 0, activator.findProviderBundles("org.apache.aries.mytest.MySPI").size());
customizer.addingBundle(implBundle, null);
Collection<Bundle> bundles = activator.findProviderBundles("org.apache.aries.mytest.MySPI");
assertEquals(1, bundles.size());
assertSame(implBundle, bundles.iterator().next());
}
use of org.osgi.framework.wiring.BundleRequirement in project aries by apache.
the class BundleWiringData method getWiresCompositeData.
private CompositeData[] getWiresCompositeData(List<BundleWire> wires) throws OpenDataException {
CompositeData[] reqWiresData = new CompositeData[wires.size()];
for (int i = 0; i < wires.size(); i++) {
BundleWire requiredWire = wires.get(i);
Map<String, Object> wireItems = new HashMap<String, Object>();
BundleCapability capability = requiredWire.getCapability();
wireItems.put(BundleWiringStateMBean.PROVIDER_BUNDLE_ID, capability.getRevision().getBundle().getBundleId());
wireItems.put(BundleWiringStateMBean.PROVIDER_BUNDLE_REVISION_ID, revisionIDMap.get(capability.getRevision()));
wireItems.put(BundleWiringStateMBean.BUNDLE_CAPABILITY, getCapReqCompositeData(BundleWiringStateMBean.BUNDLE_CAPABILITY_TYPE, capability.getNamespace(), capability.getAttributes().entrySet(), capability.getDirectives().entrySet()));
BundleRequirement requirement = requiredWire.getRequirement();
wireItems.put(BundleWiringStateMBean.REQUIRER_BUNDLE_ID, requirement.getRevision().getBundle().getBundleId());
wireItems.put(BundleWiringStateMBean.REQUIRER_BUNDLE_REVISION_ID, revisionIDMap.get(requirement.getRevision()));
wireItems.put(BundleWiringStateMBean.BUNDLE_REQUIREMENT, getCapReqCompositeData(BundleWiringStateMBean.BUNDLE_REQUIREMENT_TYPE, requirement.getNamespace(), requirement.getAttributes().entrySet(), requirement.getDirectives().entrySet()));
CompositeData wireData = new CompositeDataSupport(BundleWiringStateMBean.BUNDLE_WIRE_TYPE, wireItems);
reqWiresData[i] = wireData;
}
return reqWiresData;
}
use of org.osgi.framework.wiring.BundleRequirement in project aries by apache.
the class BundleWiringData method getRequirementsCompositeData.
public static CompositeData[] getRequirementsCompositeData(List<BundleRequirement> bundleRequirements) {
try {
CompositeData[] data = new CompositeData[bundleRequirements.size()];
for (int i = 0; i < bundleRequirements.size(); i++) {
BundleRequirement requirement = bundleRequirements.get(i);
CompositeData cd = BundleWiringData.getCapReqCompositeData(BundleWiringStateMBean.BUNDLE_REQUIREMENT_TYPE, requirement.getNamespace(), requirement.getAttributes().entrySet(), requirement.getDirectives().entrySet());
data[i] = cd;
}
return data;
} catch (OpenDataException e) {
throw new IllegalStateException("Can't create CompositeData", e);
}
}
use of org.osgi.framework.wiring.BundleRequirement in project aries by apache.
the class BundleWiringStateMBeanTest method testGetRevisionsDeclaredRequirements.
@Test
public void testGetRevisionsDeclaredRequirements() throws Exception {
BundleRevisions revisions = (BundleRevisions) bundleA.adapt(BundleRevisions.class);
Assert.assertEquals("Precondition", 1, revisions.getRevisions().size());
TabularData jmxRequirementsTable = brsMBean.getRevisionsDeclaredRequirements(bundleA.getBundleId(), BundleRevision.PACKAGE_NAMESPACE);
Assert.assertEquals(1, jmxRequirementsTable.size());
List<BundleRequirement> requirements = ((BundleRevision) revisions.getRevisions().iterator().next()).getDeclaredRequirements(BundleRevision.PACKAGE_NAMESPACE);
CompositeData jmxRevRequirements = (CompositeData) jmxRequirementsTable.values().iterator().next();
CompositeData[] jmxRequirements = (CompositeData[]) jmxRevRequirements.get(BundleWiringStateMBean.REQUIREMENTS);
Map<Map<String, Object>, Map<String, String>> expectedRequirements = requirementsToMap(requirements);
Map<Map<String, Object>, Map<String, String>> actualRequirements = jmxCapReqToMap(jmxRequirements);
Assert.assertEquals(expectedRequirements, actualRequirements);
}
use of org.osgi.framework.wiring.BundleRequirement in project karaf by apache.
the class PackageServiceImpl method getImports.
@Override
public List<PackageRequirement> getImports() {
Bundle[] bundles = bundleContext.getBundles();
SortedMap<String, PackageRequirement> requirements = new TreeMap<>();
for (Bundle bundle : bundles) {
BundleRevision rev = bundle.adapt(BundleRevision.class);
if (rev != null) {
List<BundleRequirement> reqs = rev.getDeclaredRequirements(BundleRevision.PACKAGE_NAMESPACE);
for (BundleRequirement req : reqs) {
PackageRequirement preq = create(req, bundle);
requirements.put(preq.getPackageName() + "|" + preq.getFilter() + "|" + preq.getBundle().getBundleId(), preq);
}
}
}
return new ArrayList<>(requirements.values());
}
Aggregations