Search in sources :

Example 91 with Resource

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

the class BndrunResolveContextTest method testChooseHighestFrameworkVersion.

public static void testChooseHighestFrameworkVersion() {
    MockRegistry registry;
    BndEditModel runModel;
    BndrunResolveContext context;
    Collection<Resource> resources;
    Resource fwkResource;
    registry = new MockRegistry();
    registry.addPlugin(createRepo(IO.getFile("testdata/org.apache.felix.framework-4.0.0.index.xml")));
    registry.addPlugin(createRepo(IO.getFile("testdata/repo3.index.xml")));
    runModel = new BndEditModel();
    runModel.setRunFw("org.apache.felix.framework;version='[4,4.1)'");
    context = new BndrunResolveContext(runModel, registry, log);
    context.init();
    assertEquals(IO.getFile("testdata/repo3/org.apache.felix.framework-4.0.2.jar").toURI(), findContentURI(context.getFramework()));
    // Try it the other way round
    registry = new MockRegistry();
    registry.addPlugin(createRepo(IO.getFile("testdata/repo3.index.xml")));
    registry.addPlugin(createRepo(IO.getFile("testdata/org.apache.felix.framework-4.0.0.index.xml")));
    runModel = new BndEditModel();
    runModel.setRunFw("org.apache.felix.framework;version='[4,4.1)'");
    context = new BndrunResolveContext(runModel, registry, log);
    context.init();
    assertEquals(IO.getFile("testdata/repo3/org.apache.felix.framework-4.0.2.jar").toURI(), findContentURI(context.getFramework()));
}
Also used : MockRegistry(test.lib.MockRegistry) Resource(org.osgi.resource.Resource) BndEditModel(aQute.bnd.build.model.BndEditModel)

Example 92 with Resource

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

the class BndrunResolveContextTest method testInputRequirementsAsMandatoryResource.

public static void testInputRequirementsAsMandatoryResource() {
    MockRegistry registry = new MockRegistry();
    registry.addPlugin(createRepo(IO.getFile("testdata/repo3.index.xml")));
    BndEditModel runModel = new BndEditModel();
    runModel.setRunFw("org.apache.felix.framework");
    Requirement req = new CapReqBuilder("osgi.identity").addDirective("filter", "(osgi.identity=org.apache.felix.gogo.command)").buildSyntheticRequirement();
    runModel.setRunRequires(Collections.singletonList(req));
    BndrunResolveContext context = new BndrunResolveContext(runModel, registry, log);
    context.init();
    assertEquals(IO.getFile("testdata/repo3/org.apache.felix.framework-4.0.2.jar").toURI(), findContentURI(context.getFramework()));
    Collection<Resource> mandRes = context.getMandatoryResources();
    assertEquals(1, mandRes.size());
    Resource resource = mandRes.iterator().next();
    assertNotNull(resource);
    IdentityCapability ic = ResourceUtils.getIdentityCapability(resource);
    assertNotNull(ic);
    assertEquals("<<INITIAL>>", ic.osgi_identity());
}
Also used : CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) Requirement(org.osgi.resource.Requirement) MockRegistry(test.lib.MockRegistry) Resource(org.osgi.resource.Resource) BndEditModel(aQute.bnd.build.model.BndEditModel) IdentityCapability(aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability)

Example 93 with Resource

use of org.osgi.resource.Resource 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 94 with Resource

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

the class GenericResolveContextResolveTest method testSimpleResolve.

/**
	 * Simple basic resolve. We use a small index with gogo + framework and then
	 * try to see if we can resolve the runtime from the shell requirement.
	 * 
	 * @throws Exception
	 */
public void testSimpleResolve() throws Exception {
    Repository repository = createRepo(IO.getFile("testdata/repo3.index.xml"));
    GenericResolveContext grc = new GenericResolveContext(logger);
    grc.setLevel(2);
    grc.addRepository(repository);
    grc.addFramework("org.apache.felix.framework", null);
    grc.addEE(EE.JavaSE_1_7);
    grc.addRequireBundle("org.apache.felix.gogo.shell", new VersionRange("[0,1]"));
    grc.done();
    Resolver resolver = new BndResolver(new ResolverLogger(4));
    Set<Resource> resources = resolver.resolve(grc).keySet();
    assertNotNull(getResource(resources, "org.apache.felix.gogo.runtime", "0.10"));
}
Also used : Repository(org.osgi.service.repository.Repository) Resolver(org.osgi.service.resolver.Resolver) Resource(org.osgi.resource.Resource) VersionRange(aQute.bnd.version.VersionRange)

Example 95 with Resource

use of org.osgi.resource.Resource 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

Resource (org.osgi.resource.Resource)201 Capability (org.osgi.resource.Capability)62 Requirement (org.osgi.resource.Requirement)62 ArrayList (java.util.ArrayList)57 List (java.util.List)39 HashMap (java.util.HashMap)32 File (java.io.File)27 Collection (java.util.Collection)24 Wire (org.osgi.resource.Wire)24 ResourceBuilder (aQute.bnd.osgi.resource.ResourceBuilder)23 Map (java.util.Map)22 CapReqBuilder (aQute.bnd.osgi.resource.CapReqBuilder)18 URI (java.net.URI)18 HashSet (java.util.HashSet)18 BndEditModel (aQute.bnd.build.model.BndEditModel)15 MockRegistry (test.lib.MockRegistry)15 Version (org.osgi.framework.Version)14 BundleRevision (org.osgi.framework.wiring.BundleRevision)14 Repository (org.osgi.service.repository.Repository)14 IdentityCapability (aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability)13