use of org.apache.felix.utils.collections.DictionaryAsMap in project karaf by apache.
the class SubsystemResolver method prepare.
public void prepare(Collection<Feature> allFeatures, Map<String, Set<String>> requirements, Map<String, Set<BundleRevision>> system) throws Exception {
// Build subsystems on the fly
for (Map.Entry<String, Set<String>> entry : requirements.entrySet()) {
String[] parts = entry.getKey().split("/");
if (root == null) {
root = new Subsystem(parts[0]);
} else if (!root.getName().equals(parts[0])) {
throw new IllegalArgumentException("Can not use multiple roots: " + root.getName() + ", " + parts[0]);
}
Subsystem ss = root;
for (int i = 1; i < parts.length; i++) {
ss = getOrCreateChild(ss, parts[i]);
}
for (String requirement : entry.getValue()) {
ss.require(requirement);
}
}
if (root == null) {
return;
}
// Pre-resolve
root.build(allFeatures);
// Add system resources
BundleRevision sysBundleRev = null;
boolean hasEeCap = false;
for (Map.Entry<String, Set<BundleRevision>> entry : system.entrySet()) {
Subsystem ss = null;
String[] parts = entry.getKey().split("/");
String path = parts[0];
if (path.equals(root.getName())) {
ss = root;
}
for (int i = 1; ss != null && i < parts.length; i++) {
path += "/" + parts[i];
ss = ss.getChild(path);
}
if (ss != null) {
ResourceImpl dummy = new ResourceImpl("dummy", "dummy", Version.emptyVersion);
for (BundleRevision res : entry.getValue()) {
// We need to explicitely provide service capabilities for bundles
// We use both actual services and services declared from the headers
// TODO: use actual services
Map<String, String> headers = new DictionaryAsMap<>(res.getBundle().getHeaders());
Resource tmp = ResourceBuilder.build(res.getBundle().getLocation(), headers);
for (Capability cap : tmp.getCapabilities(ServiceNamespace.SERVICE_NAMESPACE)) {
dummy.addCapability(new CapabilityImpl(dummy, cap.getNamespace(), cap.getDirectives(), cap.getAttributes()));
}
ss.addSystemResource(res);
for (Capability cap : res.getCapabilities(null)) {
hasEeCap |= cap.getNamespace().equals(EXECUTION_ENVIRONMENT_NAMESPACE);
}
if (res.getBundle().getBundleId() == 0) {
sysBundleRev = res;
}
}
ss.addSystemResource(dummy);
}
}
// Under Equinox, the osgi.ee capabilities are not provided by the system bundle
if (!hasEeCap && sysBundleRev != null) {
String provideCaps = sysBundleRev.getBundle().getHeaders().get(PROVIDE_CAPABILITY);
environmentResource = new ResourceImpl("environment", "karaf.environment", Version.emptyVersion);
environmentResource.addCapabilities(ResourceBuilder.parseCapability(environmentResource, provideCaps));
root.addSystemResource(environmentResource);
}
}
Aggregations