Search in sources :

Example 71 with Capability

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

the class ResolveTest method getResource.

/**
	 * Check if we can resolve against capabilities defined on the -provided
	 */
// public static void testResolveWithProfile() throws Exception {
// Resolver resolver = new BndResolver(new ResolverLogger(4));
// MockRegistry registry = new MockRegistry();
// registry.addPlugin(createRepo(IO.getFile("testdata/repo3.index.xml")));
// BndEditModel model = new BndEditModel();
//
// //
// // Provided capabilities
// //
//
// model.setRunFw("org.apache.felix.framework");
// model.setGenericString(Constants.DISTRO,
// "testdata/repo1/org.apache.felix.gogo.runtime-0.10.0.jar;version=file");
//
// //
// // We require gogo, but now the gogo runtime is on the runpath
// // so should be excluded
// //
//
// Requirement erq =
// CapReqBuilder.createPackageRequirement("org.apache.felix.gogo.api",
// "0.10.0")
// .buildSyntheticRequirement();
//
// model.setRunRequires(Arrays.asList(erq));
//
// BndrunResolveContext context = new BndrunResolveContext(model, registry,
// log);
// context.setLevel(4);
// context.init();
//
// Map<Resource,List<Wire>> resolved = resolver.resolve(context);
// List<Wire> wires = resolved.get(context.getInputResource());
// assertNotNull(wires);
// boolean found = false;
// for ( Wire wire : wires ) {
// if (equals(wire.getRequirement(), erq)) {
// found = true;
// assertTrue(wire.getProvider().equals(context.getSystemResource()));
// }
// }
// assertTrue("System resource not found for wire", found);
//
// Set<Resource> resources = resolved.keySet();
// Resource resource = getResource(resources,
// "org.apache.felix.gogo.runtime", "0.10");
// assertNull(resource);
//
// }
// private static boolean equals(Requirement a, Requirement b) {
// if ( a== b)
// return true;
//
// if ( a == null || b == null)
// return false;
//
// if ( a.equals(b))
// return true;
//
// if ( !a.getNamespace().equals(b.getNamespace()))
// return false;
//
// return a.getDirectives().equals(b.getDirectives()) &&
// a.getAttributes().equals(b.getAttributes());
// }
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((String) version);
                }
                if (requested.equals(current)) {
                    return resource;
                }
            }
        }
    }
    return null;
}
Also used : Capability(org.osgi.resource.Capability) Version(org.osgi.framework.Version) Resource(org.osgi.resource.Resource)

Example 72 with Capability

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

the class BndrunResolveContextTest method testResolveSystemCapabilitiesExtra.

public static void testResolveSystemCapabilitiesExtra() {
    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.genericSet("-runsystemcapabilities", "osgi.extender;osgi.extender=foobar;version:Version=1.0");
    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(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) MockRegistry(test.lib.MockRegistry) BndEditModel(aQute.bnd.build.model.BndEditModel)

Example 73 with Capability

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

the class BndrunResolveContextTest method testResolveSystemBundleAlias.

public static void testResolveSystemBundleAlias() {
    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.host").addDirective("filter", "(osgi.wiring.host=system.bundle)").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) MockRegistry(test.lib.MockRegistry) BndEditModel(aQute.bnd.build.model.BndEditModel)

Example 74 with Capability

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

the class BndrunResolveContextTest method testJREPackageNotResolved.

public static void testJREPackageNotResolved() {
    MockRegistry registry = new MockRegistry();
    registry.addPlugin(createRepo(IO.getFile("testdata/repo3.index.xml")));
    BndEditModel runModel = new BndEditModel();
    runModel.setRunFw("org.apache.felix.framework");
    // javax.annotation added in Java 6
    runModel.setEE(EE.J2SE_1_5);
    BndrunResolveContext context = new BndrunResolveContext(runModel, registry, log);
    Requirement req = CapReqBuilder.createPackageRequirement("javax.annotation", null).buildSyntheticRequirement();
    List<Capability> providers = context.findProviders(req);
    assertEquals(0, providers.size());
}
Also used : 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 75 with Capability

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

the class BndrunResolveContextTest method testFrameworkCapabilitiesPreferredOverRepository.

public static void testFrameworkCapabilitiesPreferredOverRepository() {
    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")));
    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(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) MockRegistry(test.lib.MockRegistry) BndEditModel(aQute.bnd.build.model.BndEditModel)

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