Search in sources :

Example 31 with Capability

use of org.osgi.resource.Capability in project aries by apache.

the class SubTestRepository method findProviders.

@Override
public Map<Requirement, Collection<Capability>> findProviders(Collection<? extends Requirement> requirements) {
    Map<Requirement, Collection<Capability>> res = new HashMap<Requirement, Collection<Capability>>();
    for (Requirement req : requirements) {
        if (req.getNamespace().equals("ns1") && req.getDirectives().equals(Collections.singletonMap("filter", "(x=y)"))) {
            TestCapability cap = new TestCapability("ns1", Collections.<String, Object>singletonMap("x", "y"));
            Collection<Capability> caps = Collections.<Capability>singleton(cap);
            res.put(req, caps);
        }
    }
    return res;
}
Also used : Requirement(org.osgi.resource.Requirement) Capability(org.osgi.resource.Capability) TestCapability(org.apache.aries.subsystem.core.internal.TestCapability) HashMap(java.util.HashMap) TestCapability(org.apache.aries.subsystem.core.internal.TestCapability) Collection(java.util.Collection)

Example 32 with Capability

use of org.osgi.resource.Capability in project aries by apache.

the class Aries1453Test method shouldResolveFragmentHostWithVersionRangeAndMatchWithBundlesInThatRange.

@Test
public void shouldResolveFragmentHostWithVersionRangeAndMatchWithBundlesInThatRange() {
    FragmentHostHeader header = new FragmentHostHeader("host-bundle;bundle-version=\"[9.6.0,10)\"");
    FragmentHostRequirement requirement = new FragmentHostRequirement(header.getClauses().iterator().next(), null);
    FragmentHostCapability capability = new FragmentHostCapability(new BundleSymbolicNameHeader("host-bundle"), new BundleVersionHeader("9.6.1"), new Resource() {

        @Override
        public List<Capability> getCapabilities(String namespace) {
            return null;
        }

        @Override
        public List<Requirement> getRequirements(String namespace) {
            return null;
        }
    });
    String filterDirective = requirement.getDirectives().get(Namespace.REQUIREMENT_FILTER_DIRECTIVE);
    SimpleFilter simpleFilter = SimpleFilter.parse(filterDirective);
    CapabilitySet capabilitySet = new CapabilitySet(Arrays.asList(HostNamespace.HOST_NAMESPACE), true);
    capabilitySet.addCapability(capability);
    Set<Capability> capabilities = capabilitySet.match(simpleFilter, true);
    Assert.assertTrue(capabilities.size() == 1);
    Assert.assertSame(capabilities.iterator().next(), capability);
}
Also used : Capability(org.osgi.resource.Capability) Resource(org.osgi.resource.Resource) SimpleFilter(org.apache.aries.subsystem.core.capabilityset.SimpleFilter) CapabilitySet(org.apache.aries.subsystem.core.capabilityset.CapabilitySet) List(java.util.List) Test(org.junit.Test)

Example 33 with Capability

use of org.osgi.resource.Capability in project bndtools by bndtools.

the class WorkspaceR5Repository 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) {
        List<Capability> matches = new LinkedList<Capability>();
        result.put(requirement, matches);
        for (Entry<IProject, CapabilityIndex> entry : projectMap.entrySet()) {
            IProject project = entry.getKey();
            if (project.exists() && project.isOpen()) {
                CapabilityIndex capabilityIndex = entry.getValue();
                capabilityIndex.appendMatchingCapabilities(requirement, matches);
            }
        }
    }
    return result;
}
Also used : Requirement(org.osgi.resource.Requirement) Capability(org.osgi.resource.Capability) HashMap(java.util.HashMap) Collection(java.util.Collection) LinkedList(java.util.LinkedList) IProject(org.eclipse.core.resources.IProject) CapabilityIndex(aQute.bnd.deployer.repository.CapabilityIndex)

Example 34 with Capability

use of org.osgi.resource.Capability in project bnd by bndtools.

the class AugmentRepository method findProviders.

