Search in sources :

Example 51 with CapReqBuilder

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

the class BndrunResolveContextTest method testResolverHookFiltersResult.

public static void testResolverHookFiltersResult() {
    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 removes all capabilities from resource with id
    // "osgi.cmpn"
    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 ("osgi.cmpn".equals(id))
                    iter.remove();
            }
        }
    });
    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);
    assertEquals(1, providers.size());
    assertEquals(IO.getFile("testdata/org.apache.felix.framework-4.0.2.jar").toURI(), findContentURI(providers.get(0).getResource()));
// The capability from osgi.cmpn is NOT here
}
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 52 with CapReqBuilder

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

the class BndrunResolveContextTest method testSimple.

/**
	 * Simple test that checks if we can find a resource through the
	 * findProviders
	 */
public static void testSimple() {
    MockRegistry registry = new MockRegistry();
    registry.addPlugin(createRepo(IO.getFile("testdata/repo1.index.xml"), "Repository1"));
    BndrunResolveContext context = new BndrunResolveContext(new BndEditModel(), registry, log);
    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(1, providers.size());
    Resource resource = providers.get(0).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 53 with CapReqBuilder

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

the class BndrunResolveContextTest method testUnsatisfiedSystemPackage.

public static void testUnsatisfiedSystemPackage() {
    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.wiring.package").addDirective("filter", "(osgi.wiring.package=sun.reflect)").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 54 with CapReqBuilder

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

the class BndrunResolveContextTest method testBasicFindProviders.

public static void testBasicFindProviders() {
    MockRegistry registry = new MockRegistry();
    registry.addPlugin(createRepo(IO.getFile("testdata/repo1.index.xml")));
    BndEditModel runModel = new BndEditModel();
    BndrunResolveContext context = new BndrunResolveContext(runModel, registry, log);
    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(1, providers.size());
    Resource resource = providers.get(0).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 55 with CapReqBuilder

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

the class AbstractIndexedRepo method findByHash.

ResourceHandle findByHash(String bsn, Map<String, String> properties) throws Exception {
    if (bsn == null)
        throw new IllegalArgumentException("Bundle symbolic name must be specified");
    // Get the hash string
    String hashStr = properties.get("hash");
    if (hashStr == null)
        throw new IllegalArgumentException("Content hash must be provided (using hash=<algo>:<hash>) when version=hash is specified");
    // Parse into algo and hash
    String algo = SHA_256;
    int colonIndex = hashStr.indexOf(':');
    if (colonIndex > -1) {
        algo = hashStr.substring(0, colonIndex);
        int afterColon = colonIndex + 1;
        hashStr = (colonIndex < hashStr.length()) ? hashStr.substring(afterColon) : "";
    }
    // R5 indexes are always SHA-256
    if (!SHA_256.equalsIgnoreCase(algo))
        return null;
    String contentFilter = String.format("(%s=%s)", ContentNamespace.CONTENT_NAMESPACE, hashStr);
    Requirement contentReq = new CapReqBuilder(ContentNamespace.CONTENT_NAMESPACE).filter(contentFilter).buildSyntheticRequirement();
    List<Capability> caps = new LinkedList<>();
    capabilityIndex.appendMatchingCapabilities(contentReq, caps);
    if (caps.isEmpty())
        return null;
    Resource resource = caps.get(0).getResource();
    Capability identityCap = getIdentityCapability(resource);
    Object id = identityCap.getAttributes().get(IdentityNamespace.IDENTITY_NAMESPACE);
    if (!bsn.equals(id))
        throw new IllegalArgumentException(String.format("Resource with requested hash does not match ID '%s' [hash: %s]", bsn, hashStr));
    return mapResourceToHandle(resource);
}
Also used : CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) Requirement(org.osgi.resource.Requirement) RepoResourceUtils.getIdentityCapability(aQute.bnd.deployer.repository.RepoResourceUtils.getIdentityCapability) Capability(org.osgi.resource.Capability) Resource(org.osgi.resource.Resource) LinkedList(java.util.LinkedList)

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