use of org.osgi.service.indexer.impl.types.SymbolicName in project bnd by bndtools.
the class Util method getSymbolicName.
public static SymbolicName getSymbolicName(Resource resource) throws IOException {
Manifest manifest = resource.getManifest();
if (manifest == null)
throw new IllegalArgumentException(String.format("Cannot identify symbolic name for resource %s: manifest unavailable", resource.getLocation()));
String header = manifest.getMainAttributes().getValue(Constants.BUNDLE_SYMBOLICNAME);
if (header == null)
throw new IllegalArgumentException("Not an OSGi R4+ bundle: missing 'Bundle-SymbolicName' entry from manifest.");
Map<String, Map<String, String>> map = OSGiHeader.parseHeader(header);
if (map.size() != 1)
throw new IllegalArgumentException("Invalid format for Bundle-SymbolicName header.");
Entry<String, Map<String, String>> entry = map.entrySet().iterator().next();
return new SymbolicName(entry.getKey(), entry.getValue());
}
use of org.osgi.service.indexer.impl.types.SymbolicName in project bnd by bndtools.
the class BundleAnalyzer method doBundleIdentity.
private void doBundleIdentity(Resource resource, MimeType mimeType, List<? super Capability> caps) throws Exception {
Manifest manifest = resource.getManifest();
if (manifest == null)
throw new IllegalArgumentException("Missing bundle manifest.");
String type;
switch(mimeType) {
case Bundle:
type = Namespaces.RESOURCE_TYPE_BUNDLE;
break;
case Fragment:
type = Namespaces.RESOURCE_TYPE_FRAGMENT;
break;
default:
type = Namespaces.RESOURCE_TYPE_PLAIN_JAR;
break;
}
SymbolicName bsn = Util.getSymbolicName(resource);
boolean singleton = Boolean.TRUE.toString().equalsIgnoreCase(bsn.getAttributes().get(Constants.SINGLETON_DIRECTIVE + ":"));
Version version = Util.getVersion(resource);
Builder builder = new Builder().setNamespace(Namespaces.NS_IDENTITY).addAttribute(Namespaces.NS_IDENTITY, bsn.getName()).addAttribute(Namespaces.ATTR_IDENTITY_TYPE, type).addAttribute(Namespaces.ATTR_VERSION, version);
if (singleton)
builder.addDirective(Namespaces.DIRECTIVE_SINGLETON, Boolean.TRUE.toString());
caps.add(builder.buildCapability());
}
use of org.osgi.service.indexer.impl.types.SymbolicName in project bnd by bndtools.
the class KnownBundleAnalyzer method analyzeResource.
public void analyzeResource(Resource resource, List<Capability> caps, List<Requirement> reqs) throws Exception {
SymbolicName resourceName;
try {
resourceName = Util.getSymbolicName(resource);
} catch (IllegalArgumentException e) {
// not a bundle, so return without analyzing
return;
}
for (Enumeration<?> names = defaultProperties.propertyNames(); names.hasMoreElements(); ) {
String propName = (String) names.nextElement();
processPropertyName(resource, caps, reqs, resourceName, propName, defaultProperties);
}
if (extraProperties != null)
for (Enumeration<?> names = extraProperties.propertyNames(); names.hasMoreElements(); ) {
String propName = (String) names.nextElement();
processPropertyName(resource, caps, reqs, resourceName, propName, extraProperties, defaultProperties);
}
}
use of org.osgi.service.indexer.impl.types.SymbolicName 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.impl.types.SymbolicName 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());
}
}
Aggregations