Search in sources :

Example 1 with SimpleFilter

use of io.fabric8.dosgi.capset.SimpleFilter in project fabric8 by jboss-fuse.

the class RequirementSort method collectDependencies.

@SuppressWarnings("unchecked")
private static <T extends Resource> Set<T> collectDependencies(T resource, CapabilitySet capSet) {
    Set<T> result = new LinkedHashSet<>();
    for (Requirement requirement : resource.getRequirements(null)) {
        String filter = requirement.getDirectives().get(Constants.FILTER_DIRECTIVE);
        SimpleFilter sf = (filter != null) ? SimpleFilter.parse(filter) : new SimpleFilter(null, null, SimpleFilter.MATCH_ALL);
        for (Capability cap : capSet.match(sf, true)) {
            result.add((T) cap.getResource());
        }
    }
    return result;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Requirement(org.osgi.resource.Requirement) Capability(org.osgi.resource.Capability) SimpleFilter(io.fabric8.agent.resolver.SimpleFilter)

Example 2 with SimpleFilter

use of io.fabric8.dosgi.capset.SimpleFilter in project fabric8 by jboss-fuse.

the class SubsystemResolver method associateFragments.

private void associateFragments() {
    SimpleFilter sf = createFilter(IDENTITY_NAMESPACE, "*", CAPABILITY_TYPE_ATTRIBUTE, TYPE_SUBSYSTEM);
    for (Map.Entry<Resource, List<Wire>> entry : wiring.entrySet()) {
        final Resource resource = entry.getKey();
        final Requirement requirement = getSubsystemRequirement(resource);
        if (isFragment(resource)) {
            List<Wire> wires = entry.getValue();
            final Resource host = wires.get(0).getProvider();
            final Wire wire = findMatchingWire(sf, wiring.get(host));
            if (wire != null) {
                wires.add(new Wire() {

                    @Override
                    public Capability getCapability() {
                        return wire.getCapability();
                    }

                    @Override
                    public Requirement getRequirement() {
                        return requirement;
                    }

                    @Override
                    public Resource getProvider() {
                        return wire.getProvider();
                    }

                    @Override
                    public Resource getRequirer() {
                        return resource;
                    }
                });
            }
        }
    }
}
Also used : Requirement(org.osgi.resource.Requirement) Capability(org.osgi.resource.Capability) SimpleFilter(io.fabric8.agent.resolver.SimpleFilter) Resource(org.osgi.resource.Resource) List(java.util.List) Wire(org.osgi.resource.Wire) HashMap(java.util.HashMap) DictionaryAsMap(org.apache.felix.utils.collections.DictionaryAsMap) Map(java.util.Map)

Example 3 with SimpleFilter

use of io.fabric8.dosgi.capset.SimpleFilter in project fabric8 by jboss-fuse.

the class SubsystemResolver method getResourceMapping.

private Map<Resource, String> getResourceMapping(SimpleFilter resourceFilter) {
    Map<String, String> flats = getFlatSubsystemsMap();
    Map<Resource, List<Wire>> wiring = getWiring();
    Map<Resource, String> resources = new HashMap<>();
    SimpleFilter sf = createFilter(IDENTITY_NAMESPACE, "*", CAPABILITY_TYPE_ATTRIBUTE, TYPE_SUBSYSTEM);
    if (wiring != null) {
        for (Resource resource : wiring.keySet()) {
            if (findMatchingCapability(resourceFilter, resource.getCapabilities(null)) != null) {
                // Find the subsystem where this feature is installed
                Wire wire = findMatchingWire(sf, wiring.get(resource));
                if (wire != null) {
                    String region = (String) wire.getCapability().getAttributes().get(IDENTITY_NAMESPACE);
                    region = flats.get(region);
                    resources.put(resource, region);
                }
            }
        }
    }
    return resources;
}
Also used : HashMap(java.util.HashMap) SimpleFilter(io.fabric8.agent.resolver.SimpleFilter) Resource(org.osgi.resource.Resource) List(java.util.List) Wire(org.osgi.resource.Wire)

Example 4 with SimpleFilter

use of io.fabric8.dosgi.capset.SimpleFilter in project fabric8 by jboss-fuse.

the class SubsystemResolver method getBundles.

public Map<Resource, String> getBundles() {
    if (bundles == null) {
        String filter = String.format("(&(%s=*)(|(%s=%s)(%s=%s)))", IDENTITY_NAMESPACE, CAPABILITY_TYPE_ATTRIBUTE, TYPE_BUNDLE, CAPABILITY_TYPE_ATTRIBUTE, TYPE_FRAGMENT);
        SimpleFilter sf = SimpleFilter.parse(filter);
        bundles = getResourceMapping(sf);
    }
    return bundles;
}
Also used : SimpleFilter(io.fabric8.agent.resolver.SimpleFilter)

Example 5 with SimpleFilter

use of io.fabric8.dosgi.capset.SimpleFilter in project fabric8 by jboss-fuse.

the class BaseRepository method findProviders.

@Override
public Map<Requirement, Collection<Capability>> findProviders(Collection<? extends Requirement> requirements) {
    Map<Requirement, Collection<Capability>> result = new HashMap<Requirement, Collection<Capability>>();
    for (Requirement requirement : requirements) {
        CapabilitySet set = capSets.get(requirement.getNamespace());
        if (set != null) {
            SimpleFilter sf;
            if (requirement instanceof RequirementImpl) {
                sf = ((RequirementImpl) requirement).getFilter();
            } else {
                String filter = requirement.getDirectives().get(Constants.FILTER_DIRECTIVE);
                sf = (filter != null) ? SimpleFilter.parse(filter) : new SimpleFilter(null, null, SimpleFilter.MATCH_ALL);
            }
            result.put(requirement, set.match(sf, true));
        } else {
            result.put(requirement, Collections.<Capability>emptyList());
        }
    }
    return result;
}
Also used : Requirement(org.osgi.resource.Requirement) RequirementImpl(io.fabric8.agent.resolver.RequirementImpl) Capability(org.osgi.resource.Capability) HashMap(java.util.HashMap) SimpleFilter(io.fabric8.agent.resolver.SimpleFilter) Collection(java.util.Collection) CapabilitySet(io.fabric8.agent.resolver.CapabilitySet)

Aggregations

SimpleFilter (io.fabric8.agent.resolver.SimpleFilter)6 Collection (java.util.Collection)3 HashMap (java.util.HashMap)3 Capability (org.osgi.resource.Capability)3 Requirement (org.osgi.resource.Requirement)3 SimpleFilter (io.fabric8.dosgi.capset.SimpleFilter)2 List (java.util.List)2 Resource (org.osgi.resource.Resource)2 Wire (org.osgi.resource.Wire)2 CapabilitySet (io.fabric8.agent.resolver.CapabilitySet)1 RequirementImpl (io.fabric8.agent.resolver.RequirementImpl)1 LinkedHashSet (java.util.LinkedHashSet)1 Map (java.util.Map)1 DictionaryAsMap (org.apache.felix.utils.collections.DictionaryAsMap)1