Search in sources :

Example 41 with Capability

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

the class CapabilityIndex method addCapabilities.

private synchronized void addCapabilities(Iterable<Capability> capabilities) {
    for (Capability cap : capabilities) {
        List<Capability> list = capabilityMap.get(cap.getNamespace());
        if (list == null) {
            list = new LinkedList<Capability>();
            capabilityMap.put(cap.getNamespace(), list);
        }
        list.add(cap);
    }
}
Also used : Capability(org.osgi.resource.Capability)

Example 42 with Capability

use of org.osgi.resource.Capability 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 43 with Capability

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

the class BndrunResolveContext method init.

/**
	 * Initializes the resolver. Here we will load all the information from the
	 * model.
	 */
@Override
public synchronized void init() {
    if (initialized)
        return;
    initialized = true;
    try {
        if (getLevel() <= 0) {
            Integer level = Converter.cnv(Integer.class, properties.getProperty("-resolvedebug", "0"));
            if (level != null)
                setLevel(level);
        }
        loadPreferences();
        Processor augments = loadRepositories();
        constructBlacklist(augments);
        Map<String, Set<String>> effectiveSet = loadEffectiveSet();
        if (effectiveSet != null)
            addEffectiveSet(effectiveSet);
        //
        // Create a resource from the -runrequire that contains
        // all the requirement
        //
        setInputResource(constructInputRequirements());
        //
        // We gradually build up the system resource that contains
        // the system packages, the EE, etc.
        //
        ResourceBuilder system = new ResourceBuilder();
        //
        // Let's identify the system resource to make it look less
        // ugly
        //
        //
        // If we have a distro, we do not load the environment
        // settings
        //
        String distro = properties.mergeProperties(Constants.DISTRO);
        if (distro != null && !distro.trim().isEmpty()) {
            loadPath(system, distro, Constants.DISTRO);
            loadProvidedCapabilities(system);
        } else {
            //
            // Load the EE's and packages that belong to it.
            //
            EE tmp = EE.parse(properties.getProperty(Constants.RUNEE));
            EE ee = (tmp != null) ? tmp : EE.JavaSE_1_6;
            system.addAllExecutionEnvironments(ee);
            //
            // We make the system packages as coming from the system
            // resource
            //
            Parameters systemPackages = new Parameters(properties.mergeProperties(Constants.RUNSYSTEMPACKAGES), project);
            system.addExportPackages(systemPackages);
            //
            // We make the system capabilities as coming from the system
            // resource
            //
            Parameters systemCapabilities = new Parameters(properties.mergeProperties(Constants.RUNSYSTEMCAPABILITIES), project);
            system.addProvideCapabilities(systemCapabilities);
            loadProvidedCapabilities(system);
            //
            // Load the frameworks capabilities
            //
            loadFramework(system);
            //
            // Analyze the path and add all exported packages and provided
            // capabilities
            // to the system resource
            //
            String runpath = properties.mergeProperties(Constants.RUNPATH);
            if (runpath != null && !runpath.trim().isEmpty())
                loadPath(system, runpath, Constants.RUNPATH);
        }
        //
        // We've not gathered all the capabilities of the system
        // so we can create the resource and set it as the system resource
        //
        //
        // TODO Add osgi.wiring.bundle + osgi.wiring.host
        // filed a bug about using the impl version for the system
        // capabilities
        //
        List<Capability> frameworkPackages = system.findCapabilities(PackageNamespace.PACKAGE_NAMESPACE, "(" + PackageNamespace.PACKAGE_NAMESPACE + "=org.osgi.framework)");
        if (!frameworkPackages.isEmpty()) {
            Capability c = frameworkPackages.get(0);
            Version version = (Version) c.getAttributes().get(PackageNamespace.CAPABILITY_VERSION_ATTRIBUTE);
            CapReqBuilder crb = new CapReqBuilder(IdentityNamespace.IDENTITY_NAMESPACE);
            crb.addAttribute(IdentityNamespace.IDENTITY_NAMESPACE, "system.bundle");
            crb.addAttribute(IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE, version);
            system.addCapability(crb);
        }
        setSystemResource(system.build());
    } catch (Exception e) {
        log.log(LogService.LOG_ERROR, e.getMessage(), e);
        throw new RuntimeException(e);
    }
    super.init();
}
Also used : EE(aQute.bnd.build.model.EE) CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) ResourceBuilder(aQute.bnd.osgi.resource.ResourceBuilder) Processor(aQute.bnd.osgi.Processor) Set(java.util.Set) HashSet(java.util.HashSet) Parameters(aQute.bnd.header.Parameters) Capability(org.osgi.resource.Capability) Version(org.osgi.framework.Version)

Example 44 with Capability

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

use of org.osgi.resource.Capability 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)

Aggregations

Capability (org.osgi.resource.Capability)197 Requirement (org.osgi.resource.Requirement)104 Resource (org.osgi.resource.Resource)61 ArrayList (java.util.ArrayList)40 HashMap (java.util.HashMap)39 IdentityCapability (aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability)37 CapReqBuilder (aQute.bnd.osgi.resource.CapReqBuilder)35 Collection (java.util.Collection)32 MockRegistry (test.lib.MockRegistry)26 BndEditModel (aQute.bnd.build.model.BndEditModel)25 Version (org.osgi.framework.Version)20 List (java.util.List)19 Repository (org.osgi.service.repository.Repository)17 Test (org.junit.Test)16 File (java.io.File)15 HostedCapability (org.osgi.service.resolver.HostedCapability)13 HashSet (java.util.HashSet)12 Map (java.util.Map)12 LinkedList (java.util.LinkedList)11 RequirementBuilder (aQute.bnd.osgi.resource.RequirementBuilder)8