Search in sources :

Example 41 with Requirement

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

the class AbstractIndexedRepo method findProviders.

public Map<Requirement, Collection<Capability>> findProviders(Collection<? extends Requirement> requirements) {
    try {
        init();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    Map<Requirement, Collection<Capability>> result = new HashMap<Requirement, Collection<Capability>>();
    for (Requirement requirement : requirements) {
        List<Capability> matches = new LinkedList<Capability>();
        result.put(requirement, matches);
        capabilityIndex.appendMatchingCapabilities(requirement, matches);
    }
    return result;
}
Also used : Requirement(org.osgi.resource.Requirement) RepoResourceUtils.getIdentityCapability(aQute.bnd.deployer.repository.RepoResourceUtils.getIdentityCapability) Capability(org.osgi.resource.Capability) HashMap(java.util.HashMap) Collection(java.util.Collection) URISyntaxException(java.net.URISyntaxException) FileNotFoundException(java.io.FileNotFoundException) MalformedURLException(java.net.MalformedURLException) LinkedList(java.util.LinkedList)

Example 42 with Requirement

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

the class BndrunResolveContext method constructInputRequirements.

Resource constructInputRequirements() throws Exception {
    ResourceBuilder resBuilder = new ResourceBuilder();
    CapReqBuilder identity = new CapReqBuilder(IdentityNamespace.IDENTITY_NAMESPACE).addAttribute(IdentityNamespace.IDENTITY_NAMESPACE, IDENTITY_INITIAL_RESOURCE);
    resBuilder.addCapability(identity);
    Parameters inputRequirements = new Parameters(properties.mergeProperties(Constants.RUNREQUIRES), project);
    if (inputRequirements != null && !inputRequirements.isEmpty()) {
        List<Requirement> requires = CapReqBuilder.getRequirementsFrom(inputRequirements);
        resBuilder.addRequirements(requires);
    }
    return resBuilder.build();
}
Also used : CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) Requirement(org.osgi.resource.Requirement) ResourceBuilder(aQute.bnd.osgi.resource.ResourceBuilder) Parameters(aQute.bnd.header.Parameters)

Example 43 with Requirement

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

the class AbstractResolveContext method setInputRequirements.

public void setInputRequirements(Requirement... reqs) throws Exception {
    ResourceBuilder rb = new ResourceBuilder();
    for (Requirement r : reqs) {
        rb.addRequirement(r);
    }
    setInputResource(rb.build());
}
Also used : Requirement(org.osgi.resource.Requirement) ResourceBuilder(aQute.bnd.osgi.resource.ResourceBuilder)

Example 44 with Requirement

use of org.osgi.resource.Requirement 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 45 with Requirement

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

the class ResolveProcess method format.

public static String format(Collection<Requirement> requirements) {
    Set<Requirement> mandatory = new HashSet<>();
    Set<Requirement> optional = new HashSet<>();
    for (Requirement req : requirements) {
        if (isOptional(req))
            optional.add(req);
        else
            mandatory.add(req);
    }
    try (Formatter f = new Formatter()) {
        f.format("%n  Mandatory:");
        for (Requirement req : mandatory) {
            f.format("%n    [%-19s] %s", req.getNamespace(), req);
        }
        f.format("%n  Optional:");
        for (Requirement req : optional) {
            f.format("%n    [%-19s] %s", req.getNamespace(), req);
        }
        return f.toString();
    }
}
Also used : Requirement(org.osgi.resource.Requirement) Formatter(java.util.Formatter) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

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