use of aQute.bnd.osgi.resource.CapReqBuilder in project bnd by bndtools.
the class FindProvidersTest method testReadGZippedStream.
public static void testReadGZippedStream() throws Exception {
FixedIndexedRepo repo = new FixedIndexedRepo();
Map<String, String> props = new HashMap<String, String>();
props.put("locations", IO.getFile("testdata/big_index.xml.gz").toURI().toString());
repo.setProperties(props);
Requirement req = new CapReqBuilder("osgi.identity").addDirective("filter", "(&(osgi.identity=osgi.cmpn)(version>=4.2.0)(!(version>=4.2.1)))").buildSyntheticRequirement();
Map<Requirement, Collection<Capability>> result = repo.findProviders(Collections.singleton(req));
assertNotNull(result);
assertTrue(result.containsKey(req));
Collection<Capability> caps = result.get(req);
assertEquals(1, caps.size());
Capability identityCap = caps.iterator().next();
List<Capability> contentCaps = identityCap.getResource().getCapabilities("osgi.content");
assertNotNull(contentCaps);
assertEquals(1, contentCaps.size());
Capability contentCap = contentCaps.iterator().next();
assertEquals(IO.getFile("testdata/osgi.cmpn/osgi.cmpn-4.2.0.jar").getAbsoluteFile().toURI(), contentCap.getAttributes().get("url"));
}
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;
}
use of aQute.bnd.osgi.resource.CapReqBuilder in project bnd by bndtools.
the class GenericResolveContextResolveTest method testResolveRequirementResolveDirective.
/**
* Check expressly set directive
*/
public void testResolveRequirementResolveDirective() {
Repository repository = createRepo(IO.getFile("testdata/repo6/index.xml"));
GenericResolveContext grc = new GenericResolveContext(logger);
grc.addRepository(repository);
Requirement logservice = new CapReqBuilder("osgi.service").addDirective("filter", "(objectClass=org.osgi.service.log.LogService)").addDirective("effective", "resolve").buildSyntheticRequirement();
List<Capability> providers = grc.findProviders(logservice);
assertEquals(2, providers.size());
assertNames(providers, "test.a", "test.b");
}
Aggregations