Search in sources :

Example 46 with Requirement

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;
}
Also used : Requirement(org.osgi.resource.Requirement) Capability(org.osgi.resource.Capability) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Resource(org.osgi.resource.Resource) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) Wire(org.osgi.resource.Wire) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 47 with Requirement

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;
}
Also used : Requirement(org.osgi.resource.Requirement) AggregateRepository(aQute.bnd.osgi.repository.AggregateRepository) Repository(org.osgi.service.repository.Repository) AugmentRepository(aQute.bnd.osgi.repository.AugmentRepository) Processor(aQute.bnd.osgi.Processor) Capability(org.osgi.resource.Capability) Collection(java.util.Collection) RequirementBuilder(aQute.bnd.osgi.resource.RequirementBuilder)

Example 48 with Requirement

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();
}
Also used : Requirement(org.osgi.resource.Requirement) IdentityCapability(aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability) Capability(org.osgi.resource.Capability) Resource(org.osgi.resource.Resource)

Example 49 with Requirement

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;
}
Also used : LiteralFilter(aQute.libg.filters.LiteralFilter) CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) AndFilter(aQute.libg.filters.AndFilter) Requirement(org.osgi.resource.Requirement) SimpleFilter(aQute.libg.filters.SimpleFilter) AndFilter(aQute.libg.filters.AndFilter) Filter(aQute.libg.filters.Filter) LiteralFilter(aQute.libg.filters.LiteralFilter) SimpleFilter(aQute.libg.filters.SimpleFilter)

Example 50 with Requirement

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);
        }
    }
}
Also used : Requirement(org.osgi.resource.Requirement) Resolver(org.osgi.service.resolver.Resolver) IdentityCapability(aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability) Capability(org.osgi.resource.Capability) Wire(org.osgi.resource.Wire) HashMap(java.util.HashMap) Map(java.util.Map) IdentityCapability(aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability)

Aggregations

Requirement (org.osgi.resource.Requirement)201 Capability (org.osgi.resource.Capability)103 Resource (org.osgi.resource.Resource)59 CapReqBuilder (aQute.bnd.osgi.resource.CapReqBuilder)53 ArrayList (java.util.ArrayList)51 Collection (java.util.Collection)44 BndEditModel (aQute.bnd.build.model.BndEditModel)35 HashMap (java.util.HashMap)35 IdentityCapability (aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability)34 MockRegistry (test.lib.MockRegistry)32 List (java.util.List)19 Repository (org.osgi.service.repository.Repository)19 Test (org.junit.Test)18 File (java.io.File)16 Map (java.util.Map)12 Resolver (org.osgi.service.resolver.Resolver)11 LinkedHashSet (java.util.LinkedHashSet)10 LinkedList (java.util.LinkedList)10 Wire (org.osgi.resource.Wire)10 Parameters (aQute.bnd.header.Parameters)9