@Override
public Map<Requirement, Collection<Capability>> findProviders(Collection<? extends Requirement> requirements) {
    Map<Requirement, Collection<Capability>> fromRepos = repository.findProviders(requirements);
    for (Requirement requirement : requirements) {
        List<Capability> provided = new ArrayList<>();
        boolean replaced = false;
        for (Capability originalCapability : fromRepos.get(requirement)) {
            if (isValid(originalCapability)) {
                Capability wrappedCapability = wrapped.get(originalCapability);
                if (wrappedCapability != null) {
                    provided.add(wrappedCapability);
                    replaced = true;
                } else
                    provided.add(originalCapability);
            }
        }
        Collection<Capability> additional = ResourceUtils.findProviders(requirement, augmentedCapabilities);
        replaced |= provided.addAll(additional);
        if (replaced)
            fromRepos.put(requirement, provided);
    }
    return fromRepos;
}
Also used : Requirement(org.osgi.resource.Requirement) Capability(org.osgi.resource.Capability) ArrayList(java.util.ArrayList) Collection(java.util.Collection)

Example 35 with Capability

use of org.osgi.resource.Capability in project bnd by bndtools.

the class BaseRepository method dispatch.

private void dispatch(RequirementExpression expression, Set<Resource> providers) {
    if (expression instanceof IdentityExpression) {
        Map<Requirement, Collection<Capability>> capabilities = findProviders(Collections.singleton(((IdentityExpression) expression).getRequirement()));
        for (Collection<Capability> caps : capabilities.values()) {
            for (Capability c : caps) providers.add(c.getResource());
        }
    } else if (expression instanceof OrExpression) {
        for (RequirementExpression re : ((OrExpression) expression).getRequirementExpressions()) dispatch(re, providers);
    } else if (expression instanceof AndExpression) {
        List<RequirementExpression> requirementExpressions = ((AndExpression) expression).getRequirementExpressions();
        if (requirementExpressions.isEmpty())
            return;
        if (requirementExpressions.size() == 1) {
            dispatch(requirementExpressions.get(0), providers);
            return;
        }
        Set<Resource> subset = new HashSet<>();
        dispatch(requirementExpressions.get(0), subset);
        for (int i = 1; i < requirementExpressions.size(); i++) {
            for (Iterator<Resource> it = subset.iterator(); it.hasNext(); ) {
                Resource resource = it.next();
                RequirementExpression re = requirementExpressions.get(i);
                if (!matches(re, resource)) {
                    it.remove();
                    if (subset.isEmpty())
                        return;
                }
            }
        }
        providers.addAll(subset);
    } else if (expression instanceof NotExpression) {
        Set<Resource> allSet = new HashSet<>();
        dispatch(all, allSet);
        RequirementExpression re = ((NotExpression) expression).getRequirementExpression();
        for (Iterator<Resource> it = allSet.iterator(); it.hasNext(); ) {
            Resource resource = it.next();
            if (matches(re, resource)) {
                it.remove();
                if (allSet.isEmpty())
                    return;
            }
        }
        providers.addAll(allSet);
    } else
        throw new UnsupportedOperationException("Unknown expression type " + expression.getClass());
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) Capability(org.osgi.resource.Capability) Resource(org.osgi.resource.Resource) NotExpression(org.osgi.service.repository.NotExpression) OrExpression(org.osgi.service.repository.OrExpression) Requirement(org.osgi.resource.Requirement) AndExpression(org.osgi.service.repository.AndExpression) RequirementExpression(org.osgi.service.repository.RequirementExpression) Iterator(java.util.Iterator) Collection(java.util.Collection) IdentityExpression(org.osgi.service.repository.IdentityExpression) HashSet(java.util.HashSet)

Aggregations

Capability (org.osgi.resource.Capability)197 Requirement (org.osgi.resource.Requirement)104 Resource (org.osgi.resource.Resource)61 ArrayList (java.util.ArrayList)40 HashMap (java.util.HashMap)39 IdentityCapability (aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability)37 CapReqBuilder (aQute.bnd.osgi.resource.CapReqBuilder)35 Collection (java.util.Collection)32 MockRegistry (test.lib.MockRegistry)26 BndEditModel (aQute.bnd.build.model.BndEditModel)25 Version (org.osgi.framework.Version)20 List (java.util.List)19 Repository (org.osgi.service.repository.Repository)17 Test (org.junit.Test)16 File (java.io.File)15 HostedCapability (org.osgi.service.resolver.HostedCapability)13 HashSet (java.util.HashSet)12 Map (java.util.Map)12 LinkedList (java.util.LinkedList)11 RequirementBuilder (aQute.bnd.osgi.resource.RequirementBuilder)8