use of org.apache.felix.utils.resource.CapabilityImpl in project karaf by apache.
the class ResourceUtils method toFeatureCapability.
public static String toFeatureCapability(String feature) {
String[] parts = feature.split("/");
Map<String, String> dirs = Collections.emptyMap();
Map<String, Object> attrs = new StringArrayMap<>(parts.length > 1 ? 3 : 2);
attrs.put(IDENTITY_NAMESPACE, parts[0]);
attrs.put(CAPABILITY_TYPE_ATTRIBUTE, TYPE_FEATURE);
if (parts.length > 1) {
attrs.put(CAPABILITY_VERSION_ATTRIBUTE, VersionTable.getVersion(parts[1]));
}
return new CapabilityImpl(null, IDENTITY_NAMESPACE, dirs, attrs).toString();
}
use of org.apache.felix.utils.resource.CapabilityImpl in project karaf by apache.
the class Subsystem method cloneResource.
ResourceImpl cloneResource(Resource resource) {
ResourceImpl res = new ResourceImpl();
for (Capability cap : resource.getCapabilities(null)) {
res.addCapability(new CapabilityImpl(res, cap.getNamespace(), new StringArrayMap<>(cap.getDirectives()), new StringArrayMap<>(cap.getAttributes())));
}
for (Requirement req : resource.getRequirements(null)) {
SimpleFilter sf;
if (req instanceof RequirementImpl) {
sf = ((RequirementImpl) req).getFilter();
} else if (req.getDirectives().containsKey(REQUIREMENT_FILTER_DIRECTIVE)) {
sf = SimpleFilter.parse(req.getDirectives().get(REQUIREMENT_FILTER_DIRECTIVE));
} else {
sf = SimpleFilter.convert(req.getAttributes());
}
res.addRequirement(new RequirementImpl(res, req.getNamespace(), new StringArrayMap<>(req.getDirectives()), new StringArrayMap<>(req.getAttributes()), sf));
}
return res;
}
use of org.apache.felix.utils.resource.CapabilityImpl in project karaf by apache.
the class SubsystemResolver method prepare.
@Override
public void prepare(Map<String, List<Feature>> allFeatures, Map<String, Set<String>> requirements, Map<String, Set<BundleRevision>> system) throws Exception {
// related requirements. Each region's subsystem will also _require_ all child subsystems
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++) {
String childName = String.join("/", Arrays.copyOfRange(parts, 0, i + 1));
ss = getOrCreateChild(ss, childName, parts[i]);
}
for (String requirement : entry.getValue()) {
// #1a. each "[feature:]*" and "requirement:*" requirements are added directly as resource requirements:
// - feature: ns=osgi.identity, 'osgi.identity=f1; type=karaf.feature; filter:="(&(osgi.identity=f1)(type=karaf.feature))"'
// - requirement: as-is
// - bundle: added only as downloadable bundle - used only by assembly builder
ss.require(requirement);
}
}
if (root == null) {
return;
}
// #2. Pre-resolve
// - for each region's subsystem X, feature requirements are changed into child subsystems of X
// - for each feature, any dependant features (<feature>/<feature>) will become non-mandatory (why?)
// child subsystem of the same region's subsystem as original feature
// - for each feature, any conditional (<feature>/<conditional>) will become mandatory (why?)
// child subsystem of the original feature's subsystem
root.build(allFeatures);
// #3. Add system resources
// - from all unmanaged bundles we'll gather Provide-Capability headers' clauses in "osgi.service" namespace
// and Export-Service headers
// - these capabilities will be added to "dummy" Resource added as o.a.k.features.internal.region.Subsystem.installable
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