Search in sources :

Example 61 with Resource

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

the class ResolveProcess method augment.

private static ResolutionException augment(Collection<Requirement> unresolved, ResolveContext context, ResolutionException re) {
    if (unresolved.isEmpty()) {
        return re;
    }
    long deadline = System.currentTimeMillis() + 1000L;
    Set<Requirement> list = new HashSet<>(unresolved);
    Set<Resource> resources = new HashSet<>();
    try {
        for (Requirement r : unresolved) {
            Requirement find = missing(context, r, resources, deadline);
            if (find != null) {
                list.add(find);
            }
        }
    } catch (TimeoutException toe) {
    }
    return new ResolutionException(re.getMessage(), re.getCause(), list);
}
Also used : ResolutionException(org.osgi.service.resolver.ResolutionException) Requirement(org.osgi.resource.Requirement) Resource(org.osgi.resource.Resource) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) TimeoutException(java.util.concurrent.TimeoutException)

Example 62 with Resource

use of org.osgi.resource.Resource 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 63 with Resource

use of org.osgi.resource.Resource 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 64 with Resource

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

the class DebugReporter method doBlackList.

private void doBlackList() {
    header("BLACKLISTED RESOURCES");
    for (Resource r : context.getBlackList()) {
        resource(r);
    }
    nl();
}
Also used : Resource(org.osgi.resource.Resource)

Example 65 with Resource

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

the class AbstractResolveContext method getResources.

public List<Resource> getResources(List<Repository> repos, Requirement req) {
    Set<Resource> resources = new HashSet<Resource>();
    for (Repository repo : repos) {
        Collection<Capability> providers = findProviders(repo, req);
        resources.addAll(ResourceUtils.getResources(providers));
    }
    return new ArrayList<>(resources);
}
Also used : Repository(org.osgi.service.repository.Repository) ResourcesRepository(aQute.bnd.osgi.repository.ResourcesRepository) HostedCapability(org.osgi.service.resolver.HostedCapability) Capability(org.osgi.resource.Capability) Resource(org.osgi.resource.Resource) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Aggregations

Resource (org.osgi.resource.Resource)201 Capability (org.osgi.resource.Capability)62 Requirement (org.osgi.resource.Requirement)62 ArrayList (java.util.ArrayList)57 List (java.util.List)39 HashMap (java.util.HashMap)32 File (java.io.File)27 Collection (java.util.Collection)24 Wire (org.osgi.resource.Wire)24 ResourceBuilder (aQute.bnd.osgi.resource.ResourceBuilder)23 Map (java.util.Map)22 CapReqBuilder (aQute.bnd.osgi.resource.CapReqBuilder)18 URI (java.net.URI)18 HashSet (java.util.HashSet)18 BndEditModel (aQute.bnd.build.model.BndEditModel)15 MockRegistry (test.lib.MockRegistry)15 Version (org.osgi.framework.Version)14 BundleRevision (org.osgi.framework.wiring.BundleRevision)14 Repository (org.osgi.service.repository.Repository)14 IdentityCapability (aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability)13