Search in sources :

Example 1 with VersionRange

use of org.apache.felix.utils.version.VersionRange in project karaf by apache.

the class Subsystem method doBuild.

private void doBuild(Collection<Feature> features, boolean mandatory) throws Exception {
    for (Subsystem child : children) {
        child.doBuild(features, true);
    }
    if (feature != null) {
        for (Dependency dep : feature.getDependencies()) {
            Subsystem ss = this;
            while (!ss.isAcceptDependencies()) {
                ss = ss.getParent();
            }
            ss.requireFeature(dep.getName(), dep.getVersion(), false);
        }
        for (Conditional cond : feature.getConditional()) {
            Feature fcond = cond.asFeature();
            String ssName = this.name + "#" + (fcond.hasVersion() ? fcond.getName() + "-" + fcond.getVersion() : fcond.getName());
            Subsystem fs = getChild(ssName);
            if (fs == null) {
                fs = new Subsystem(ssName, fcond, this, true);
                fs.doBuild(features, false);
                installable.add(fs);
                children.add(fs);
            }
        }
    }
    List<Requirement> processed = new ArrayList<>();
    while (true) {
        List<Requirement> requirements = getRequirements(IDENTITY_NAMESPACE);
        requirements.addAll(dependentFeatures);
        requirements.removeAll(processed);
        if (requirements.isEmpty()) {
            break;
        }
        for (Requirement requirement : requirements) {
            String name = (String) requirement.getAttributes().get(IDENTITY_NAMESPACE);
            String type = (String) requirement.getAttributes().get(CAPABILITY_TYPE_ATTRIBUTE);
            VersionRange range = (VersionRange) requirement.getAttributes().get(CAPABILITY_VERSION_ATTRIBUTE);
            if (TYPE_FEATURE.equals(type)) {
                for (Feature feature : features) {
                    if (feature.getName().equals(name) && (range == null || range.contains(VersionTable.getVersion(feature.getVersion())))) {
                        if (feature != this.feature) {
                            String ssName = this.name + "#" + (feature.hasVersion() ? feature.getName() + "-" + feature.getVersion() : feature.getName());
                            Subsystem fs = getChild(ssName);
                            if (fs == null) {
                                fs = new Subsystem(ssName, feature, this, mandatory && !SubsystemResolveContext.isOptional(requirement));
                                fs.build(features);
                                installable.add(fs);
                                children.add(fs);
                            }
                        }
                    }
                }
            }
            processed.add(requirement);
        }
    }
}
Also used : ResourceUtils.addIdentityRequirement(org.apache.karaf.features.internal.resolver.ResourceUtils.addIdentityRequirement) ResourceUtils.toFeatureRequirement(org.apache.karaf.features.internal.resolver.ResourceUtils.toFeatureRequirement) Requirement(org.osgi.resource.Requirement) ArrayList(java.util.ArrayList) Conditional(org.apache.karaf.features.Conditional) VersionRange(org.apache.felix.utils.version.VersionRange) Dependency(org.apache.karaf.features.Dependency) Feature(org.apache.karaf.features.Feature)

Example 2 with VersionRange

use of org.apache.felix.utils.version.VersionRange in project karaf by apache.

the class Blacklist method blacklist.

public static boolean blacklist(Feature feature, Clause[] clauses) {
    for (Clause clause : clauses) {
        // Check feature name
        if (clause.getName().equals(feature.getName())) {
            // Check feature version
            VersionRange range = VersionRange.ANY_VERSION;
            String vr = clause.getAttribute(BLACKLIST_RANGE);
            if (vr != null) {
                range = new VersionRange(vr, true);
            }
            if (range.contains(VersionTable.getVersion(feature.getVersion()))) {
                String type = clause.getAttribute(BLACKLIST_TYPE);
                if (type == null || TYPE_FEATURE.equals(type)) {
                    return true;
                }
            }
        }
        // Check bundles
        blacklist(feature.getBundle(), clauses);
        // Check conditional bundles
        for (Conditional cond : feature.getConditional()) {
            blacklist(cond.getBundle(), clauses);
        }
    }
    return false;
}
Also used : VersionRange(org.apache.felix.utils.version.VersionRange) Conditional(org.apache.karaf.features.internal.model.Conditional) Clause(org.apache.felix.utils.manifest.Clause)

Example 3 with VersionRange

