Search in sources :

Example 11 with Resolver

use of org.osgi.service.resolver.Resolver in project aries by apache.

the class DependencyCalculator method calculateDependencies.

public List<Requirement> calculateDependencies() throws ResolutionException {
    ArrayList<Requirement> result = new ArrayList<Requirement>();
    Resolver resolver = Activator.getInstance().getResolver();
    Map<Resource, List<Wire>> resolution = resolver.resolve(context);
    for (List<Wire> wires : resolution.values()) for (Wire wire : wires) if (wire.getCapability() instanceof MissingCapability)
        result.add(wire.getRequirement());
    result.trimToSize();
    return result;
}
Also used : Requirement(org.osgi.resource.Requirement) Resolver(org.osgi.service.resolver.Resolver) ArrayList(java.util.ArrayList) Resource(org.osgi.resource.Resource) ArrayList(java.util.ArrayList) List(java.util.List) Wire(org.osgi.resource.Wire)

Example 12 with Resolver

use of org.osgi.service.resolver.Resolver in project bnd by bndtools.

the class BndrunResolveContextTest method testResolveProvidedCapabilitiesWithDistro.

public static void testResolveProvidedCapabilitiesWithDistro() throws Exception {
    MockRegistry registry = new MockRegistry();
    registry.addPlugin(createRepo(IO.getFile("testdata/repo3.index.xml")));
    BndEditModel model = new BndEditModel();
    model.genericSet("-runprovidedcapabilities", "osgi.service;objectClass=foo.bar.FooBarService;effective:=active");
    model.setDistro(Arrays.asList("testdata/distro.jar;version=file"));
    List<Requirement> requires = new ArrayList<Requirement>();
    List<Capability> caps = CapReqBuilder.getCapabilitiesFrom(new Parameters("osgi.service;objectClass=foo.bar.FooBarService;effective:=active"));
    Requirement req = CapReqBuilder.createRequirementFromCapability(caps.get(0)).buildSyntheticRequirement();
    requires.add(req);
    model.setRunRequires(requires);
    BndrunResolveContext context = new BndrunResolveContext(model, registry, log);
    context.setLevel(0);
    context.init();
    Resolver resolver = new BndResolver(new ResolverLogger(4));
    resolver.resolve(context);
}
Also used : Requirement(org.osgi.resource.Requirement) Parameters(aQute.bnd.header.Parameters) Capability(org.osgi.resource.Capability) IdentityCapability(aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability) Resolver(org.osgi.service.resolver.Resolver) MockRegistry(test.lib.MockRegistry) ArrayList(java.util.ArrayList) BndEditModel(aQute.bnd.build.model.BndEditModel)

Example 13 with Resolver

use of org.osgi.service.resolver.Resolver in project bnd by bndtools.

the class ResolveTest method testResolveWithDistro.

/**
	 * Test if we can resolve with a distro
	 * 
	 * @throws ResolutionException
	 */
public void testResolveWithDistro() throws ResolutionException {
    MockRegistry registry = new MockRegistry();
    registry.addPlugin(createRepo(IO.getFile("testdata/repo3.index.xml")));
    BndEditModel model = new BndEditModel();
    model.setDistro(Arrays.asList("testdata/distro.jar;version=file"));
    List<Requirement> requires = new ArrayList<Requirement>();
    CapReqBuilder capReq = CapReqBuilder.createBundleRequirement("org.apache.felix.gogo.shell", "[0,1)");
    requires.add(capReq.buildSyntheticRequirement());
    model.setRunRequires(requires);
    BndrunResolveContext context = new BndrunResolveContext(model, registry, log);
    context.setLevel(0);
    context.init();
    Resolver resolver = new BndResolver(new ResolverLogger(4));
    Map<Resource, List<Wire>> resolved = resolver.resolve(context);
    Set<Resource> resources = resolved.keySet();
    Resource shell = getResource(resources, "org.apache.felix.gogo.shell", "0.10.0");
    assertNotNull(shell);
}
Also used : CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) Resolver(org.osgi.service.resolver.Resolver) MockRegistry(test.lib.MockRegistry) ArrayList(java.util.ArrayList) Resource(org.osgi.resource.Resource) Requirement(org.osgi.resource.Requirement) ArrayList(java.util.ArrayList) List(java.util.List) BndEditModel(aQute.bnd.build.model.BndEditModel)

