use of org.osgi.resource.Requirement in project bnd by bndtools.
the class BndEditModelTest method testVariableInRunRequirements.
public static void testVariableInRunRequirements() throws Exception {
Workspace ws = new Workspace(new File("testresources/ws"));
BndEditModel model = new BndEditModel(ws);
File f = new File("testresources/ws/p7/reuse.bndrun");
model.setBndResource(f);
model.setBndResourceName("reuse.bndrun");
model.loadFrom(f);
// VERIFY
Processor processor = model.getProperties();
String runrequirements = processor.mergeProperties(Constants.RUNREQUIRES);
String[] rrr = runrequirements.split(",");
assertEquals(4, rrr.length);
assertEquals("osgi.identity;filter:='(osgi.identity=variable)'", rrr[0]);
assertEquals("osgi.identity;filter:='(osgi.identity=variable2)'", rrr[1]);
assertEquals("osgi.identity;filter:='(osgi.identity=b)'", rrr[2]);
assertEquals("osgi.identity;filter:='(osgi.identity=c)'", rrr[3]);
// [cs] don't know how to update this.
List<Requirement> r = model.getRunRequires();
assertEquals(3, r.size());
assertEquals(new CapReqBuilder("${var}").buildSyntheticRequirement(), r.get(0));
assertEquals(new CapReqBuilder(IdentityNamespace.IDENTITY_NAMESPACE).addDirective(Namespace.REQUIREMENT_FILTER_DIRECTIVE, "(osgi.identity=b)").buildSyntheticRequirement(), r.get(1));
assertEquals(new CapReqBuilder(IdentityNamespace.IDENTITY_NAMESPACE).addDirective(Namespace.REQUIREMENT_FILTER_DIRECTIVE, "(osgi.identity=c)").buildSyntheticRequirement(), r.get(2));
// Test Set with variables
List<Requirement> rr = new LinkedList<Requirement>();
rr.add(new CapReqBuilder(IdentityNamespace.IDENTITY_NAMESPACE).addDirective(Namespace.REQUIREMENT_FILTER_DIRECTIVE, "(osgi.identity=b)").buildSyntheticRequirement());
rr.add(new CapReqBuilder("${var}").buildSyntheticRequirement());
model.setRunRequires(rr);
// VERIFY
processor = model.getProperties();
runrequirements = processor.mergeProperties(Constants.RUNREQUIRES);
rrr = runrequirements.split(",");
assertEquals(3, rrr.length);
assertEquals("osgi.identity;filter:='(osgi.identity=b)'", rrr[0]);
assertEquals("osgi.identity;filter:='(osgi.identity=variable)'", rrr[1]);
assertEquals("osgi.identity;filter:='(osgi.identity=variable2)'", rrr[2]);
// Test SET
rr = new LinkedList<Requirement>();
rr.add(getReq("(osgi.identity=b)"));
rr.add(getReq("(osgi.identity=c)"));
model.setRunRequires(rr);
// VERIFY
processor = model.getProperties();
runrequirements = processor.mergeProperties(Constants.RUNREQUIRES);
rrr = runrequirements.split(",");
assertEquals(2, rrr.length);
assertEquals("osgi.identity;filter:='(osgi.identity=b)'", rrr[0]);
assertEquals("osgi.identity;filter:='(osgi.identity=c)'", rrr[1]);
r = model.getRunRequires();
assertEquals(getReq("(osgi.identity=b)"), r.get(0));
assertEquals(getReq("(osgi.identity=c)"), r.get(1));
// TEST Saving changes and those changes persist...
Document d = new Document("");
model.saveChangesTo(d);
processor = model.getProperties();
runrequirements = processor.mergeProperties(Constants.RUNREQUIRES);
rrr = runrequirements.split(",");
assertEquals(2, rrr.length);
assertEquals(" osgi.identity;filter:='(osgi.identity=b)'", rrr[0]);
assertEquals(" osgi.identity;filter:='(osgi.identity=c)'", rrr[1]);
assertEquals(getReq("(osgi.identity=b)"), r.get(0));
assertEquals(getReq("(osgi.identity=c)"), r.get(1));
}
use of org.osgi.resource.Requirement 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 org.osgi.resource.Requirement in project bnd by bndtools.
the class XMLResourceGeneratorTest method testBasic.
public void testBasic() throws URISyntaxException, Exception {
Repository repository = getTestRepository();
File location = new File(tmp, "index.xml");
new XMLResourceGenerator().name("test").repository(repository).save(location);
Repository other = getRepository(location.toURI());
Map<Requirement, Collection<Capability>> findProviders = other.findProviders(Collections.singleton(WILDCARD));
Set<Resource> resources = ResourceUtils.getResources(findProviders.get(WILDCARD));
assertEquals(1, resources.size());
Resource r = resources.iterator().next();
assertEquals("http://macbadge-updates.s3.amazonaws.com/plugins/name.njbartlett.eclipse.macbadge_1.0.0.201110100042.jar", ResourceUtils.getContentCapability(r).url().toString());
}
use of org.osgi.resource.Requirement in project bnd by bndtools.
the class CapReqBuilderTest method testAliasedRequirementWithVersion.
public void testAliasedRequirementWithVersion() throws Exception {
Parameters params = OSGiHeader.parseHeader("bnd.identity; id=org.example.foo; version=1.2");
Requirement req = CapReqBuilder.getRequirementsFrom(params).get(0);
assertEquals("osgi.identity", req.getNamespace());
assertEquals("(&(osgi.identity=org.example.foo)(version>=1.2.0))", req.getDirectives().get("filter"));
}
use of org.osgi.resource.Requirement in project bnd by bndtools.
the class CapReqFilterTest method testReqNoFilterCapWithAttr.
public void testReqNoFilterCapWithAttr() throws Exception {
Capability cap = new CapabilityBuilder("foobar").addAttribute("blah", "baz").addAttribute("version", "42").buildSyntheticCapability();
Requirement req = new RequirementBuilder("foobar").buildSyntheticRequirement();
assertTrue(ResourceUtils.matches(req, cap));
}
Aggregations