Search in sources :

Example 76 with Requirement

use of org.osgi.resource.Requirement in project bnd by bndtools.

the class BndrunResolveContextTest method testProviderPreference.

public static void testProviderPreference() {
    Requirement req = new CapReqBuilder("osgi.wiring.package").addDirective("filter", "(osgi.wiring.package=org.apache.felix.gogo.api)").buildSyntheticRequirement();
    MockRegistry registry;
    BndrunResolveContext context;
    List<Capability> providers;
    Resource resource;
    // First try it with repo1 first
    registry = new MockRegistry();
    registry.addPlugin(createRepo(IO.getFile("testdata/repo1.index.xml")));
    registry.addPlugin(createRepo(IO.getFile("testdata/repo2.index.xml")));
    context = new BndrunResolveContext(new BndEditModel(), registry, log);
    providers = context.findProviders(req);
    assertEquals(2, providers.size());
    resource = providers.get(0).getResource();
    assertEquals(IO.getFile("testdata/repo1/org.apache.felix.gogo.runtime-0.10.0.jar").toURI(), findContentURI(resource));
    resource = providers.get(1).getResource();
    assertEquals(IO.getFile("testdata/repo2/org.apache.felix.gogo.runtime-0.10.0.jar").toURI(), findContentURI(resource));
    // Now try it with repo2 first
    registry = new MockRegistry();
    registry.addPlugin(createRepo(IO.getFile("testdata/repo2.index.xml")));
    registry.addPlugin(createRepo(IO.getFile("testdata/repo1.index.xml")));
    context = new BndrunResolveContext(new BndEditModel(), registry, log);
    providers = context.findProviders(req);
    assertEquals(2, providers.size());
    resource = providers.get(0).getResource();
    assertEquals(IO.getFile("testdata/repo2/org.apache.felix.gogo.runtime-0.10.0.jar").toURI(), findContentURI(resource));
    resource = providers.get(1).getResource();
    assertEquals(IO.getFile("testdata/repo1/org.apache.felix.gogo.runtime-0.10.0.jar").toURI(), findContentURI(resource));
}
Also used : CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) Requirement(org.osgi.resource.Requirement) Capability(org.osgi.resource.Capability) IdentityCapability(aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability) MockRegistry(test.lib.MockRegistry) Resource(org.osgi.resource.Resource) BndEditModel(aQute.bnd.build.model.BndEditModel)

Example 77 with Requirement

use of org.osgi.resource.Requirement in project bnd by bndtools.

the class GenericResolveContextResolveTest method testResolveRequirementNoDirective.

/**
	 * Check default directive
	 */
public void testResolveRequirementNoDirective() {
    Repository repository = createRepo(IO.getFile("testdata/repo6/index.xml"));
    GenericResolveContext grc = new GenericResolveContext(logger);
    grc.setLevel(2);
    grc.addRepository(repository);
    Requirement logservice = new CapReqBuilder("osgi.service").addDirective("filter", "(objectClass=org.osgi.service.log.LogService)").buildSyntheticRequirement();
    List<Capability> providers = grc.findProviders(logservice);
    assertEquals(2, providers.size());
    assertNames(providers, "test.a", "test.b");
}
Also used : CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) Requirement(org.osgi.resource.Requirement) Repository(org.osgi.service.repository.Repository) Capability(org.osgi.resource.Capability)

Example 78 with Requirement

use of org.osgi.resource.Requirement in project bnd by bndtools.

the class GenericResolveContextResolveTest method testResolveRequirementActiveDirective.

public void testResolveRequirementActiveDirective() {
    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", "active").buildSyntheticRequirement();
    List<Capability> providers = grc.findProviders(logservice);
    assertEquals(3, providers.size());
    assertNames(providers, "test.a", "test.b", "test.c");
}
Also used : CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) Requirement(org.osgi.resource.Requirement) Repository(org.osgi.service.repository.Repository) Capability(org.osgi.resource.Capability)

Example 79 with Requirement

use of org.osgi.resource.Requirement in project bnd by bndtools.

the class BndrunResolveContextTest method testResolverHookFiltersResultWithBlacklistAndVersionRange2.

