use of org.osgi.resource.Requirement in project bnd by bndtools.
the class TestObrCapReqParsing method testObrEEReq.
public static void testObrEEReq() throws Exception {
FileInputStream stream = new FileInputStream("testdata/bree-obr.xml");
URI baseUri = new File("testdata").toURI();
List<Resource> resources = parseIndex(stream, baseUri);
assertEquals(1, resources.size());
List<Requirement> eeReqs = resources.get(0).getRequirements("osgi.ee");
assertNotNull(eeReqs);
assertEquals(1, eeReqs.size());
assertEquals("(|(osgi.ee=J2SE-1.4)(osgi.ee=OSGi/Minimum-1.1))", eeReqs.get(0).getDirectives().get("filter"));
}
use of org.osgi.resource.Requirement 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 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 ResourceTest method getResources.
private Set<Resource> getResources(String locations) throws MalformedURLException, URISyntaxException {
FixedIndexedRepo repo = new FixedIndexedRepo();
repo.setLocations(locations);
Requirement wildcard = ResourceUtils.createWildcardRequirement();
Collection<Capability> caps = repo.findProviders(Collections.singleton(wildcard)).get(wildcard);
return ResourceUtils.getResources(caps);
}
Aggregations