Example 14 with Resolver

use of org.osgi.service.resolver.Resolver in project bnd by bndtools.

the class ResolveTest method testMinimalSetup.

/**
	 * Test minimal setup
	 * 
	 * @throws URISyntaxException
	 * @throws MalformedURLException
	 */
public void testMinimalSetup() throws MalformedURLException, URISyntaxException {
    File index = IO.getFile("testdata/repo3.index.xml");
    FixedIndexedRepo fir = new FixedIndexedRepo();
    fir.setLocations(index.toURI().toString());
    Processor model = new Processor();
    model.setProperty("-runfw", "org.apache.felix.framework");
    model.setProperty("-runrequires", "osgi.identity;filter:='(osgi.identity=org.apache.felix.gogo.shell)'");
    BndrunResolveContext context = new BndrunResolveContext(model, null, model, log);
    context.setLevel(0);
    context.addRepository(fir);
    context.init();
    Resolver resolver = new BndResolver(new ResolverLogger(4));
    try {
        Map<Resource, List<Wire>> resolved = resolver.resolve(context);
        Set<Resource> resources = resolved.keySet();
        Resource shell = getResource(resources, "org.apache.felix.gogo.shell", "0.10.0");
        assertNotNull(shell);
    } catch (ResolutionException e) {
        e.printStackTrace();
        fail("Resolve failed");
    }
}
Also used : ResolutionException(org.osgi.service.resolver.ResolutionException) Processor(aQute.bnd.osgi.Processor) Resolver(org.osgi.service.resolver.Resolver) Resource(org.osgi.resource.Resource) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File) FixedIndexedRepo(aQute.bnd.deployer.repository.FixedIndexedRepo)

Example 15 with Resolver

use of org.osgi.service.resolver.Resolver in project bnd by bndtools.

the class ResolveTest method assertAugmentResolve.

private static void assertAugmentResolve(String augment, String require, String effective) throws Exception {
    MockRegistry registry = new MockRegistry();
    registry.addPlugin(createRepo(IO.getFile("testdata/repo3.index.xml")));
    Processor model = new Processor();
    model.setRunfw("org.apache.felix.framework");
    model.setProperty("-augment", augment);
    model.setRunRequires(require);
    if (effective != null)
        model.setProperty("-resolve.effective", effective);
    BndrunResolveContext context = new BndrunResolveContext(model, null, registry, log);
    Resolver resolver = new BndResolver(new ResolverLogger(4));
    Map<Resource, List<Wire>> resolved = resolver.resolve(context);
    Set<Resource> resources = resolved.keySet();
    Resource resource = getResource(resources, "org.apache.felix.gogo.runtime", "0.10");
    assertNotNull(resource);
}
Also used : Processor(aQute.bnd.osgi.Processor) Resolver(org.osgi.service.resolver.Resolver) MockRegistry(test.lib.MockRegistry) Resource(org.osgi.resource.Resource) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

Resolver (org.osgi.service.resolver.Resolver)16 ArrayList (java.util.ArrayList)12 Resource (org.osgi.resource.Resource)12 Requirement (org.osgi.resource.Requirement)11 List (java.util.List)10 Repository (org.osgi.service.repository.Repository)7 BndEditModel (aQute.bnd.build.model.BndEditModel)6 MockRegistry (test.lib.MockRegistry)6 CapReqBuilder (aQute.bnd.osgi.resource.CapReqBuilder)5 Capability (org.osgi.resource.Capability)5 ResolutionException (org.osgi.service.resolver.ResolutionException)5 Collection (java.util.Collection)4 Processor (aQute.bnd.osgi.Processor)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Wire (org.osgi.resource.Wire)3 Parameters (aQute.bnd.header.Parameters)2 IdentityCapability (aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability)2 InfoRepository (aQute.bnd.service.repository.InfoRepository)2 BndResolver (biz.aQute.resolve.BndResolver)2