use of org.osgi.framework.wiring.BundleCapability in project aries by apache.
the class SubsystemResolverHook method filterMatches.
public void filterMatches(BundleRequirement requirement, Collection<BundleCapability> candidates) {
// Filter out candidates that don't come from preferred providers when
// there is at least one preferred provider.
// (1) Find the subsystem(s) containing requirement.getResource() as a
// constituent.
Collection<BasicSubsystem> requirers = subsystems.getSubsystemsReferencing(requirement.getResource());
// (2) For each candidate, ask each subsystem if the candidate or any of
// the candidate's containing subsystems is a preferred provider. If at
// least one preferred provider exists, filter out all other candidates
// that are not also preferred providers.
Collection<BundleCapability> preferredProviders = new ArrayList<BundleCapability>(candidates.size());
for (BundleCapability candidate : candidates) for (BasicSubsystem subsystem : requirers) {
PreferredProviderHeader header = subsystem.getSubsystemManifest().getPreferredProviderHeader();
if (header != null && (header.contains(candidate.getResource()) || isResourceConstituentOfPreferredSubsystem(candidate.getResource(), subsystem)))
preferredProviders.add(candidate);
}
if (!preferredProviders.isEmpty())
candidates.retainAll(preferredProviders);
}
use of org.osgi.framework.wiring.BundleCapability in project karaf by apache.
the class BundleWiresTest method testFilterMatches.
@Test
public void testFilterMatches() throws IOException {
BundleWires wires = readFromFile();
BundleRequirement req = packageRequirement(packageFilter);
BundleCapability candidate1 = bundleCap(targetBundleId, targetBundleVersion);
List<BundleCapability> candidates = new ArrayList<>();
candidates.add(candidate1);
BundleCapability matchingCandidate = bundleCap(targetBundleId, "1.1.0");
candidates.add(matchingCandidate);
c.replay();
wires.filterMatches(req, candidates);
assertEquals(1, candidates.size());
assertEquals(candidate1, candidates.iterator().next());
c.verify();
}
use of org.osgi.framework.wiring.BundleCapability in project karaf by apache.
the class BundleWiresTest method bundleCap.
private BundleCapability bundleCap(long bundleId, String version) {
BundleRevision rev = c.createMock(BundleRevision.class);
Bundle bundle = c.createMock(Bundle.class);
expect(bundle.getBundleId()).andReturn(bundleId);
expect(rev.getBundle()).andReturn(bundle);
BundleCapability cap = c.createMock(BundleCapability.class);
expect(cap.getRevision()).andReturn(rev);
Map<String, Object> attrs = new HashMap<>();
attrs.put(Constants.VERSION_ATTRIBUTE, version);
expect(cap.getAttributes()).andReturn(attrs);
return cap;
}
use of org.osgi.framework.wiring.BundleCapability in project karaf by apache.
the class Headers method checkPackage.
private boolean checkPackage(String packageName, String version) {
VersionRange range = VersionRange.parseVersionRange(version);
Bundle[] bundles = bundleContext.getBundles();
for (int i = 0; (bundles != null) && (i < bundles.length); i++) {
BundleWiring wiring = bundles[i].adapt(BundleWiring.class);
List<BundleCapability> caps = wiring != null ? wiring.getCapabilities(BundleRevision.PACKAGE_NAMESPACE) : null;
if (caps != null) {
for (BundleCapability cap : caps) {
String n = getAttribute(cap, BundleRevision.PACKAGE_NAMESPACE);
String v = getAttribute(cap, Constants.VERSION_ATTRIBUTE);
if (packageName.equals(n) && range.contains(VersionTable.getVersion(v))) {
return true;
}
}
}
}
return false;
}
use of org.osgi.framework.wiring.BundleCapability in project karaf by apache.
the class PackageServiceImpl method getExports.
public List<PackageVersion> getExports() {
Bundle[] bundles = bundleContext.getBundles();
SortedMap<String, PackageVersion> packageVersionMap = new TreeMap<>();
for (Bundle bundle : bundles) {
BundleRevision rev = bundle.adapt(BundleRevision.class);
if (rev != null) {
List<BundleCapability> caps = rev.getDeclaredCapabilities(BundleRevision.PACKAGE_NAMESPACE);
for (BundleCapability cap : caps) {
Map<String, Object> attr = cap.getAttributes();
String packageName = (String) attr.get(BundleRevision.PACKAGE_NAMESPACE);
Version version = (Version) attr.get("version");
String key = packageName + ":" + version.toString();
PackageVersion pVer = packageVersionMap.computeIfAbsent(key, k -> new PackageVersion(packageName, version));
pVer.addBundle(bundle);
}
}
}
return new ArrayList<>(packageVersionMap.values());
}
Aggregations