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);
}
}
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;
}
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;
}
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;
}
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.");
}
Aggregations