use of org.apache.felix.utils.version.VersionRange in project karaf by apache.

the class ResourceUtils method toFeatureRequirement.

public static String toFeatureRequirement(String feature) {
    String[] parts = feature.split("/");
    Map<String, Object> attrs = new HashMap<>();
    attrs.put(IDENTITY_NAMESPACE, parts[0]);
    attrs.put(CAPABILITY_TYPE_ATTRIBUTE, TYPE_FEATURE);
    if (parts.length > 1) {
        attrs.put(CAPABILITY_VERSION_ATTRIBUTE, new VersionRange(parts[1]));
    }
    Map<String, String> dirs = new HashMap<>();
    dirs.put(Constants.FILTER_DIRECTIVE, SimpleFilter.convert(attrs).toString());
    return new RequirementImpl(null, IDENTITY_NAMESPACE, dirs, attrs).toString();
}
Also used : HashMap(java.util.HashMap) VersionRange(org.apache.felix.utils.version.VersionRange)

Example 4 with VersionRange

use of org.apache.felix.utils.version.VersionRange in project karaf by apache.

the class ShowBundleTree method createNodeForImport.

/*
     * Create a child node for a given import (by finding a matching export in the currently installed bundles)
     */
private void createNodeForImport(Node<Bundle> node, Bundle bundle, Clause i) {
    VersionRange range = VersionRange.parseVersionRange(i.getAttribute(Constants.VERSION_ATTRIBUTE));
    boolean foundMatch = false;
    for (Bundle b : bundleContext.getBundles()) {
        BundleWiring wiring = b.adapt(BundleWiring.class);
        if (wiring != null) {
            List<BundleCapability> caps = wiring.getCapabilities(BundleRevision.PACKAGE_NAMESPACE);
            if (caps != null) {
                for (BundleCapability cap : caps) {
                    String n = getAttribute(cap, BundleRevision.PACKAGE_NAMESPACE);
                    String v = getAttribute(cap, Constants.VERSION_ATTRIBUTE);
                    if (i.getName().equals(n) && range.contains(VersionTable.getVersion(v))) {
                        boolean existing = tree.flatten().contains(b);
                        System.out.printf("- import %s: resolved using %s%n", i, b);
                        foundMatch = true;
                        if (!node.hasChild(b)) {
                            Node<Bundle> child = node.addChild(b);
                            if (!existing) {
                                createNode(child);
                            }
                        }
                    }
                }
            }
        }
    }
    if (!foundMatch) {
        System.out.printf("- import %s: WARNING - unable to find matching export%n", i);
    }
}
Also used : Bundle(org.osgi.framework.Bundle) BundleWiring(org.osgi.framework.wiring.BundleWiring) VersionRange(org.apache.felix.utils.version.VersionRange) BundleCapability(org.osgi.framework.wiring.BundleCapability)

Example 5 with VersionRange

use of org.apache.felix.utils.version.VersionRange in project karaf by apache.

the class Headers method checkBundle.

private boolean checkBundle(String bundleName, String version) {
    VersionRange vr = VersionRange.parseVersionRange(version);
    Bundle[] bundles = bundleContext.getBundles();
    for (int i = 0; (bundles != null) && (i < bundles.length); i++) {
        String sym = bundles[i].getSymbolicName();
        if ((sym != null) && sym.equals(bundleName)) {
            if (vr.contains(bundles[i].getVersion())) {
                return true;
            }
        }
    }
    return false;
}
Also used : Bundle(org.osgi.framework.Bundle) VersionRange(org.apache.felix.utils.version.VersionRange)

Aggregations

VersionRange (org.apache.felix.utils.version.VersionRange)20 Version (org.osgi.framework.Version)8 Bundle (org.osgi.framework.Bundle)7 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 Feature (org.apache.karaf.features.Feature)5 InputStream (java.io.InputStream)4 EnumSet (java.util.EnumSet)4 HashSet (java.util.HashSet)4 List (java.util.List)4 Set (java.util.Set)4 TreeSet (java.util.TreeSet)4 IOException (java.io.IOException)3 URL (java.net.URL)3 Collection (java.util.Collection)3 Collections (java.util.Collections)3 Hashtable (java.util.Hashtable)3 Map (java.util.Map)3 Manifest (java.util.jar.Manifest)3 Clause (org.apache.felix.utils.manifest.Clause)3