Search in sources :

Example 1 with VersionRange

use of org.osgi.framework.VersionRange in project felix by apache.

the class RequirementParser method toBundleFilter.

private static String toBundleFilter(String bsn, String versionRangeStr) {
    final String filterStr;
    String bsnFilter = String.format("(%s=%s)", BundleNamespace.BUNDLE_NAMESPACE, bsn);
    if (versionRangeStr == null) {
        filterStr = bsnFilter;
    } else {
        VersionRange versionRange = new VersionRange(versionRangeStr);
        if (versionRange.isExact()) {
            String exactVersionFilter = String.format("(%s=%s)", BundleNamespace.CAPABILITY_BUNDLE_VERSION_ATTRIBUTE, versionRange.getLeft());
            filterStr = String.format("(&%s%s)", bsnFilter, exactVersionFilter);
        } else if (versionRange.getRight() == null) {
            filterStr = String.format("(&%s%s)", bsnFilter, lowerVersionFilter(versionRange));
        } else {
            filterStr = String.format("(&%s%s%s)", bsnFilter, lowerVersionFilter(versionRange), upperVersionFilter(versionRange));
        }
    }
    return filterStr;
}
Also used : VersionRange(org.osgi.framework.VersionRange)

Example 2 with VersionRange

use of org.osgi.framework.VersionRange in project sling by apache.

the class BundleBlackList method getBlackListFromBootstrapFile.

private void getBlackListFromBootstrapFile(BufferedReader r) throws IOException {
    String line = null;
    while ((line = r.readLine()) != null) {
        line = line.trim();
        String bundleSymbolicName = null;
        VersionRange versionRange = null;
        if (line.length() > 0 && line.startsWith(UNINSTALL_PREFIX)) {
            final String[] s = line.split(" ");
            extractBlackList(bundleSymbolicName, versionRange, s, 1, 2);
        }
    }
}
Also used : VersionRange(org.osgi.framework.VersionRange)

Example 3 with VersionRange

use of org.osgi.framework.VersionRange in project rt.equinox.framework by eclipse.

the class OSGiManifestBuilderFactory method addPackageImports.

private static void addPackageImports(ModuleRevisionBuilder builder, ManifestElement[] importElements, Collection<String> importPackageNames, boolean dynamic) throws BundleException {
    if (importElements == null)
        return;
    for (ManifestElement importElement : importElements) {
        String[] packageNames = importElement.getValueComponents();
        Map<String, Object> attributes = getAttributes(importElement);
        Map<String, String> directives = getDirectives(importElement);
        directives.remove(PackageNamespace.REQUIREMENT_EFFECTIVE_DIRECTIVE);
        directives.remove(PackageNamespace.REQUIREMENT_CARDINALITY_DIRECTIVE);
        if (dynamic) {
            directives.put(PackageNamespace.REQUIREMENT_RESOLUTION_DIRECTIVE, PackageNamespace.RESOLUTION_DYNAMIC);
        }
        String versionRangeAttr = (String) attributes.remove(PackageNamespace.CAPABILITY_VERSION_ATTRIBUTE);
        @SuppressWarnings("deprecation") String specVersionRangeAttr = (String) attributes.remove(Constants.PACKAGE_SPECIFICATION_VERSION);
        VersionRange versionRange = versionRangeAttr == null ? (specVersionRangeAttr == null ? null : new VersionRange(specVersionRangeAttr)) : new VersionRange(versionRangeAttr);
        String bundleVersionRangeAttr = (String) attributes.remove(PackageNamespace.CAPABILITY_BUNDLE_VERSION_ATTRIBUTE);
        VersionRange bundleVersionRange = bundleVersionRangeAttr == null ? null : new VersionRange(bundleVersionRangeAttr);
        // the attribute "optional" used to be used in old versions of equinox to specify optional imports
        // preserving behavior for compatibility
        Object optionalAttr = attributes.remove(Namespace.RESOLUTION_OPTIONAL);
        for (String packageName : packageNames) {
            if (!dynamic) {
                importPackageNames.add(packageName);
            }
            // fill in the filter directive based on the attributes
            Map<String, String> packageDirectives = new HashMap<>(directives);
            StringBuilder filter = new StringBuilder();
            filter.append('(').append(PackageNamespace.PACKAGE_NAMESPACE).append('=').append(packageName).append(')');
            int size = filter.length();
            for (Map.Entry<String, Object> attribute : attributes.entrySet()) filter.append('(').append(attribute.getKey()).append('=').append(attribute.getValue()).append(')');
            if (versionRange != null)
                filter.append(versionRange.toFilterString(PackageNamespace.CAPABILITY_VERSION_ATTRIBUTE));
            if (bundleVersionRange != null)
                filter.append(bundleVersionRange.toFilterString(PackageNamespace.CAPABILITY_BUNDLE_VERSION_ATTRIBUTE));
            if (size != filter.length())
                // need to add (&...)
                // $NON-NLS-1$
                filter.insert(0, "(&").append(')');
            packageDirectives.put(PackageNamespace.REQUIREMENT_FILTER_DIRECTIVE, filter.toString());
            // fill in cardinality for dynamic wild cards
            if (dynamic && packageName.indexOf('*') >= 0)
                packageDirectives.put(PackageNamespace.REQUIREMENT_CARDINALITY_DIRECTIVE, PackageNamespace.CARDINALITY_MULTIPLE);
            // check the old optional attribute
            if ("true".equals(optionalAttr) && packageDirectives.get(Namespace.REQUIREMENT_RESOLUTION_DIRECTIVE) == null) {
                // $NON-NLS-1$
                packageDirectives.put(Namespace.REQUIREMENT_RESOLUTION_DIRECTIVE, Namespace.RESOLUTION_OPTIONAL);
            }
            builder.addRequirement(PackageNamespace.PACKAGE_NAMESPACE, packageDirectives, new HashMap<String, Object>(0));
        }
    }
}
Also used : ManifestElement(org.eclipse.osgi.util.ManifestElement) HashMap(java.util.HashMap) VersionRange(org.osgi.framework.VersionRange) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with VersionRange

