Search in sources :

Example 36 with Capability

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

the class BridgeRepository method index.

private void index() throws Exception {
    Map<Requirement, Collection<Capability>> all = repository.findProviders(Collections.singleton(allRq));
    for (Capability capability : all.get(allRq)) {
        Resource r = capability.getResource();
        index(r);
    }
}
Also used : Requirement(org.osgi.resource.Requirement) IdentityCapability(aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability) Capability(org.osgi.resource.Capability) ContentCapability(aQute.bnd.osgi.resource.ResourceUtils.ContentCapability) Resource(org.osgi.resource.Resource) Collection(java.util.Collection)

Example 37 with Capability

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

the class ResourcesRepository method findProviders.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public Map<Requirement, Collection<Capability>> findProviders(Collection<? extends Requirement> requirements) {
    MultiMap<Requirement, Capability> result = new MultiMap<>();
    for (Requirement requirement : requirements) {
        List<Capability> capabilities = findProvider(requirement);
        result.put(requirement, capabilities);
    }
    return (Map) result;
}
Also used : MultiMap(aQute.lib.collections.MultiMap) Requirement(org.osgi.resource.Requirement) Capability(org.osgi.resource.Capability) MultiMap(aQute.lib.collections.MultiMap) Map(java.util.Map)

Example 38 with Capability

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

the class ResourcesRepository method findProvider.

public List<Capability> findProvider(Requirement requirement) {
    List<Capability> result = new ArrayList<Capability>();
    String namespace = requirement.getNamespace();
    for (Resource resource : resources) {
        for (Capability capability : resource.getCapabilities(namespace)) {
            if (ResourceUtils.matches(requirement, capability)) {
                result.add(capability);
            }
        }
    }
    return result;
}
Also used : Capability(org.osgi.resource.Capability) ArrayList(java.util.ArrayList) Resource(org.osgi.resource.Resource)

Example 39 with Capability

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

the class XMLResourceGenerator method repository.

public XMLResourceGenerator repository(Repository repository) throws Exception {
    Requirement wildcard = ResourceUtils.createWildcardRequirement();
    Map<Requirement, Collection<Capability>> findProviders = repository.findProviders(Collections.singleton(wildcard));
    for (Capability capability : findProviders.get(wildcard)) {
        resource(capability.getResource());
    }
    return this;
}
Also used : Requirement(org.osgi.resource.Requirement) Capability(org.osgi.resource.Capability) Collection(java.util.Collection)

Example 40 with Capability

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

the class RepoResourceUtils method getContentUrl.

public static URI getContentUrl(Resource resource) {
    List<Capability> caps = resource.getCapabilities(ContentNamespace.CONTENT_NAMESPACE);
    if (caps.isEmpty())
        throw new IllegalArgumentException("Resource has no content capability");
    Object uri = caps.iterator().next().getAttributes().get(ContentNamespace.CAPABILITY_URL_ATTRIBUTE);
    if (uri == null)
        throw new IllegalArgumentException("Resource content has no 'uri' attribute.");
    if (uri instanceof URI)
        return (URI) uri;
    try {
        if (uri instanceof URL)
            return ((URL) uri).toURI();
        if (uri instanceof String)
            return new URI((String) uri);
    } catch (URISyntaxException e) {
        throw new IllegalArgumentException("Failed to convert resource content location to a valid URI.", e);
    }
    throw new IllegalArgumentException("Failed to convert resource content location to a valid URI.");
}
Also used : Capability(org.osgi.resource.Capability) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) URL(java.net.URL)

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