Search in sources :

Example 76 with Capability

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

the class BndrunResolveContextTest method testResolverHookCannotFilterFrameworkCapabilities.

public static void testResolverHookCannotFilterFrameworkCapabilities() {
    MockRegistry registry = new MockRegistry();
    registry.addPlugin(createRepo(IO.getFile("testdata/osgi.cmpn-4.3.0.index.xml")));
    registry.addPlugin(createRepo(IO.getFile("testdata/org.apache.felix.framework-4.0.2.index.xml")));
    // Add a hook that tries to remove all capabilities from resource with
    // id "org.apache.felix.framework"
    registry.addPlugin(new ResolverHook() {

        public void filterMatches(Requirement requirement, List<Capability> candidates) {
            for (Iterator<Capability> iter = candidates.iterator(); iter.hasNext(); ) {
                Object id = iter.next().getResource().getCapabilities("osgi.identity").get(0).getAttributes().get("osgi.identity");
                if ("org.apache.felix.framework".equals(id)) {
                    fail("this line should not be reached");
                }
            }
        }
    });
    BndEditModel runModel = new BndEditModel();
    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);
    // The filter was ineffective
    assertEquals(2, providers.size());
    assertEquals(IO.getFile("testdata/org.apache.felix.framework-4.0.2.jar").toURI(), findContentURI(providers.get(0).getResource()));
    assertEquals(IO.getFile("testdata/osgi.cmpn-4.3.0.jar").toURI(), findContentURI(providers.get(1).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) ResolverHook(aQute.bnd.service.resolve.hook.ResolverHook) MockRegistry(test.lib.MockRegistry) Iterator(java.util.Iterator) BndEditModel(aQute.bnd.build.model.BndEditModel)

Example 77 with Capability

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

the class BndrunResolveContextTest method testResolveSystemPackagesExtra.

public static void testResolveSystemPackagesExtra() {
    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);
    runModel.setSystemPackages(Collections.singletonList(new ExportedPackage("sun.reflect", new Attrs())));
    BndrunResolveContext context = new BndrunResolveContext(runModel, registry, log);
    Requirement req = new CapReqBuilder("osgi.wiring.package").addDirective("filter", "(osgi.wiring.package=sun.reflect)").buildSyntheticRequirement();
    List<Capability> providers = context.findProviders(req);
    assertEquals(1, providers.size());
    assertEquals(IO.getFile("testdata/repo3/org.apache.felix.framework-4.0.2.jar").toURI(), findContentURI(providers.get(0).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) ExportedPackage(aQute.bnd.build.model.clauses.ExportedPackage) MockRegistry(test.lib.MockRegistry) Attrs(aQute.bnd.header.Attrs) BndEditModel(aQute.bnd.build.model.BndEditModel)

Example 78 with Capability

use of org.osgi.resource.Capability 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 79 with Capability

use of org.osgi.resource.Capability 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 80 with Capability

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

the class GenericResolveContextResolveTest method getResource.

private static Resource getResource(Set<Resource> resources, String bsn, String versionString) {
    for (Resource resource : resources) {
        List<Capability> identities = resource.getCapabilities(IdentityNamespace.IDENTITY_NAMESPACE);
        if (identities != null && identities.size() == 1) {
            Capability idCap = identities.get(0);
            Object id = idCap.getAttributes().get(IdentityNamespace.IDENTITY_NAMESPACE);
            Object version = idCap.getAttributes().get(IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE);
            if (bsn.equals(id)) {
                if (versionString == null) {
                    return resource;
                }
                Version requested = Version.parseVersion(versionString);
                Version current;
                if (version instanceof Version) {
                    current = (Version) version;
                } else {
                    current = Version.parseVersion("" + version);
                }
                if (requested.equals(current)) {
                    return resource;
                }
            }
        }
    }
    return null;
}
Also used : Capability(org.osgi.resource.Capability) Version(aQute.bnd.version.Version) Resource(org.osgi.resource.Resource)

Aggregations

Capability (org.osgi.resource.Capability)197 Requirement (org.osgi.resource.Requirement)104 Resource (org.osgi.resource.Resource)61 ArrayList (java.util.ArrayList)40 HashMap (java.util.HashMap)39 IdentityCapability (aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability)37 CapReqBuilder (aQute.bnd.osgi.resource.CapReqBuilder)35 Collection (java.util.Collection)32 MockRegistry (test.lib.MockRegistry)26 BndEditModel (aQute.bnd.build.model.BndEditModel)25 Version (org.osgi.framework.Version)20 List (java.util.List)19 Repository (org.osgi.service.repository.Repository)17 Test (org.junit.Test)16 File (java.io.File)15 HostedCapability (org.osgi.service.resolver.HostedCapability)13 HashSet (java.util.HashSet)12 Map (java.util.Map)12 LinkedList (java.util.LinkedList)11 RequirementBuilder (aQute.bnd.osgi.resource.RequirementBuilder)8