Search in sources :

Example 56 with CapReqBuilder

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

the class TestWrapper method testListsBecomeStrings.

/**
	 * Attributes do not properly encode lists (they are encoded as "[a,b]",
	 * e.g. there is a toString somewhere // This turned out to be caused by the
	 * PersistentResource.getAttr conversion/type guessing. We always turned an
	 * object into a string; so lists became strings.
	 */
public void testListsBecomeStrings() throws Exception {
    InfoRepositoryWrapper iw = getRepo();
    Requirement cr = new CapReqBuilder("osgi.service").filter("(objectClass=osgi.enroute.logger.api.LoggerAdmin)").addDirective("effective", "active").buildSyntheticRequirement();
    Map<Requirement, Collection<Capability>> provider = iw.findProviders(Collections.singleton(cr));
    assertEquals(1, provider.size());
}
Also used : CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) Requirement(org.osgi.resource.Requirement) Collection(java.util.Collection)

Example 57 with CapReqBuilder

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

the class TestWrapper method testImportService.

/**
	 * Could not find an Import-Service capability // This turned out to be
	 * caused by a toLowerCase in the filter :-(
	 */
public void testImportService() throws Exception {
    InfoRepositoryWrapper iw = getRepo();
    Requirement cr = new CapReqBuilder("osgi.service").filter("(objectClass=org.slf4j.Logger)").addDirective("effective", "active").buildSyntheticRequirement();
    Map<Requirement, Collection<Capability>> provider = iw.findProviders(Collections.singleton(cr));
    assertNotNull(provider);
    assertEquals(1, provider.size());
    Capability cap = provider.values().iterator().next().iterator().next();
    Resource resource = cap.getResource();
    assertNotNull(resource);
    List<Capability> capabilities = resource.getCapabilities("osgi.identity");
    assertEquals(1, capabilities.size());
    Capability identity = capabilities.iterator().next();
    assertEquals("osgi.logger.provider", identity.getAttributes().get("osgi.identity"));
}
Also used : CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) Requirement(org.osgi.resource.Requirement) Capability(org.osgi.resource.Capability) Resource(org.osgi.resource.Resource) Collection(java.util.Collection)

Example 58 with CapReqBuilder

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

the class TestWrapper method testAugment2.

/**
	 * Test the augments facility. This allows us to add caps/reqs to bundles
	 * with a file from the workspace.
	 */
public void testAugment2() throws Exception {
    File cache = new File("generated/tmp/test/cache");
    IO.deleteWithException(cache);
    Workspace ws = Workspace.getWorkspace(IO.getFile("testdata/ws"));
    assertNotNull(ws);
    Repository repo = ws.getPlugin(Repository.class);
    assertNotNull(repo);
    assertNotNull(repo.get("biz.aQute.jpm.daemon", new Version("1.1.0"), null));
    org.osgi.service.repository.Repository osgi = ws.getPlugin(org.osgi.service.repository.Repository.class);
    //
    // Get the test and identity capability
    //
    Requirement testreq = new CapReqBuilder("test").filter("(test=1)").buildSyntheticRequirement();
    Requirement identity = new CapReqBuilder("osgi.identity").filter("(osgi.identity=biz.aQute.jpm.daemon)").buildSyntheticRequirement();
    Map<Requirement, Collection<Capability>> result = osgi.findProviders(Arrays.asList(testreq, identity));
    assertNotNull(result);
    assertEquals(2, result.size());
    //
    // Test if they come from the same resource
    //
    Capability testcap = result.get(testreq).iterator().next();
    Capability identitycap = result.get(identity).iterator().next();
    assertNotNull(testcap);
    assertNotNull(identitycap);
    assertEquals(testcap.getResource(), identitycap.getResource());
}
Also used : CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) Requirement(org.osgi.resource.Requirement) InfoRepository(aQute.bnd.service.repository.InfoRepository) Repository(aQute.bnd.jpm.Repository) Capability(org.osgi.resource.Capability) Version(aQute.bnd.version.Version) Collection(java.util.Collection) File(java.io.File) Workspace(aQute.bnd.build.Workspace)

