Search in sources :

Example 1 with Builder

use of org.osgi.service.indexer.Builder in project bnd by bndtools.

the class SCRAnalyzer method createRequirement.

private static Requirement createRequirement(VersionRange range) {
    Builder builder = new Builder().setNamespace(Namespaces.NS_EXTENDER);
    StringBuilder filter = new StringBuilder();
    filter.append('(').append(Namespaces.NS_EXTENDER).append('=').append(Namespaces.EXTENDER_SCR).append(')');
    filter.insert(0, "(&");
    Util.addVersionFilter(filter, range, VersionKey.PackageVersion);
    filter.append(')');
    builder.addDirective(Namespaces.DIRECTIVE_FILTER, filter.toString()).addDirective(Namespaces.DIRECTIVE_EFFECTIVE, Namespaces.EFFECTIVE_ACTIVE);
    Requirement requirement = builder.buildRequirement();
    return requirement;
}
Also used : Requirement(org.osgi.service.indexer.Requirement) Builder(org.osgi.service.indexer.Builder)

Example 2 with Builder

use of org.osgi.service.indexer.Builder in project bnd by bndtools.

the class BundleAnalyzer method doPlainJarIdentity.

private void doPlainJarIdentity(Resource resource, List<? super Capability> caps) {
    String name = (String) resource.getProperties().get(Resource.NAME);
    if (name.toLowerCase().endsWith(SUFFIX_JAR))
        name = name.substring(0, name.length() - SUFFIX_JAR.length());
    Version version = null;
    int dashIndex = name.lastIndexOf('-');
    if (dashIndex > 0) {
        try {
            String versionStr = name.substring(dashIndex + 1);
            version = new Version(versionStr);
            name = name.substring(0, dashIndex);
        } catch (Exception e) {
            version = null;
        }
    }
    Builder builder = new Builder().setNamespace(Namespaces.NS_IDENTITY).addAttribute(Namespaces.NS_IDENTITY, name).addAttribute(Namespaces.ATTR_IDENTITY_TYPE, Namespaces.RESOURCE_TYPE_PLAIN_JAR);
    if (version != null)
        builder.addAttribute(Namespaces.ATTR_VERSION, version);
    caps.add(builder.buildCapability());
}
Also used : Version(org.osgi.framework.Version) Builder(org.osgi.service.indexer.Builder) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 3 with Builder

use of org.osgi.service.indexer.Builder 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());
}
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)

Example 4 with Builder

use of org.osgi.service.indexer.Builder in project bnd by bndtools.

the class BundleAnalyzer method doImports.

private void doImports(Resource resource, List<? super Requirement> reqs) throws Exception {
    Manifest manifest = resource.getManifest();
    String importsStr = manifest.getMainAttributes().getValue(Constants.IMPORT_PACKAGE);
    Map<String, Map<String, String>> imports = OSGiHeader.parseHeader(importsStr);
    for (Entry<String, Map<String, String>> entry : imports.entrySet()) {
        StringBuilder filter = new StringBuilder();
        String pkgName = OSGiHeader.removeDuplicateMarker(entry.getKey());
        filter.append("(osgi.wiring.package=").append(pkgName).append(")");
        String versionStr = entry.getValue().get(Constants.VERSION_ATTRIBUTE);
        if (versionStr != null) {
            VersionRange version = new VersionRange(versionStr);
            filter.insert(0, "(&");
            Util.addVersionFilter(filter, version, VersionKey.PackageVersion);
            filter.append(")");
        }
        Builder builder = new Builder().setNamespace(Namespaces.NS_WIRING_PACKAGE).addDirective(Namespaces.DIRECTIVE_FILTER, filter.toString());
        copyAttribsAndDirectives(entry.getValue(), builder, Constants.VERSION_ATTRIBUTE, "specification-version");
        reqs.add(builder.buildRequirement());
    }
}
Also used : Builder(org.osgi.service.indexer.Builder) VersionRange(org.osgi.service.indexer.impl.types.VersionRange) Manifest(java.util.jar.Manifest) Map(java.util.Map)

Example 5 with Builder

use of org.osgi.service.indexer.Builder in project bnd by bndtools.

the class BundleAnalyzer method doBREE.

private void doBREE(Resource resource, List<? super Requirement> reqs) throws Exception {
    @SuppressWarnings("deprecation") String breeStr = resource.getManifest().getMainAttributes().getValue(Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT);
    Map<String, Map<String, String>> brees = OSGiHeader.parseHeader(breeStr);
    final String filter;
    if (!brees.isEmpty()) {
        if (brees.size() == 1) {
            String bree = brees.keySet().iterator().next();
            filter = EE.parseBREE(bree).toFilter();
        } else {
            StringBuilder builder = new StringBuilder().append("(|");
            for (String bree : brees.keySet()) {
                bree = OSGiHeader.removeDuplicateMarker(bree);
                builder.append(EE.parseBREE(bree).toFilter());
            }
            builder.append(')');
            filter = builder.toString();
        }
        Requirement requirement = new Builder().setNamespace(Namespaces.NS_EE).addDirective(Namespaces.DIRECTIVE_FILTER, filter).buildRequirement();
        reqs.add(requirement);
    }
}
Also used : Requirement(org.osgi.service.indexer.Requirement) 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