Search in sources :

Example 46 with CapReqBuilder

use of aQute.bnd.osgi.resource.CapReqBuilder in project bnd by bndtools.

the class BndrunResolveContextTest method testResolvePreferences.

public static void testResolvePreferences() {
    MockRegistry registry = new MockRegistry();
    registry.addPlugin(createRepo(IO.getFile("testdata/repo4/index.xml")));
    BndEditModel runModel = new BndEditModel();
    runModel.setRunFw("org.apache.felix.framework");
    runModel.genericSet("-resolve.preferences", "x.1");
    Requirement requirement = new CapReqBuilder("x").buildSyntheticRequirement();
    BndrunResolveContext context = new BndrunResolveContext(runModel, registry, log);
    List<Capability> providers = context.findProviders(requirement);
    assertEquals(3, providers.size());
    assertEquals(IO.getFile("testdata/repo4/x.1.jar").toURI(), findContentURI(providers.get(0).getResource()));
    assertEquals(IO.getFile("testdata/repo4/x.3.jar").toURI(), findContentURI(providers.get(1).getResource()));
    assertEquals(IO.getFile("testdata/repo4/x.2.jar").toURI(), findContentURI(providers.get(2).getResource()));
}
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) BndEditModel(aQute.bnd.build.model.BndEditModel)

Example 47 with CapReqBuilder

use of aQute.bnd.osgi.resource.CapReqBuilder in project bnd by bndtools.

the class BndrunResolveContextTest method testSimpleBlacklist.

/**
	 * Test the blacklist. We reject any resources that matches a specific
	 * requirements
	 */
public static void testSimpleBlacklist() {
    MockRegistry registry = new MockRegistry();
    registry.addPlugin(createRepo(IO.getFile("testdata/repo1.index.xml"), "Repository1"));
    BndEditModel model = new BndEditModel();
    Requirement blacklist = new CapReqBuilder("osgi.wiring.package").addDirective("filter", "(osgi.wiring.package=org.apache.felix.gogo.api)").buildSyntheticRequirement();
    model.setRunBlacklist(Arrays.asList(blacklist));
    BndrunResolveContext context = new BndrunResolveContext(model, registry, log);
    //
    // This one is ok in testSimple
    // but should fail because we blacklisted it
    //
    Requirement req = new CapReqBuilder("osgi.wiring.package").addDirective("filter", "(osgi.wiring.package=org.apache.felix.gogo.api)").buildSyntheticRequirement();
    List<Capability> providers = context.findProviders(req);
    assertEquals(0, providers.size());
}
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) BndEditModel(aQute.bnd.build.model.BndEditModel)

Example 48 with CapReqBuilder

use of aQute.bnd.osgi.resource.CapReqBuilder in project bnd by bndtools.

the class BndrunResolveContextTest method testResolverHookFiltersResultWithBlacklist.

public static void testResolverHookFiltersResultWithBlacklist() {
    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.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(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 49 with CapReqBuilder

use of aQute.bnd.osgi.resource.CapReqBuilder in project bnd by bndtools.

the class BndrunResolveContextTest method testUnsatisfiedRequirement.

public static void testUnsatisfiedRequirement() {
    MockRegistry registry = new MockRegistry();
    registry.addPlugin(createRepo(IO.getFile("testdata/repo3.index.xml")));
    BndEditModel runModel = new BndEditModel();
    runModel.setRunFw("org.apache.felix.framework");
    runModel.setEE(EE.JavaSE_1_6);
    BndrunResolveContext context = new BndrunResolveContext(runModel, registry, log);
    Requirement req = new CapReqBuilder("osgi.extender").addDirective("filter", "(&(osgi.extender=foobar)(version>=1.0))").buildSyntheticRequirement();
    List<Capability> providers = context.findProviders(req);
    assertEquals(0, providers.size());
}
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) BndEditModel(aQute.bnd.build.model.BndEditModel)

Example 50 with CapReqBuilder

use of aQute.bnd.osgi.resource.CapReqBuilder in project bnd by bndtools.

the class BndrunResolveContextTest method testReorderRepositories.

public static void testReorderRepositories() {
    Requirement req = new CapReqBuilder("osgi.wiring.package").addDirective("filter", "(osgi.wiring.package=org.apache.felix.gogo.api)").buildSyntheticRequirement();
    MockRegistry registry = new MockRegistry();
    registry.addPlugin(createRepo(IO.getFile("testdata/repo1.index.xml"), "Repository1"));
    registry.addPlugin(createRepo(IO.getFile("testdata/repo2.index.xml"), "Repository2"));
    BndrunResolveContext context;
    List<Capability> providers;
    Resource resource;
    BndEditModel runModel;
    runModel = new BndEditModel();
    runModel.setRunRepos(Arrays.asList(new String[] { "Repository2", "Repository1" }));
    context = new BndrunResolveContext(runModel, 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)

Aggregations

CapReqBuilder (aQute.bnd.osgi.resource.CapReqBuilder)69 Requirement (org.osgi.resource.Requirement)53 Capability (org.osgi.resource.Capability)35 BndEditModel (aQute.bnd.build.model.BndEditModel)32 MockRegistry (test.lib.MockRegistry)28 IdentityCapability (aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability)23 Resource (org.osgi.resource.Resource)18 ArrayList (java.util.ArrayList)11 Collection (java.util.Collection)10 Repository (org.osgi.service.repository.Repository)9 ResourceBuilder (aQute.bnd.osgi.resource.ResourceBuilder)8 HashMap (java.util.HashMap)8 File (java.io.File)7 List (java.util.List)7 AndFilter (aQute.libg.filters.AndFilter)6 LiteralFilter (aQute.libg.filters.LiteralFilter)6 SimpleFilter (aQute.libg.filters.SimpleFilter)6 Parameters (aQute.bnd.header.Parameters)5 InfoRepository (aQute.bnd.service.repository.InfoRepository)5 Version (aQute.bnd.version.Version)5