use of org.osgi.service.indexer.Builder in project bnd by bndtools.
the class BundleAnalyzer method doBundleAndHost.
private void doBundleAndHost(Resource resource, List<? super Capability> caps) throws Exception {
Builder bundleBuilder = new Builder().setNamespace(Namespaces.NS_WIRING_BUNDLE);
Builder hostBuilder = new Builder().setNamespace(Namespaces.NS_WIRING_HOST);
boolean allowFragments = true;
Attributes attribs = resource.getManifest().getMainAttributes();
if (attribs.getValue(Constants.FRAGMENT_HOST) != null)
return;
SymbolicName bsn = Util.getSymbolicName(resource);
Version version = Util.getVersion(resource);
bundleBuilder.addAttribute(Namespaces.NS_WIRING_BUNDLE, bsn.getName()).addAttribute(Constants.BUNDLE_VERSION_ATTRIBUTE, version);
hostBuilder.addAttribute(Namespaces.NS_WIRING_HOST, bsn.getName()).addAttribute(Constants.BUNDLE_VERSION_ATTRIBUTE, version);
for (Entry<String, String> attribEntry : bsn.getAttributes().entrySet()) {
String key = attribEntry.getKey();
if (key.endsWith(":")) {
String directiveName = key.substring(0, key.length() - 1);
if (Constants.FRAGMENT_ATTACHMENT_DIRECTIVE.equalsIgnoreCase(directiveName)) {
if (Constants.FRAGMENT_ATTACHMENT_NEVER.equalsIgnoreCase(attribEntry.getValue()))
allowFragments = false;
} else if (!Constants.SINGLETON_DIRECTIVE.equalsIgnoreCase(directiveName)) {
bundleBuilder.addDirective(directiveName, attribEntry.getValue());
}
} else {
bundleBuilder.addAttribute(key, attribEntry.getValue());
}
}
caps.add(bundleBuilder.buildCapability());
if (allowFragments)
caps.add(hostBuilder.buildCapability());
}
use of org.osgi.service.indexer.Builder in project bnd by bndtools.
the class BundleAnalyzer method doExports.
private void doExports(Resource resource, List<? super Capability> caps) throws Exception {
Manifest manifest = resource.getManifest();
String exportsStr = manifest.getMainAttributes().getValue(Constants.EXPORT_PACKAGE);
Map<String, Map<String, String>> exports = OSGiHeader.parseHeader(exportsStr);
for (Entry<String, Map<String, String>> entry : exports.entrySet()) {
Builder builder = new Builder().setNamespace(Namespaces.NS_WIRING_PACKAGE);
String pkgName = OSGiHeader.removeDuplicateMarker(entry.getKey());
builder.addAttribute(Namespaces.NS_WIRING_PACKAGE, pkgName);
String versionStr = entry.getValue().get(Constants.VERSION_ATTRIBUTE);
Version version = (versionStr != null) ? new Version(versionStr) : new Version(0, 0, 0);
builder.addAttribute(Namespaces.ATTR_VERSION, version);
for (Entry<String, String> attribEntry : entry.getValue().entrySet()) {
String key = attribEntry.getKey();
if (!"specification-version".equalsIgnoreCase(key) && !Constants.VERSION_ATTRIBUTE.equalsIgnoreCase(key)) {
if (key.endsWith(":"))
builder.addDirective(key.substring(0, key.length() - 1), attribEntry.getValue());
else
builder.addAttribute(key, attribEntry.getValue());
}
}
SymbolicName bsn = Util.getSymbolicName(resource);
builder.addAttribute(Namespaces.ATTR_BUNDLE_SYMBOLIC_NAME, bsn.getName());
Version bundleVersion = Util.getVersion(resource);
builder.addAttribute(Namespaces.ATTR_BUNDLE_VERSION, bundleVersion);
caps.add(builder.buildCapability());
}
}
use of org.osgi.service.indexer.Builder in project bnd by bndtools.
the class BundleAnalyzer method buildFromHeader.
private static void buildFromHeader(String headerStr, Yield<Builder> output) {
if (headerStr == null)
return;
Map<String, Map<String, String>> header = OSGiHeader.parseHeader(headerStr);
for (Entry<String, Map<String, String>> entry : header.entrySet()) {
String namespace = OSGiHeader.removeDuplicateMarker(entry.getKey());
Builder builder = new Builder().setNamespace(namespace);
Map<String, String> attribs = entry.getValue();
Util.copyAttribsToBuilder(builder, attribs);
output.yield(builder);
}
}
Aggregations