Search in sources :

Example 1 with VersionRange

use of org.osgi.service.indexer.impl.types.VersionRange 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 2 with VersionRange

use of org.osgi.service.indexer.impl.types.VersionRange in project bnd by bndtools.

the class BundleAnalyzer method doBundleNativeCode.

private void doBundleNativeCode(Resource resource, final List<? super Requirement> reqs) throws IOException {
    String nativeHeaderStr = resource.getManifest().getMainAttributes().getValue(Constants.BUNDLE_NATIVECODE);
    if (nativeHeaderStr == null)
        return;
    boolean optional = false;
    List<String> options = new LinkedList<String>();
    Map<String, Map<String, String>> nativeHeader = OSGiHeader.parseHeader(nativeHeaderStr);
    for (Entry<String, Map<String, String>> entry : nativeHeader.entrySet()) {
        String name = entry.getKey();
        if ("*".equals(name)) {
            optional = true;
            continue;
        }
        StringBuilder builder = new StringBuilder().append("(&");
        Map<String, String> attribs = entry.getValue();
        String osnamesFilter = buildFilter(attribs, Constants.BUNDLE_NATIVECODE_OSNAME, Namespaces.ATTR_NATIVE_OSNAME);
        if (osnamesFilter != null)
            builder.append(osnamesFilter);
        String versionRangeStr = attribs.get(Constants.BUNDLE_NATIVECODE_OSVERSION);
        if (versionRangeStr != null)
            Util.addVersionFilter(builder, new VersionRange(versionRangeStr), VersionKey.NativeOsVersion);
        String processorFilter = buildFilter(attribs, Constants.BUNDLE_NATIVECODE_PROCESSOR, Namespaces.ATTR_NATIVE_PROCESSOR);
        if (processorFilter != null)
            builder.append(processorFilter);
        String languageFilter = buildFilter(attribs, Constants.BUNDLE_NATIVECODE_LANGUAGE, Namespaces.ATTR_NATIVE_LANGUAGE);
        if (languageFilter != null)
            builder.append(languageFilter);
        String selectionFilter = attribs.get(Constants.SELECTION_FILTER_ATTRIBUTE);
        if (selectionFilter != null)
            builder.append(selectionFilter);
        builder.append(")");
        options.add(builder.toString());
    }
    if (options.isEmpty())
        return;
    String filter;
    if (options.size() == 1)
        filter = options.get(0);
    else {
        StringBuilder builder = new StringBuilder();
        builder.append("(|");
        for (String option : options) builder.append(option);
        builder.append(")");
        filter = builder.toString();
    }
    Builder builder = new Builder().setNamespace(Namespaces.NS_NATIVE).addDirective(Namespaces.DIRECTIVE_FILTER, filter);
    if (optional)
        builder.addDirective(Namespaces.DIRECTIVE_RESOLUTION, Namespaces.RESOLUTION_OPTIONAL);
    reqs.add(builder.buildRequirement());
}
Also used : Builder(org.osgi.service.indexer.Builder) VersionRange(org.osgi.service.indexer.impl.types.VersionRange) Map(java.util.Map) LinkedList(java.util.LinkedList)

Example 3 with VersionRange

use of org.osgi.service.indexer.impl.types.VersionRange in project bnd by bndtools.

the class BundleAnalyzer method doRequireBundles.

private void doRequireBundles(Resource resource, List<? super Requirement> reqs) throws Exception {
    Manifest manifest = resource.getManifest();
    String requiresStr = manifest.getMainAttributes().getValue(Constants.REQUIRE_BUNDLE);
    if (requiresStr == null)
        return;
    Map<String, Map<String, String>> requires = OSGiHeader.parseHeader(requiresStr);
    for (Entry<String, Map<String, String>> entry : requires.entrySet()) {
        StringBuilder filter = new StringBuilder();
        String bsn = OSGiHeader.removeDuplicateMarker(entry.getKey());
        filter.append("(osgi.wiring.bundle=").append(bsn).append(")");
        String versionStr = entry.getValue().get(Constants.BUNDLE_VERSION_ATTRIBUTE);
        if (versionStr != null) {
            VersionRange version = new VersionRange(versionStr);
            filter.insert(0, "(&");
            Util.addVersionFilter(filter, version, VersionKey.BundleVersion);
            filter.append(")");
        }
        Builder builder = new Builder().setNamespace(Namespaces.NS_WIRING_BUNDLE).addDirective(Namespaces.DIRECTIVE_FILTER, filter.toString());
        copyAttribsAndDirectives(entry.getValue(), builder, Constants.BUNDLE_VERSION_ATTRIBUTE);
        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 4 with VersionRange

use of org.osgi.service.indexer.impl.types.VersionRange in project bnd by bndtools.

the class BundleAnalyzer method doFragment.

private void doFragment(Resource resource, List<? super Requirement> reqs) throws Exception {
    Manifest manifest = resource.getManifest();
    String fragmentHost = manifest.getMainAttributes().getValue(Constants.FRAGMENT_HOST);
    if (fragmentHost != null) {
        StringBuilder filter = new StringBuilder();
        Map<String, Map<String, String>> fragmentList = OSGiHeader.parseHeader(fragmentHost);
        if (fragmentList.size() != 1)
            throw new IllegalArgumentException("Invalid Fragment-Host header: cannot contain multiple entries");
        Entry<String, Map<String, String>> entry = fragmentList.entrySet().iterator().next();
        String bsn = entry.getKey();
        filter.append("(&(osgi.wiring.host=").append(bsn).append(")");
        String versionStr = entry.getValue().get(Constants.BUNDLE_VERSION_ATTRIBUTE);
        VersionRange version = versionStr != null ? new VersionRange(versionStr) : new VersionRange(Version.emptyVersion.toString());
        Util.addVersionFilter(filter, version, VersionKey.BundleVersion);
        filter.append(")");
        Builder builder = new Builder().setNamespace(Namespaces.NS_WIRING_HOST).addDirective(Namespaces.DIRECTIVE_FILTER, filter.toString());
        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 VersionRange

use of org.osgi.service.indexer.impl.types.VersionRange in project bnd by bndtools.

the class KnownBundleAnalyzer method processPropertyName.

private static void processPropertyName(Resource resource, List<Capability> caps, List<Requirement> reqs, SymbolicName resourceName, String name, Properties... propertiesList) throws IOException {
    String[] bundleRef = name.split(";");
    String bsn = bundleRef[0];
    if (resourceName.getName().equals(bsn)) {
        VersionRange versionRange = null;
        if (bundleRef.length > 1)
            versionRange = new VersionRange(bundleRef[1]);
        Version version = Util.getVersion(resource);
        if (versionRange == null || versionRange.match(version)) {
            processClause(name, Util.readProcessedProperty(name, propertiesList), caps, reqs);
        }
    }
}
Also used : Version(org.osgi.framework.Version) VersionRange(org.osgi.service.indexer.impl.types.VersionRange)

Aggregations

VersionRange (org.osgi.service.indexer.impl.types.VersionRange)6 Map (java.util.Map)4 Manifest (java.util.jar.Manifest)4 Builder (org.osgi.service.indexer.Builder)4 Version (org.osgi.framework.Version)2 LinkedList (java.util.LinkedList)1 StringTokenizer (java.util.StringTokenizer)1 Requirement (org.osgi.service.indexer.Requirement)1