use of org.osgi.framework.VersionRange in project rt.equinox.framework by eclipse.

the class OSGiManifestBuilderFactory method getRequireBundle.

private static void getRequireBundle(ModuleRevisionBuilder builder, ManifestElement[] requireBundles) throws BundleException {
    if (requireBundles == null)
        return;
    for (ManifestElement requireElement : requireBundles) {
        String[] bundleNames = requireElement.getValueComponents();
        Map<String, Object> attributes = getAttributes(requireElement);
        Map<String, String> directives = getDirectives(requireElement);
        directives.remove(BundleNamespace.REQUIREMENT_CARDINALITY_DIRECTIVE);
        directives.remove(BundleNamespace.REQUIREMENT_EFFECTIVE_DIRECTIVE);
        String versionRangeAttr = (String) attributes.remove(BundleNamespace.CAPABILITY_BUNDLE_VERSION_ATTRIBUTE);
        VersionRange versionRange = versionRangeAttr == null ? null : new VersionRange(versionRangeAttr);
        // These two attrs are used as directives in previous versions of equinox
        // Preserving behavior for compatibility reasons.
        Object optionalAttr = attributes.remove(Namespace.RESOLUTION_OPTIONAL);
        Object reprovideAttr = attributes.remove(ATTR_OLD_REPRIVIDE);
        for (String bundleName : bundleNames) {
            if (bundleName.equals(builder.getSymbolicName())) {
                // ignore requirements to ourself
                continue;
            }
            // fill in the filter directive based on the attributes
            Map<String, String> bundleDirectives = new HashMap<>(directives);
            StringBuilder filter = new StringBuilder();
            filter.append('(').append(BundleNamespace.BUNDLE_NAMESPACE).append('=').append(bundleName).append(')');
            int size = filter.length();
            for (Map.Entry<String, Object> attribute : attributes.entrySet()) filter.append('(').append(attribute.getKey()).append('=').append(attribute.getValue()).append(')');
            if (versionRange != null)
                filter.append(versionRange.toFilterString(BundleNamespace.CAPABILITY_BUNDLE_VERSION_ATTRIBUTE));
            if (size != filter.length())
                // need to add (&...)
                // $NON-NLS-1$
                filter.insert(0, "(&").append(')');
            bundleDirectives.put(BundleNamespace.REQUIREMENT_FILTER_DIRECTIVE, filter.toString());
            // check the old compatibility attributes
            if ("true".equals(optionalAttr) && bundleDirectives.get(Namespace.REQUIREMENT_RESOLUTION_DIRECTIVE) == null) {
                // $NON-NLS-1$
                bundleDirectives.put(Namespace.REQUIREMENT_RESOLUTION_DIRECTIVE, Namespace.RESOLUTION_OPTIONAL);
            }
            if ("true".equals(reprovideAttr) && bundleDirectives.get(BundleNamespace.REQUIREMENT_VISIBILITY_DIRECTIVE) == null) {
                // $NON-NLS-1$
                bundleDirectives.put(BundleNamespace.REQUIREMENT_VISIBILITY_DIRECTIVE, BundleNamespace.VISIBILITY_REEXPORT);
            }
            builder.addRequirement(BundleNamespace.BUNDLE_NAMESPACE, bundleDirectives, new HashMap<String, Object>(0));
        }
    }
}
Also used : ManifestElement(org.eclipse.osgi.util.ManifestElement) HashMap(java.util.HashMap) VersionRange(org.osgi.framework.VersionRange) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with VersionRange

