use of org.osgi.resource.Requirement in project bnd by bndtools.
the class ResolveProcess method tidyUpOptional.
private static Map<Resource, List<Wire>> tidyUpOptional(Map<Resource, List<Wire>> required, Map<Resource, List<Wire>> discoveredOptional, LogService log) {
Map<Resource, List<Wire>> toReturn = new HashMap<Resource, List<Wire>>();
Set<Capability> requiredIdentities = new HashSet<Capability>();
for (Resource r : required.keySet()) {
Capability normalisedIdentity = toPureIdentity(r, log);
if (normalisedIdentity != null) {
requiredIdentities.add(normalisedIdentity);
}
}
Set<Capability> acceptedIdentities = new HashSet<>();
for (Entry<Resource, List<Wire>> entry : discoveredOptional.entrySet()) {
// If we're required we are not also optional
Resource optionalResource = entry.getKey();
if (required.containsKey(optionalResource)) {
continue;
}
// If another resource with the same identity is required
// then we defer to it, otherwise we will get the an optional
// resource showing up from a different repository
Capability optionalIdentity = toPureIdentity(optionalResource, log);
if (requiredIdentities.contains(optionalIdentity)) {
continue;
}
// Only wires to required resources should kept
List<Wire> validWires = new ArrayList<Wire>();
optional: for (Wire optionalWire : entry.getValue()) {
Resource requirer = optionalWire.getRequirer();
Capability requirerIdentity = toPureIdentity(requirer, log);
if (required.containsKey(requirer)) {
Requirement req = optionalWire.getRequirement();
// Somebody does require this - do they have a match
// already?
List<Wire> requiredWires = required.get(requirer);
for (Wire requiredWire : requiredWires) {
if (req.equals(requiredWire.getRequirement())) {
continue optional;
}
}
validWires.add(optionalWire);
}
}
// This can happen if the same resource is in multiple repos
if (!validWires.isEmpty()) {
if (acceptedIdentities.add(optionalIdentity)) {
toReturn.put(optionalResource, validWires);
} else {
log.log(LogService.LOG_INFO, "Discarding the optional resource " + optionalResource + " because another optional resource with the identity " + optionalIdentity + " has already been selected. This usually happens when the same bundle is present in multiple repositories.");
}
}
}
return toReturn;
}
use of org.osgi.resource.Requirement in project bnd by bndtools.
the class BndrunResolveContext method findRepositoryAugments.
private Processor findRepositoryAugments(Collection<Repository> orderedRepositories) {
Processor main = new Processor();
RequirementBuilder rb = new RequirementBuilder(BND_AUGMENT);
rb.filter("(path=*)");
Requirement req = rb.buildSyntheticRequirement();
for (Repository r : orderedRepositories) {
Map<Requirement, Collection<Capability>> found = r.findProviders(Collections.singleton(req));
Collection<Capability> capabilities = found.get(req);
if (capabilities != null) {
for (Capability capability : capabilities) {
findAdditionalAugmentsFromResource(main, capability);
}
}
}
return main;
}
use of org.osgi.resource.Requirement in project bnd by bndtools.
the class DebugReporter method doAllMembers.
private void doAllMembers() {
header("RESOURCES");
Requirement r = CapReqBuilder.createBundleRequirement("*", null).buildSyntheticRequirement();
List<Capability> providers = context.findProviders(r);
Set<Resource> resources = ResourceUtils.getResources(providers);
for (Resource resource : resources) {
resource(resource);
}
resource(context.getSystemResource());
nl();
}
use of org.osgi.resource.Requirement in project bnd by bndtools.
the class AbstractResolveContext method createIdentityRequirement.
public static Requirement createIdentityRequirement(String identity, String versionRange) {
// Construct a filter & requirement to find matches
Filter filter = new SimpleFilter(IdentityNamespace.IDENTITY_NAMESPACE, identity);
if (versionRange != null)
filter = new AndFilter().addChild(filter).addChild(new LiteralFilter(Filters.fromVersionRange(versionRange)));
Requirement frameworkReq = new CapReqBuilder(IdentityNamespace.IDENTITY_NAMESPACE).addDirective(Namespace.REQUIREMENT_FILTER_DIRECTIVE, filter.toString()).buildSyntheticRequirement();
return frameworkReq;
}
use of org.osgi.resource.Requirement in project bnd by bndtools.
the class DebugReporter method resource.
private void resource(Resource r) {
IdentityCapability id = ResourceUtils.getIdentityCapability(r);
String resolveError = null;
if (!context.isSystemResource(r) && level >= 3 && id != null)
try {
String v = id.version() == null ? null : id.version().toString();
Requirement req = CapReqBuilder.createBundleRequirement(id.osgi_identity(), v).buildSyntheticRequirement();
context.setInputRequirements(req);
Resolver resolver = new BndResolver(new ResolverLogger(4));
Map<Resource, List<Wire>> resolved = resolver.resolve(context);
} catch (Exception e) {
resolveError = e.toString();
}
String s = resolveError == null ? " " : "!";
if (id == null)
out.printf("%s %s%n", s, r);
else
out.printf("%s %-50s %-20s %s%n", s, id.osgi_identity(), noNull(id.version()), id.description(""));
if (level >= 2) {
for (Capability c : r.getCapabilities(null)) {
capability(" ", c);
}
for (Requirement rq : r.getRequirements(null)) {
requirement(" ", rq);
}
}
}
Aggregations