Search in sources :

Example 91 with Requirement

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));
}
Also used : CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) Requirement(org.osgi.resource.Requirement) Processor(aQute.bnd.osgi.Processor) Document(aQute.bnd.properties.Document) File(java.io.File) BndEditModel(aQute.bnd.build.model.BndEditModel) LinkedList(java.util.LinkedList) Workspace(aQute.bnd.build.Workspace)

Example 92 with Requirement

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"));
}
Also used : CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) Requirement(org.osgi.resource.Requirement) Capability(org.osgi.resource.Capability) HashMap(java.util.HashMap) Collection(java.util.Collection)

Example 93 with Requirement

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());
}
Also used : Requirement(org.osgi.resource.Requirement) Repository(org.osgi.service.repository.Repository) Resource(org.osgi.resource.Resource) Collection(java.util.Collection) File(java.io.File)

Example 94 with Requirement

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"));
}
Also used : Requirement(org.osgi.resource.Requirement) Parameters(aQute.bnd.header.Parameters)

Example 95 with Requirement

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));
}
Also used : Requirement(org.osgi.resource.Requirement) Capability(org.osgi.resource.Capability) CapabilityBuilder(aQute.bnd.osgi.resource.CapabilityBuilder) RequirementBuilder(aQute.bnd.osgi.resource.RequirementBuilder)

Aggregations

Requirement (org.osgi.resource.Requirement)201 Capability (org.osgi.resource.Capability)103 Resource (org.osgi.resource.Resource)59 CapReqBuilder (aQute.bnd.osgi.resource.CapReqBuilder)53 ArrayList (java.util.ArrayList)51 Collection (java.util.Collection)44 BndEditModel (aQute.bnd.build.model.BndEditModel)35 HashMap (java.util.HashMap)35 IdentityCapability (aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability)34 MockRegistry (test.lib.MockRegistry)32 List (java.util.List)19 Repository (org.osgi.service.repository.Repository)19 Test (org.junit.Test)18 File (java.io.File)16 Map (java.util.Map)12 Resolver (org.osgi.service.resolver.Resolver)11 LinkedHashSet (java.util.LinkedHashSet)10 LinkedList (java.util.LinkedList)10 Wire (org.osgi.resource.Wire)10 Parameters (aQute.bnd.header.Parameters)9