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;
}
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);
}
}
}
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());
}
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));
}
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;
}
Aggregations