use of aQute.bnd.osgi.resource.CapReqBuilder in project bnd by bndtools.
the class TestWrapper method testListsBecomeStrings.
/**
* Attributes do not properly encode lists (they are encoded as "[a,b]",
* e.g. there is a toString somewhere // This turned out to be caused by the
* PersistentResource.getAttr conversion/type guessing. We always turned an
* object into a string; so lists became strings.
*/
public void testListsBecomeStrings() throws Exception {
InfoRepositoryWrapper iw = getRepo();
Requirement cr = new CapReqBuilder("osgi.service").filter("(objectClass=osgi.enroute.logger.api.LoggerAdmin)").addDirective("effective", "active").buildSyntheticRequirement();
Map<Requirement, Collection<Capability>> provider = iw.findProviders(Collections.singleton(cr));
assertEquals(1, provider.size());
}
use of aQute.bnd.osgi.resource.CapReqBuilder in project bnd by bndtools.
the class TestWrapper method testImportService.
/**
* Could not find an Import-Service capability // This turned out to be
* caused by a toLowerCase in the filter :-(
*/
public void testImportService() throws Exception {
InfoRepositoryWrapper iw = getRepo();
Requirement cr = new CapReqBuilder("osgi.service").filter("(objectClass=org.slf4j.Logger)").addDirective("effective", "active").buildSyntheticRequirement();
Map<Requirement, Collection<Capability>> provider = iw.findProviders(Collections.singleton(cr));
assertNotNull(provider);
assertEquals(1, provider.size());
Capability cap = provider.values().iterator().next().iterator().next();
Resource resource = cap.getResource();
assertNotNull(resource);
List<Capability> capabilities = resource.getCapabilities("osgi.identity");
assertEquals(1, capabilities.size());
Capability identity = capabilities.iterator().next();
assertEquals("osgi.logger.provider", identity.getAttributes().get("osgi.identity"));
}
use of aQute.bnd.osgi.resource.CapReqBuilder in project bnd by bndtools.
the class TestWrapper method testAugment2.
/**
* Test the augments facility. This allows us to add caps/reqs to bundles
* with a file from the workspace.
*/
public void testAugment2() throws Exception {
File cache = new File("generated/tmp/test/cache");
IO.deleteWithException(cache);
Workspace ws = Workspace.getWorkspace(IO.getFile("testdata/ws"));
assertNotNull(ws);
Repository repo = ws.getPlugin(Repository.class);
assertNotNull(repo);
assertNotNull(repo.get("biz.aQute.jpm.daemon", new Version("1.1.0"), null));
org.osgi.service.repository.Repository osgi = ws.getPlugin(org.osgi.service.repository.Repository.class);
//
// Get the test and identity capability
//
Requirement testreq = new CapReqBuilder("test").filter("(test=1)").buildSyntheticRequirement();
Requirement identity = new CapReqBuilder("osgi.identity").filter("(osgi.identity=biz.aQute.jpm.daemon)").buildSyntheticRequirement();
Map<Requirement, Collection<Capability>> result = osgi.findProviders(Arrays.asList(testreq, identity));
assertNotNull(result);
assertEquals(2, result.size());
//
// Test if they come from the same resource
//
Capability testcap = result.get(testreq).iterator().next();
Capability identitycap = result.get(identity).iterator().next();
assertNotNull(testcap);
assertNotNull(identitycap);
assertEquals(testcap.getResource(), identitycap.getResource());
}
use of aQute.bnd.osgi.resource.CapReqBuilder in project bnd by bndtools.
the class AbstractResolveContext method setFramework.
/**
* Add a framework resource to the system resource builder
*
* @param system the system resource being build up
* @param framework the framework resource
* @throws Exception
*/
protected void setFramework(ResourceBuilder system, Resource framework) throws Exception {
//
// We copy the framework capabilities
//
system.addCapabilities(framework.getCapabilities(null));
//
// Add system.bundle alias. This is mandated by the spec that a
// framework has a bundle namespace capability.
//
CapReqBuilder cap = new CapReqBuilder(BundleNamespace.BUNDLE_NAMESPACE);
cap.addAttribute(BundleNamespace.BUNDLE_NAMESPACE, Constants.SYSTEM_BUNDLE_SYMBOLICNAME);
//
// TODO BJ is this right? Use the version of the provider framework?
//
String frameworkVersion = ResourceUtils.getIdentityVersion(framework);
cap.addAttribute(BundleNamespace.CAPABILITY_BUNDLE_VERSION_ATTRIBUTE, frameworkVersion);
system.addCapability(cap);
//
// Add a HOST namespace capability for fragments
//
cap = new CapReqBuilder(HostNamespace.HOST_NAMESPACE);
cap.addAttribute(HostNamespace.HOST_NAMESPACE, Constants.SYSTEM_BUNDLE_SYMBOLICNAME);
//
// TODO BJ is this right? Use the version of the provider framework?
//
cap.addAttribute(HostNamespace.CAPABILITY_BUNDLE_VERSION_ATTRIBUTE, frameworkVersion);
system.addCapability(cap);
this.framework = framework;
}
use of aQute.bnd.osgi.resource.CapReqBuilder in project bndtools by bndtools.
the class RunRequirementsPart method createRequirement.
private static Requirement createRequirement(Object elem) {
String bsn = null;
Version version = null;
if (elem instanceof RepositoryBundle) {
bsn = ((RepositoryBundle) elem).getBsn();
} else if (elem instanceof RepositoryBundleVersion) {
RepositoryBundleVersion rbv = (RepositoryBundleVersion) elem;
bsn = rbv.getBsn();
version = rbv.getVersion();
} else if (elem instanceof ProjectBundle) {
bsn = ((ProjectBundle) elem).getBsn();
}
if (bsn != null) {
Filter filter = new SimpleFilter(IdentityNamespace.IDENTITY_NAMESPACE, bsn);
if (version != null) {
filter = new AndFilter().addChild(filter).addChild(new SimpleFilter("version", Operator.GreaterThanOrEqual, version.toString()));
}
Requirement req = new CapReqBuilder(IdentityNamespace.IDENTITY_NAMESPACE).addDirective(Namespace.REQUIREMENT_FILTER_DIRECTIVE, filter.toString()).buildSyntheticRequirement();
return req;
}
return null;
}
Aggregations