use of org.osgi.framework.wiring.BundleCapability in project karaf by apache.
the class BundleWiresTest method testFilterCandidates.
@Test
public void testFilterCandidates() throws IOException {
BundleWires wires = readFromFile();
BundleRequirement req = packageRequirement(packageFilter);
BundleCapability candidate1 = bundleCap(targetBundleId, targetBundleVersion, true);
List<BundleCapability> candidates = new ArrayList<>();
candidates.add(candidate1);
BundleCapability matchingCandidate = bundleCap(targetBundleId, "1.1.0", true);
candidates.add(matchingCandidate);
c.replay();
Set<BundleCapability> goodCandidates = wires.filterCandidates(req, candidates);
assertEquals(1, goodCandidates.size());
assertEquals(candidate1, goodCandidates.iterator().next());
c.verify();
}
use of org.osgi.framework.wiring.BundleCapability in project navajo by Dexels.
the class CustomJavaFileFolder method enumerateWiring.
private void enumerateWiring(String packageName, List<JavaFileObject> result, Bundle b) {
String packageNameDot = packageName.replaceAll("/", ".");
if (b.getSymbolicName().startsWith("navajo.script")) {
// ignore script bundles
return;
}
BundleWiring bw = b.adapt(BundleWiring.class);
if (bw == null) {
return;
}
boolean foundExportedPackage = false;
List<BundleCapability> sss = bw.getCapabilities("osgi.wiring.package");
for (BundleCapability bundleWire : sss) {
String exported = (String) bundleWire.getAttributes().get("osgi.wiring.package");
if (packageNameDot.equals(exported)) {
foundExportedPackage = true;
}
}
if (!foundExportedPackage) {
return;
}
Collection<String> cc = bw.listResources(packageName, null, BundleWiring.LISTRESOURCES_LOCAL);
for (String resource : cc) {
URL u = b.getResource(resource);
if (u != null) {
URI uri = null;
try {
uri = u.toURI();
final CustomJavaFileObject customJavaFileObject = new CustomJavaFileObject(resource, uri, u.toURI(), Kind.CLASS);
result.add(customJavaFileObject);
contentMap.put(resource, customJavaFileObject);
} catch (Exception e1) {
logger.warn("URI failed for URL: {} ignoring.", u);
}
}
}
}
use of org.osgi.framework.wiring.BundleCapability in project tycho by eclipse.
the class DependencyComputer method getRequiredBundlePackages.
private void getRequiredBundlePackages(ModuleWire requiredWire, Set<String> importedPackageNames, Map<String, Set<ModuleCapability>> packages, Map<ModuleWiring, Map<String, Set<ModuleCapability>>> allSources) {
ModuleWiring providerWiring = requiredWire.getProviderWiring();
for (ModuleCapability packageCapability : providerWiring.getModuleCapabilities(PackageNamespace.PACKAGE_NAMESPACE)) {
String packageName = getPackageName(packageCapability);
// if imported then packages from required bundles do not get added
if (!importedPackageNames.contains(packageName)) {
addAggregatePackageSource(packageCapability, packageName, requiredWire, packages, allSources);
}
}
// get the declared packages
Set<String> declaredPackageNames = new HashSet<>();
for (BundleCapability declaredPackage : providerWiring.getRevision().getDeclaredCapabilities(PackageNamespace.PACKAGE_NAMESPACE)) {
declaredPackageNames.add(getPackageName(declaredPackage));
}
// and from attached fragments
for (BundleWire fragmentWire : providerWiring.getProvidedWires(HostNamespace.HOST_NAMESPACE)) {
for (BundleCapability declaredPackage : fragmentWire.getRequirer().getDeclaredCapabilities(PackageNamespace.PACKAGE_NAMESPACE)) {
declaredPackageNames.add(getPackageName(declaredPackage));
}
}
for (ModuleWire packageWire : providerWiring.getRequiredModuleWires(PackageNamespace.PACKAGE_NAMESPACE)) {
String packageName = getPackageName(packageWire.getCapability());
if (!importedPackageNames.contains(packageName) && declaredPackageNames.contains(packageName)) {
// if the package is a declared capability AND the wiring imports the package
// then it is substituted
addAggregatePackageSource(packageWire.getCapability(), packageName, packageWire, packages, allSources);
}
}
}
use of org.osgi.framework.wiring.BundleCapability in project ecf by eclipse.
the class RemoteServiceAdmin method getVersionForPackage.
private Version getVersionForPackage(final Bundle providingBundle, String packageName) {
Version result = null;
BundleRevision providingBundleRevision = AccessController.doPrivileged(new PrivilegedAction<BundleRevision>() {
public BundleRevision run() {
return providingBundle.adapt(BundleRevision.class);
}
});
if (providingBundleRevision == null)
return null;
List<BundleCapability> providerCapabilities = providingBundleRevision.getDeclaredCapabilities(BundleRevision.PACKAGE_NAMESPACE);
for (BundleCapability c : providerCapabilities) {
result = getVersionForMatchingCapability(packageName, c);
if (result != null)
return result;
}
return result;
}
use of org.osgi.framework.wiring.BundleCapability in project ecf by eclipse.
the class RemoteServiceAdmin method getPackageVersionViaRequestingBundle.
private Version getPackageVersionViaRequestingBundle(String packageName, final Bundle requestingBundle, Version remoteVersion) {
Version result = null;
// First check the requesting bundle for the desired export package
// capability
BundleRevision requestingBundleRevision = AccessController.doPrivileged(new PrivilegedAction<BundleRevision>() {
public BundleRevision run() {
return requestingBundle.adapt(BundleRevision.class);
}
});
if (requestingBundleRevision != null) {
List<BundleCapability> requestingBundleCapabilities = requestingBundleRevision.getDeclaredCapabilities(BundleRevision.PACKAGE_NAMESPACE);
for (BundleCapability requestingBundleCapability : requestingBundleCapabilities) {
Version candidate = getVersionForMatchingCapability(packageName, requestingBundleCapability);
// If found, set our result
if (candidate != null) {
if (remoteVersion != null && candidate.equals(remoteVersion))
return candidate;
result = candidate;
}
}
}
// look in exported package that are wired to the requesting bundle
if (result == null) {
// look for wired exported packages
BundleWiring requestingBundleWiring = requestingBundle.adapt(BundleWiring.class);
if (requestingBundleWiring != null) {
result = getPackageVersionForMatchingWire(packageName, requestingBundleWiring.getRequiredWires(BundleRevision.PACKAGE_NAMESPACE), BundleRevision.PACKAGE_NAMESPACE);
// in wired require bundles
if (result == null)
result = getPackageVersionForMatchingWire(packageName, requestingBundleWiring.getRequiredWires(BundleRevision.BUNDLE_NAMESPACE), BundleRevision.BUNDLE_NAMESPACE);
}
}
return result;
}
Aggregations