use of aQute.bnd.osgi.resource.CapReqBuilder in project bnd by bndtools.
the class AbstractResolveContext method createIdentityRequirement.
public static Requirement createIdentityRequirement(String identity, String versionRange) {
// Construct a filter & requirement to find matches
Filter filter = new SimpleFilter(IdentityNamespace.IDENTITY_NAMESPACE, identity);
if (versionRange != null)
filter = new AndFilter().addChild(filter).addChild(new LiteralFilter(Filters.fromVersionRange(versionRange)));
Requirement frameworkReq = new CapReqBuilder(IdentityNamespace.IDENTITY_NAMESPACE).addDirective(Namespace.REQUIREMENT_FILTER_DIRECTIVE, filter.toString()).buildSyntheticRequirement();
return frameworkReq;
}
use of aQute.bnd.osgi.resource.CapReqBuilder in project bnd by bndtools.
the class AbstractResolveContext method createPackageCapability.
public static Capability createPackageCapability(String packageName, String versionString) throws Exception {
CapReqBuilder builder = new CapReqBuilder(PackageNamespace.PACKAGE_NAMESPACE);
builder.addAttribute(PackageNamespace.PACKAGE_NAMESPACE, packageName);
Version version = versionString != null ? new Version(versionString) : Version.emptyVersion;
builder.addAttribute(PackageNamespace.CAPABILITY_VERSION_ATTRIBUTE, version);
return builder.buildSyntheticCapability();
}
use of aQute.bnd.osgi.resource.CapReqBuilder in project bnd by bndtools.
the class PersistentResourceTest method testSimple.
public void testSimple() throws Exception {
ResourceBuilder rb = new ResourceBuilder();
rb.addCapability(new CapReqBuilder("test").addAttribute("double", 3.0).addAttribute("long", 3L).addAttribute("string", "3.0").addAttribute("version", new Version("3.0")).buildSyntheticCapability());
Resource r = rb.build();
PersistentResource pr = new PersistentResource(r);
String s = new JSONCodec().enc().put(pr).toString();
PersistentResource pr2 = new JSONCodec().dec().from(s).get(PersistentResource.class);
List<Capability> capabilities = pr.getResource().getCapabilities(null);
List<Requirement> requirements = pr.getResource().getRequirements(null);
assertEquals(1, capabilities.size());
assertEquals(0, requirements.size());
Capability capability = capabilities.get(0);
assertEquals("test", capability.getNamespace());
assertEquals(3.0, capability.getAttributes().get("double"));
assertEquals(3L, capability.getAttributes().get("long"));
assertEquals("3.0", capability.getAttributes().get("string"));
assertEquals(new Version("3.0"), capability.getAttributes().get("version"));
assertEquals(0, capability.getDirectives().size());
}
use of aQute.bnd.osgi.resource.CapReqBuilder in project bnd by bndtools.
the class TestWrapper method augmentTest.
private void augmentTest(InfoRepository repo) throws Exception, IOException {
assertNotNull(repo.get("biz.aQute.jpm.daemon", new Version("1.1.0"), null));
InfoRepositoryWrapper iw = new InfoRepositoryWrapper(tmp, Collections.singleton(repo));
Properties augments = new UTF8Properties();
augments.load(new StringReader("biz.aQute.jpm.daemon: cap=test;test=1\n"));
iw.addAugment(augments);
//
// 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 = iw.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());
iw.close();
}
use of aQute.bnd.osgi.resource.CapReqBuilder in project bndtools by bndtools.
the class RunRequirementsPart method convertLegacyRequireList.
private List<Requirement> convertLegacyRequireList(String input) throws IllegalArgumentException {
List<Requirement> result = new ArrayList<Requirement>();
if (Constants.EMPTY_HEADER.equalsIgnoreCase(input.trim()))
return result;
QuotedTokenizer qt = new QuotedTokenizer(input, ",");
String token = qt.nextToken();
while (token != null) {
String item = token.trim();
int index = item.indexOf(":");
if (index < 0)
throw new IllegalArgumentException("Invalid format for requirement");
String name = item.substring(0, index);
String filter = item.substring(index + 1);
Requirement req = new CapReqBuilder(name).addDirective(Namespace.REQUIREMENT_FILTER_DIRECTIVE, filter).buildSyntheticRequirement();
result.add(req);
token = qt.nextToken();
}
return result;
}
Aggregations