Search in sources :

Example 96 with Requirement

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"));
}
Also used : Requirement(org.osgi.resource.Requirement) Resource(org.osgi.resource.Resource) URI(java.net.URI) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 97 with Requirement

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;
}
Also used : CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) Requirement(org.osgi.resource.Requirement) QuotedTokenizer(aQute.libg.qtokens.QuotedTokenizer) ArrayList(java.util.ArrayList)

Example 98 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 99 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 100 with Requirement

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

Aggregations

Requirement (org.osgi.resource.Requirement)193 Capability (org.osgi.resource.Capability)102 Resource (org.osgi.resource.Resource)59 CapReqBuilder (aQute.bnd.osgi.resource.CapReqBuilder)53 ArrayList (java.util.ArrayList)46 Collection (java.util.Collection)44 BndEditModel (aQute.bnd.build.model.BndEditModel)35 IdentityCapability (aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability)34 HashMap (java.util.HashMap)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)14 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