use of org.osgi.framework.wiring.BundleRequirement in project karaf by apache.
the class BundleServiceImpl method getDiag.
@Override
public String getDiag(Bundle bundle) {
StringBuilder message = new StringBuilder();
for (BundleStateService bundleStateService : stateServices) {
String part = bundleStateService.getDiag(bundle);
if (part != null) {
message.append(bundleStateService.getName());
message.append("\n");
message.append(part);
}
}
if (bundle.getState() == Bundle.INSTALLED) {
System.out.println("Unsatisfied Requirements:");
List<BundleRequirement> reqs = getUnsatisfiedRequirements(bundle, null);
for (BundleRequirement req : reqs) {
System.out.println(req);
}
}
return message.toString();
}
use of org.osgi.framework.wiring.BundleRequirement in project karaf by apache.
the class Requirements method printMatchingRequirements.
private static boolean printMatchingRequirements(BundleWiring wiring, Pattern namespace) {
List<BundleWire> wires = wiring.getRequiredWires(null);
Map<BundleRequirement, List<BundleWire>> aggregateReqs = aggregateRequirements(namespace, wires);
List<BundleRequirement> allReqs = wiring.getRequirements(null);
boolean matches = false;
for (BundleRequirement req : allReqs) {
if (matchNamespace(namespace, req.getNamespace())) {
matches = true;
List<BundleWire> providers = aggregateReqs.get(req);
if (providers != null) {
System.out.println(req.getNamespace() + "; " + req.getDirectives().get(Constants.FILTER_DIRECTIVE) + " resolved by:");
for (BundleWire wire : providers) {
String msg;
Object keyAttr = wire.getCapability().getAttributes().get(wire.getCapability().getNamespace());
if (keyAttr != null) {
msg = wire.getCapability().getNamespace() + "; " + keyAttr + " " + getVersionFromCapability(wire.getCapability());
} else {
msg = wire.getCapability().toString();
}
msg = " " + msg + " from " + wire.getProviderWiring().getBundle();
System.out.println(msg);
}
} else {
System.out.println(req.getNamespace() + "; " + req.getDirectives().get(Constants.FILTER_DIRECTIVE) + " " + UNRESOLVED_MESSAGE);
}
}
}
return matches;
}
use of org.osgi.framework.wiring.BundleRequirement in project karaf by apache.
the class BundleInstallSupportImpl method resolveBundles.
@Override
public void resolveBundles(Set<Bundle> bundles, final Map<Resource, List<Wire>> wiring, Map<Resource, Bundle> resToBnd) {
// Make sure it's only used for us
final Thread thread = Thread.currentThread();
// Translate wiring
final Map<Bundle, Resource> bndToRes = new HashMap<>();
for (Resource res : resToBnd.keySet()) {
bndToRes.put(resToBnd.get(res), res);
}
// Hook
final ResolverHook hook = new ResolverHook() {
@Override
public void filterResolvable(Collection<BundleRevision> candidates) {
}
@Override
public void filterSingletonCollisions(BundleCapability singleton, Collection<BundleCapability> collisionCandidates) {
}
@Override
public void filterMatches(BundleRequirement requirement, Collection<BundleCapability> candidates) {
if (Thread.currentThread() == thread) {
// osgi.ee capabilities are provided by the system bundle, so just ignore those
if (ExecutionEnvironmentNamespace.EXECUTION_ENVIRONMENT_NAMESPACE.equals(requirement.getNamespace())) {
return;
}
Bundle sourceBundle = requirement.getRevision().getBundle();
Resource sourceResource = bndToRes.get(sourceBundle);
List<Wire> wires = wiring.get(sourceResource);
if (sourceBundle == null || wires == null) {
// is being resolve at the same time, so do not interfere
return;
}
Set<Resource> wired = new HashSet<>();
// Get a list of allowed wired resources
wired.add(sourceResource);
for (Wire wire : wires) {
wired.add(wire.getProvider());
if (HostNamespace.HOST_NAMESPACE.equals(wire.getRequirement().getNamespace())) {
for (Wire hostWire : wiring.get(wire.getProvider())) {
wired.add(hostWire.getProvider());
}
}
}
// Remove candidates that are not allowed
for (Iterator<BundleCapability> candIter = candidates.iterator(); candIter.hasNext(); ) {
BundleCapability cand = candIter.next();
BundleRevision br = cand.getRevision();
if ((br.getTypes() & BundleRevision.TYPE_FRAGMENT) != 0) {
br = br.getWiring().getRequiredWires(null).get(0).getProvider();
}
Resource res = bndToRes.get(br.getBundle());
if (!wired.contains(br) && !wired.contains(res)) {
candIter.remove();
}
}
}
}
@Override
public void end() {
}
};
hooks.put(Thread.currentThread(), hook);
try {
FrameworkWiring frameworkWiring = systemBundleContext.getBundle().adapt(FrameworkWiring.class);
frameworkWiring.resolveBundles(bundles);
} finally {
hooks.remove(Thread.currentThread());
}
}
use of org.osgi.framework.wiring.BundleRequirement in project karaf by apache.
the class BundleWiresTest method testFilterCandidatesSelfSatisfiedCapability.
@Test
public void testFilterCandidatesSelfSatisfiedCapability() throws IOException {
// no wires are created with itself
Bundle bundle = wiredBundle(Collections.emptyList());
BundleCapability candidate1 = bundleCap(1, targetBundleVersion, false);
List<BundleCapability> candidates = new ArrayList<>();
candidates.add(candidate1);
BundleCapability matchingCandidate = bundleCap(2, "1.1.0", false);
candidates.add(matchingCandidate);
BundleRequirement req = packageRequirement(packageFilter);
c.replay();
BundleWires wires = new BundleWires(bundle);
Set<BundleCapability> goodCandidates = wires.filterCandidates(req, candidates);
assertEquals(1, goodCandidates.size());
assertEquals(candidate1, goodCandidates.iterator().next());
c.verify();
}
use of org.osgi.framework.wiring.BundleRequirement 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();
}
Aggregations