use of org.osgi.resource.Requirement in project bndtools by bndtools.
the class ResourceCapReqLoader method loadRequirements.
@Override
public Map<String, List<RequirementWrapper>> loadRequirements() throws Exception {
Map<String, List<RequirementWrapper>> result = new HashMap<String, List<RequirementWrapper>>();
List<Requirement> reqs = resource.getRequirements(null);
for (Requirement req : reqs) {
String ns = req.getNamespace();
List<RequirementWrapper> listForNamespace = result.get(ns);
if (listForNamespace == null) {
listForNamespace = new LinkedList<RequirementWrapper>();
result.put(ns, listForNamespace);
}
RequirementWrapper wrapper = new RequirementWrapper();
wrapper.requirement = req;
listForNamespace.add(wrapper);
}
return result;
}
use of org.osgi.resource.Requirement in project bnd by bndtools.
the class ResolveCommand method _query.
public void _query(QueryOptions options) throws Exception {
List<String> args = options._arguments();
String bsn = args.remove(0);
String version = null;
if (!args.isEmpty())
version = args.remove(0);
ProjectResolver pr = new ProjectResolver(bnd.getProject(options.project()));
addClose(pr);
IdentityCapability resource = pr.getResource(bsn, version);
bnd.out.printf("%-30s %-20s %s\n", resource.osgi_identity(), resource.version(), resource.description(""));
Resource r = resource.getResource();
FilterParser p = new FilterParser();
if (r != null) {
List<Requirement> requirements = resource.getResource().getRequirements(null);
if (!requirements.isEmpty()) {
bnd.out.println("Requirements:");
for (Requirement req : requirements) {
Expression parse = p.parse(req);
bnd.out.printf(" %-20s %s\n", req.getNamespace(), parse);
}
}
List<Capability> capabilities = resource.getResource().getCapabilities(null);
if (!capabilities.isEmpty()) {
bnd.out.println("Capabilities:");
for (Capability cap : capabilities) {
Map<String, Object> attrs = new HashMap<String, Object>(cap.getAttributes());
Object id = attrs.remove(cap.getNamespace());
Object vv = attrs.remove("version");
if (vv == null)
vv = attrs.remove("bundle-version");
bnd.out.printf(" %-20s %-40s %-20s attrs=%s dirs=%s\n", cap.getNamespace(), id, vv, attrs, cap.getDirectives());
}
}
}
}
use of org.osgi.resource.Requirement in project bnd by bndtools.
the class ResolveCommand method _validate.
public void _validate(ValidateOptions options) throws Exception {
ResourceBuilder system = new ResourceBuilder();
system.addEE(options.ee(EE.JavaSE_1_8));
if (options.core() != null)
system.addManifest(options.core().getManifest());
if (options.packages() != null)
system.addExportPackages(options.packages());
if (options.capabilities() != null)
system.addProvideCapabilities(options.capabilities());
if (options.system() != null) {
File f = IO.getFile(options.system());
if (!f.isFile()) {
error("Specified system file but not found: %s", f);
return;
}
Domain domain = Domain.domain(f);
system.addManifest(domain);
}
List<String> args = options._arguments();
File index = getFile(args.remove(0));
logger.debug("validating {}", index);
ResolverValidator validator = new ResolverValidator(bnd);
validator.use(bnd);
validator.addRepository(index.toURI());
validator.setSystem(system.build());
List<Resolution> result = validator.validate();
Set<Requirement> done = new HashSet<>();
for (Resolution res : result) {
if (options.all()) {
bnd.out.format("%s %-60s%n", res.succeeded ? "OK" : "**", res.resource, res.message == null ? "" : res.message);
}
if (!res.succeeded) {
for (Requirement req : res.missing) {
if (done.contains(req))
continue;
bnd.out.format(" missing %s%n", req);
done.add(req);
}
if (options.all()) {
for (Requirement req : res.repos) {
bnd.out.format(" repos %s%n", req);
}
for (Requirement req : res.system) {
bnd.out.format(" system %s%n", req);
}
for (Requirement req : res.optionals) {
bnd.out.format(" optional %s%n", req);
}
}
}
}
bnd.getInfo(validator);
}
use of org.osgi.resource.Requirement in project bnd by bndtools.
the class Project method getBundleByHash.
private Container getBundleByHash(String bsn, Map<String, String> attrs) throws Exception {
String hashStr = attrs.get("hash");
String algo = SHA_256;
String hash = hashStr;
int colonIndex = hashStr.indexOf(':');
if (colonIndex > -1) {
algo = hashStr.substring(0, colonIndex);
int afterColon = colonIndex + 1;
hash = (colonIndex < hashStr.length()) ? hashStr.substring(afterColon) : "";
}
for (RepositoryPlugin plugin : workspace.getRepositories()) {
// The plugin *may* understand version=hash directly
DownloadBlocker blocker = new DownloadBlocker(this);
File result = plugin.get(bsn, Version.LOWEST, Collections.unmodifiableMap(attrs), blocker);
// Service, use a capability search on the osgi.content namespace.
if (result == null && plugin instanceof Repository) {
Repository repo = (Repository) plugin;
if (!SHA_256.equals(algo))
// R5 repos only support SHA-256
continue;
Requirement contentReq = new CapReqBuilder(ContentNamespace.CONTENT_NAMESPACE).filter(String.format("(%s=%s)", ContentNamespace.CONTENT_NAMESPACE, hash)).buildSyntheticRequirement();
Set<Requirement> reqs = Collections.singleton(contentReq);
Map<Requirement, Collection<Capability>> providers = repo.findProviders(reqs);
Collection<Capability> caps = providers != null ? providers.get(contentReq) : null;
if (caps != null && !caps.isEmpty()) {
Capability cap = caps.iterator().next();
IdentityCapability idCap = ResourceUtils.getIdentityCapability(cap.getResource());
Map<String, Object> idAttrs = idCap.getAttributes();
String id = (String) idAttrs.get(IdentityNamespace.IDENTITY_NAMESPACE);
Object version = idAttrs.get(IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE);
Version bndVersion = version != null ? Version.parseVersion(version.toString()) : Version.LOWEST;
if (!bsn.equals(id)) {
String error = String.format("Resource with requested hash does not match ID '%s' [hash: %s]", bsn, hashStr);
return new Container(this, bsn, "hash", Container.TYPE.ERROR, null, error, null, null);
}
result = plugin.get(id, bndVersion, null, blocker);
}
}
if (result != null)
return toContainer(bsn, "hash", attrs, result, blocker);
}
// If we reach this far, none of the repos found the resource.
return new Container(this, bsn, "hash", Container.TYPE.ERROR, null, "Could not find resource by content hash " + hashStr, null, null);
}
use of org.osgi.resource.Requirement in project bnd by bndtools.
the class ResourceImpl method setRequirements.
void setRequirements(List<Requirement> requirements) {
Map<String, List<Requirement>> prepare = new HashMap<>();
for (Requirement requirement : requirements) {
List<Requirement> list = prepare.get(requirement.getNamespace());
if (list == null) {
list = new LinkedList<Requirement>();
prepare.put(requirement.getNamespace(), list);
}
list.add(requirement);
}
for (Map.Entry<String, List<Requirement>> entry : prepare.entrySet()) {
entry.setValue(unmodifiableList(new ArrayList<>(entry.getValue())));
}
allRequirements = unmodifiableList(new ArrayList<>(requirements));
requirementMap = prepare;
}
Aggregations