use of org.osgi.framework.VersionRange in project rt.equinox.framework by eclipse.

the class OSGiManifestBuilderFactory method getFragmentHost.

private static void getFragmentHost(ModuleRevisionBuilder builder, ManifestElement[] fragmentHosts) throws BundleException {
    if (fragmentHosts == null || fragmentHosts.length == 0)
        return;
    ManifestElement fragmentHost = fragmentHosts[0];
    String hostName = fragmentHost.getValue();
    Map<String, Object> attributes = getAttributes(fragmentHost);
    Map<String, String> directives = getDirectives(fragmentHost);
    directives.remove(HostNamespace.REQUIREMENT_CARDINALITY_DIRECTIVE);
    directives.remove(HostNamespace.REQUIREMENT_EFFECTIVE_DIRECTIVE);
    String versionRangeAttr = (String) attributes.remove(HostNamespace.CAPABILITY_BUNDLE_VERSION_ATTRIBUTE);
    VersionRange versionRange = versionRangeAttr == null ? null : new VersionRange(versionRangeAttr);
    // fill in the filter directive based on the attributes
    StringBuilder filter = new StringBuilder();
    filter.append('(').append(HostNamespace.HOST_NAMESPACE).append('=').append(hostName).append(')');
    int size = filter.length();
    for (Map.Entry<String, Object> attribute : attributes.entrySet()) filter.append('(').append(attribute.getKey()).append('=').append(attribute.getValue()).append(')');
    if (versionRange != null)
        filter.append(versionRange.toFilterString(HostNamespace.CAPABILITY_BUNDLE_VERSION_ATTRIBUTE));
    if (size != filter.length())
        // need to add (&...)
        // $NON-NLS-1$
        filter.insert(0, "(&").append(')');
    directives.put(BundleNamespace.REQUIREMENT_FILTER_DIRECTIVE, filter.toString());
    builder.addRequirement(HostNamespace.HOST_NAMESPACE, directives, new HashMap<String, Object>(0));
    // Add a fragment capability to advertise what host this resource is providing a fragment for
    directives = Collections.singletonMap(EquinoxModuleDataNamespace.CAPABILITY_EFFECTIVE_DIRECTIVE, EquinoxModuleDataNamespace.EFFECTIVE_INFORMATION);
    builder.addCapability(EquinoxFragmentNamespace.FRAGMENT_NAMESPACE, directives, Collections.<String, Object>singletonMap(EquinoxFragmentNamespace.FRAGMENT_NAMESPACE, hostName));
}
Also used : ManifestElement(org.eclipse.osgi.util.ManifestElement) VersionRange(org.osgi.framework.VersionRange) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

VersionRange (org.osgi.framework.VersionRange)18 Version (org.osgi.framework.Version)7 HashMap (java.util.HashMap)4 Test (org.junit.Test)4 Map (java.util.Map)3 ManifestElement (org.eclipse.osgi.util.ManifestElement)3 File (java.io.File)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ZipFile (org.apache.commons.compress.archivers.zip.ZipFile)2 Requirement (org.osgi.resource.Requirement)2 Artifact (io.fabric8.patch.management.Artifact)1 Artifact.isSameButVersion (io.fabric8.patch.management.Artifact.isSameButVersion)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedList (java.util.LinkedList)1 Matcher (java.util.regex.Matcher)1 SimpleFilter (org.apache.aries.subsystem.core.capabilityset.SimpleFilter)1 BasicRequirement (org.apache.aries.subsystem.core.internal.BasicRequirement)1 LocationPattern (org.apache.karaf.features.LocationPattern)1 BundleReplacements (org.apache.karaf.features.internal.model.processing.BundleReplacements)1