public static void testResolverHookFiltersResultWithBlacklistAndVersionRange2() {
    MockRegistry registry = new MockRegistry();
    registry.addPlugin(createRepo(new File("testdata/osgi.cmpn-4.3.0.index.xml")));
    registry.addPlugin(createRepo(new File("testdata/org.apache.felix.framework-4.0.2.index.xml")));
    // Add a hook that removes all capabilities from resource with id
    // "osgi.cmpn"
    HashMap<String, String> blacklistProp = new HashMap<String, String>();
    BndEditModel runModel = new BndEditModel();
    ArrayList<Requirement> blacklistlist = new ArrayList<Requirement>();
    blacklistlist.add(CapReqBuilder.createSimpleRequirement("osgi.identity", "osgi.cmpn", "[4.0.0,4.4.0)").buildSyntheticRequirement());
    runModel.setRunBlacklist(blacklistlist);
    runModel.setRunFw("org.apache.felix.framework");
    Requirement requirement = new CapReqBuilder("osgi.wiring.package").addDirective("filter", "(&(osgi.wiring.package=org.osgi.util.tracker)(version>=1.5)(!(version>=1.6)))").buildSyntheticRequirement();
    BndrunResolveContext context = new BndrunResolveContext(runModel, registry, log);
    List<Capability> providers = context.findProviders(requirement);
    assertEquals(1, providers.size());
    assertEquals(new File("testdata/org.apache.felix.framework-4.0.2.jar").toURI(), findContentURI(providers.get(0).getResource()));
}
Also used : CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) Capability(org.osgi.resource.Capability) IdentityCapability(aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability) HashMap(java.util.HashMap) MockRegistry(test.lib.MockRegistry) ArrayList(java.util.ArrayList) Requirement(org.osgi.resource.Requirement) File(java.io.File) BndEditModel(aQute.bnd.build.model.BndEditModel)

Example 80 with Requirement

use of org.osgi.resource.Requirement in project bnd by bndtools.

the class BndrunResolveContextTest method testResolverHookFiltersResultWithBlacklistAndVersionRange1.

public static void testResolverHookFiltersResultWithBlacklistAndVersionRange1() {
    MockRegistry registry = new MockRegistry();
    registry.addPlugin(createRepo(new File("testdata/osgi.cmpn-4.3.0.index.xml")));
    registry.addPlugin(createRepo(new File("testdata/org.apache.felix.framework-4.0.2.index.xml")));
    // Add a hook that removes all capabilities from resource with id
    // "osgi.cmpn"
    HashMap<String, String> blacklistProp = new HashMap<String, String>();
    BndEditModel runModel = new BndEditModel();
    ArrayList<Requirement> blacklistlist = new ArrayList<Requirement>();
    blacklistlist.add(CapReqBuilder.createSimpleRequirement("osgi.identity", "osgi.cmpn", "[4.0.0,4.3.0)").buildSyntheticRequirement());
    runModel.setRunBlacklist(blacklistlist);
    runModel.setRunFw("org.apache.felix.framework");
    Requirement requirement = new CapReqBuilder("osgi.wiring.package").addDirective("filter", "(&(osgi.wiring.package=org.osgi.util.tracker)(version>=1.5)(!(version>=1.6)))").buildSyntheticRequirement();
    BndrunResolveContext context = new BndrunResolveContext(runModel, registry, log);
    List<Capability> providers = context.findProviders(requirement);
    assertEquals(2, providers.size());
    assertEquals(new File("testdata/org.apache.felix.framework-4.0.2.jar").toURI(), findContentURI(providers.get(0).getResource()));
    assertEquals(new File("testdata/osgi.cmpn-4.3.0.jar").toURI(), findContentURI(providers.get(1).getResource()));
}
Also used : CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) Capability(org.osgi.resource.Capability) IdentityCapability(aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability) HashMap(java.util.HashMap) MockRegistry(test.lib.MockRegistry) ArrayList(java.util.ArrayList) Requirement(org.osgi.resource.Requirement) File(java.io.File) BndEditModel(aQute.bnd.build.model.BndEditModel)

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