Search in sources :

Example 6 with Resolver

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

the class JpmRepoTest method testUnresolved.

public void testUnresolved() throws ResolutionException {
    Repository repo = ws.getPlugin(Repository.class);
    BndEditModel model = new BndEditModel();
    model.setRunFw("org.apache.felix.framework");
    List<Requirement> requires = new ArrayList<Requirement>();
    CapReqBuilder capReq = CapReqBuilder.createBundleRequirement("org.apache.felix.webconsole", "[4,5)");
    requires.add(capReq.buildSyntheticRequirement());
    Map<Requirement, Collection<Capability>> shell = repo.findProviders(requires);
    assertNotNull(shell);
    assertEquals(1, shell.size());
    model.setRunRequires(requires);
    BndrunResolveContext context = new BndrunResolveContext(model, ws, log);
    Resolver resolver = new BndResolver(new org.apache.felix.resolver.Logger(4));
    try {
        Map<Resource, List<Wire>> resolved = resolver.resolve(context);
        fail("Resolve did not fail");
    } catch (ResolutionException e) {
        assertEquals(1, e.getUnresolvedRequirements().size());
        ResolutionException augmented = ResolveProcess.augment(context, e);
        assertEquals(2, augmented.getUnresolvedRequirements().size());
    }
}
Also used : CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) BndResolver(biz.aQute.resolve.BndResolver) Resolver(org.osgi.service.resolver.Resolver) ArrayList(java.util.ArrayList) Resource(org.osgi.resource.Resource) ResolutionException(org.osgi.service.resolver.ResolutionException) Requirement(org.osgi.resource.Requirement) InfoRepository(aQute.bnd.service.repository.InfoRepository) Repository(org.osgi.service.repository.Repository) BndrunResolveContext(biz.aQute.resolve.BndrunResolveContext) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List) BndResolver(biz.aQute.resolve.BndResolver) BndEditModel(aQute.bnd.build.model.BndEditModel)

Example 7 with Resolver

use of org.osgi.service.resolver.Resolver 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 8 with Resolver

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

the class DebugReporter method resource.

private void resource(Resource r) {
    IdentityCapability id = ResourceUtils.getIdentityCapability(r);
    String resolveError = null;
    if (!context.isSystemResource(r) && level >= 3 && id != null)
        try {
            String v = id.version() == null ? null : id.version().toString();
            Requirement req = CapReqBuilder.createBundleRequirement(id.osgi_identity(), v).buildSyntheticRequirement();
            context.setInputRequirements(req);
            Resolver resolver = new BndResolver(new ResolverLogger(4));
            Map<Resource, List<Wire>> resolved = resolver.resolve(context);
        } catch (Exception e) {
            resolveError = e.toString();
        }
    String s = resolveError == null ? " " : "!";
    if (id == null)
        out.printf("%s %s%n", s, r);
    else
        out.printf("%s %-50s %-20s %s%n", s, id.osgi_identity(), noNull(id.version()), id.description(""));
    if (level >= 2) {
        for (Capability c : r.getCapabilities(null)) {
            capability("   ", c);
        }
        for (Requirement rq : r.getRequirements(null)) {
            requirement("  ", rq);
        }
    }
}
Also used : Requirement(org.osgi.resource.Requirement) Resolver(org.osgi.service.resolver.Resolver) IdentityCapability(aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability) Capability(org.osgi.resource.Capability) Wire(org.osgi.resource.Wire) HashMap(java.util.HashMap) Map(java.util.Map) IdentityCapability(aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability)

Example 9 with Resolver

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

the class JpmRepoTest method testSimpleResolve.

// public void testResolveProviderWithRunpath() throws Exception {
// try {
// Project provider = ws.getProject("provider");
// provider.build();
// assertTrue(provider.check());
//
// Project requirer = ws.getProject("requirer");
// requirer.build();
// assertTrue(requirer.check());
//
// BndEditModel model = new BndEditModel();
// model.setProject(requirer);
// BndrunResolveContext context = new BndrunResolveContext(model, ws, log);
//
// Resolver resolver = new ResolverImpl(new
// org.apache.felix.resolver.Logger(4), null);
//
// Map<Resource,List<Wire>> resolved = resolver.resolve(context);
// Set<Resource> resources = resolved.keySet();
// Resource resource = getResource(resources, "requirer", "0");
// assertNotNull(resource);
// }
// catch (ResolutionException e) {
// fail("Resolve failed " + e);
// }
// }
public void testSimpleResolve() {
    Repository repo = ws.getPlugin(Repository.class);
    BndEditModel model = new BndEditModel();
    model.setRunFw("org.apache.felix.framework");
    List<Requirement> requires = new ArrayList<Requirement>();
    CapReqBuilder capReq = CapReqBuilder.createBundleRequirement("org.apache.felix.gogo.shell", "[0,1)");
    requires.add(capReq.buildSyntheticRequirement());
    Map<Requirement, Collection<Capability>> shell = repo.findProviders(requires);
    assertNotNull(shell);
    assertEquals(1, shell.size());
    model.setRunRequires(requires);
    BndrunResolveContext context = new BndrunResolveContext(model, ws, log);
    Resolver resolver = new BndResolver(new org.apache.felix.resolver.Logger(4));
    try {
        Map<Resource, List<Wire>> resolved = resolver.resolve(context);
        Set<Resource> resources = resolved.keySet();
        Resource resource = getResource(resources, "org.apache.felix.gogo.runtime", "0.12");
        assertNotNull(resource);
    } catch (ResolutionException e) {
        fail("Resolve failed");
    }
}
Also used : CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) BndResolver(biz.aQute.resolve.BndResolver) Resolver(org.osgi.service.resolver.Resolver) ArrayList(java.util.ArrayList) Resource(org.osgi.resource.Resource) ResolutionException(org.osgi.service.resolver.ResolutionException) Requirement(org.osgi.resource.Requirement) InfoRepository(aQute.bnd.service.repository.InfoRepository) Repository(org.osgi.service.repository.Repository) BndrunResolveContext(biz.aQute.resolve.BndrunResolveContext) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List) BndResolver(biz.aQute.resolve.BndResolver) BndEditModel(aQute.bnd.build.model.BndEditModel)

Example 10 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)

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