Search in sources :

Example 16 with Builder

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());
}
Also used : Version(org.osgi.framework.Version) Builder(org.osgi.service.indexer.Builder) Attributes(java.util.jar.Attributes) SymbolicName(org.osgi.service.indexer.impl.types.SymbolicName)

Example 17 with Builder

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());
    }
}
Also used : Version(org.osgi.framework.Version) Builder(org.osgi.service.indexer.Builder) Manifest(java.util.jar.Manifest) SymbolicName(org.osgi.service.indexer.impl.types.SymbolicName) Map(java.util.Map)

Example 18 with Builder

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);
    }
}
Also used : Builder(org.osgi.service.indexer.Builder) Map(java.util.Map)

Aggregations

Builder (org.osgi.service.indexer.Builder)18 Map (java.util.Map)10 Manifest (java.util.jar.Manifest)5 Version (org.osgi.framework.Version)5 VersionRange (org.osgi.service.indexer.impl.types.VersionRange)4 Requirement (org.osgi.service.indexer.Requirement)3 SymbolicName (org.osgi.service.indexer.impl.types.SymbolicName)3 Capability (org.osgi.service.indexer.Capability)2 Resource (org.osgi.service.indexer.Resource)2 Project (aQute.bnd.build.Project)1 WorkspaceR5Repository (bndtools.central.WorkspaceR5Repository)1 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1