Example 59 with CapReqBuilder

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

the class AbstractResolveContext method setFramework.

/**
	 * Add a framework resource to the system resource builder
	 * 
	 * @param system the system resource being build up
	 * @param framework the framework resource
	 * @throws Exception
	 */
protected void setFramework(ResourceBuilder system, Resource framework) throws Exception {
    //
    // We copy the framework capabilities
    //
    system.addCapabilities(framework.getCapabilities(null));
    //
    // Add system.bundle alias. This is mandated by the spec that a
    // framework has a bundle namespace capability.
    //
    CapReqBuilder cap = new CapReqBuilder(BundleNamespace.BUNDLE_NAMESPACE);
    cap.addAttribute(BundleNamespace.BUNDLE_NAMESPACE, Constants.SYSTEM_BUNDLE_SYMBOLICNAME);
    //
    // TODO BJ is this right? Use the version of the provider framework?
    //
    String frameworkVersion = ResourceUtils.getIdentityVersion(framework);
    cap.addAttribute(BundleNamespace.CAPABILITY_BUNDLE_VERSION_ATTRIBUTE, frameworkVersion);
    system.addCapability(cap);
    //
    // Add a HOST namespace capability for fragments
    //
    cap = new CapReqBuilder(HostNamespace.HOST_NAMESPACE);
    cap.addAttribute(HostNamespace.HOST_NAMESPACE, Constants.SYSTEM_BUNDLE_SYMBOLICNAME);
    //
    // TODO BJ is this right? Use the version of the provider framework?
    //
    cap.addAttribute(HostNamespace.CAPABILITY_BUNDLE_VERSION_ATTRIBUTE, frameworkVersion);
    system.addCapability(cap);
    this.framework = framework;
}
Also used : CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder)

Example 60 with CapReqBuilder

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

the class RunRequirementsPart method createRequirement.

private static Requirement createRequirement(Object elem) {
    String bsn = null;
    Version version = null;
    if (elem instanceof RepositoryBundle) {
        bsn = ((RepositoryBundle) elem).getBsn();
    } else if (elem instanceof RepositoryBundleVersion) {
        RepositoryBundleVersion rbv = (RepositoryBundleVersion) elem;
        bsn = rbv.getBsn();
        version = rbv.getVersion();
    } else if (elem instanceof ProjectBundle) {
        bsn = ((ProjectBundle) elem).getBsn();
    }
    if (bsn != null) {
        Filter filter = new SimpleFilter(IdentityNamespace.IDENTITY_NAMESPACE, bsn);
        if (version != null) {
            filter = new AndFilter().addChild(filter).addChild(new SimpleFilter("version", Operator.GreaterThanOrEqual, version.toString()));
        }
        Requirement req = new CapReqBuilder(IdentityNamespace.IDENTITY_NAMESPACE).addDirective(Namespace.REQUIREMENT_FILTER_DIRECTIVE, filter.toString()).buildSyntheticRequirement();
        return req;
    }
    return null;
}
Also used : RepositoryBundle(bndtools.model.repo.RepositoryBundle) ProjectBundle(bndtools.model.repo.ProjectBundle) CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) AndFilter(aQute.libg.filters.AndFilter) Requirement(org.osgi.resource.Requirement) RepositoryBundleVersion(bndtools.model.repo.RepositoryBundleVersion) Version(aQute.bnd.version.Version) RepositoryBundleVersion(bndtools.model.repo.RepositoryBundleVersion) SimpleFilter(aQute.libg.filters.SimpleFilter) AndFilter(aQute.libg.filters.AndFilter) Filter(aQute.libg.filters.Filter) LiteralFilter(aQute.libg.filters.LiteralFilter) SimpleFilter(aQute.libg.filters.SimpleFilter)

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