Search in sources :

Example 51 with Capability

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

the class AbstractResolveContext method isPermitted.

private boolean isPermitted(Resource resource) {
    // OSGi frameworks cannot be selected as ordinary resources
    Capability fwkCap = findFrameworkContractCapability(resource);
    if (fwkCap != null) {
        return false;
    }
    // Remove osgi.core and any ee JAR
    List<Capability> idCaps = resource.getCapabilities(IdentityNamespace.IDENTITY_NAMESPACE);
    if (idCaps == null || idCaps.isEmpty()) {
        log.log(LogService.LOG_ERROR, "Resource is missing an identity capability (osgi.identity).");
        return false;
    }
    if (idCaps.size() > 1) {
        log.log(LogService.LOG_ERROR, "Resource has more than one identity capability (osgi.identity).");
        return false;
    }
    String identity = (String) idCaps.get(0).getAttributes().get(IdentityNamespace.IDENTITY_NAMESPACE);
    if (identity == null) {
        log.log(LogService.LOG_ERROR, "Resource is missing an identity capability (osgi.identity).");
        return false;
    }
    if ("osgi.core".equals(identity))
        return false;
    if (identity.startsWith("ee."))
        return false;
    return true;
}
Also used : HostedCapability(org.osgi.service.resolver.HostedCapability) Capability(org.osgi.resource.Capability)

Example 52 with Capability

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

Example 53 with Capability

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

the class ProjectResolver method getResource.

public IdentityCapability getResource(String bsn, String version) {
    Requirement requirement = CapReqBuilder.createBundleRequirement(bsn, version).buildSyntheticRequirement();
    List<Capability> result = getContext().findProviders(requirement);
    if (result == null || result.isEmpty())
        return null;
    return ResourceUtils.getIdentityCapability(result.get(0).getResource());
}
Also used : Requirement(org.osgi.resource.Requirement) IdentityCapability(aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability) Capability(org.osgi.resource.Capability)

Example 54 with Capability

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

the class ResolveProcess method findResolvedProvider.

private static Resource findResolvedProvider(Wire wire, Set<Resource> resources, AbstractResolveContext rc) {
    // Make sure not to add new resources into the result. The resolver
    // already created the closure of all the needed resources. We need to
    // find the key in the result that already provides the capability
    // defined by this wire.
    Capability capability = wire.getCapability();
    Resource resource = capability.getResource();
    if (rc.isSystemResource(resource) || (ResourceUtils.isFragment(resource) && resources.contains(resource))) {
        return resource;
    }
    for (Resource resolved : resources) {
        for (Capability resolvedCap : resolved.getCapabilities(capability.getNamespace())) {
            if (ResourceUtils.matches(wire.getRequirement(), resolvedCap)) {
                return resolved;
            }
        }
    }
    // It shouldn't be possible to arrive here!
    throw new IllegalStateException(Strings.format("The capability for wire %s was not associated with a resource in the resolution", wire));
}
Also used : Capability(org.osgi.resource.Capability) Resource(org.osgi.resource.Resource)

Example 55 with Capability

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

the class PackageDropAdapter method performDrop.

@Override
public boolean performDrop(Object data) {
    int insertionIndex = -1;
    Object target = getCurrentTarget();
    if (target != null) {
        insertionIndex = indexOf(target);
        int loc = getCurrentLocation();
        if (loc == LOCATION_ON || loc == LOCATION_AFTER)
            insertionIndex++;
    }
    List<T> newEntries = new ArrayList<T>();
    if (data instanceof IResource[]) {
        for (IResource resource : (IResource[]) data) {
            IJavaElement javaElement = JavaCore.create(resource);
            if (javaElement instanceof IPackageFragment) {
                newEntries.add(createNewEntry(javaElement.getElementName()));
            }
        }
    } else if (data instanceof IStructuredSelection) {
        Iterator<?> iterator = ((IStructuredSelection) data).iterator();
        while (iterator.hasNext()) {
            Object element = iterator.next();
            if (element instanceof IPackageFragment) {
                IPackageFragment pkg = (IPackageFragment) element;
                newEntries.add(createNewEntry(pkg.getElementName()));
            } else if (element instanceof Capability) {
                Capability cap = (Capability) element;
                String namespace = cap.getNamespace();
                if (PackageNamespace.PACKAGE_NAMESPACE.equals(namespace)) {
                    String pkgName = (String) cap.getAttributes().get(namespace);
                    newEntries.add(createNewEntry(pkgName));
                }
            } else if (element instanceof Requirement) {
                String pkgName = getPackageNameFromRequirement((Requirement) element);
                if (pkgName != null)
                    newEntries.add(createNewEntry(pkgName));
            } else if (element instanceof RequirementWrapper) {
                String pkgName = getPackageNameFromRequirement(((RequirementWrapper) element).requirement);
                if (pkgName != null)
                    newEntries.add(createNewEntry(pkgName));
            }
        }
    }
    addRows(insertionIndex, newEntries);
    return true;
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) Capability(org.osgi.resource.Capability) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Requirement(org.osgi.resource.Requirement) Iterator(java.util.Iterator) RequirementWrapper(bndtools.model.resolution.RequirementWrapper) IResource(org.eclipse.core.resources.IResource)

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