Search in sources :

Example 1 with BndResolver

use of biz.aQute.resolve.BndResolver 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 2 with BndResolver

use of biz.aQute.resolve.BndResolver in project bnd by bndtools.

the class DistroCommandTest method testResolveAgainstDistro.

public void testResolveAgainstDistro() throws Exception {
    bnd bnd = new bnd();
    CommandLine cmdline = new CommandLine(null);
    List<String> remoteArgs = new ArrayList<>();
    RemoteOptions remoteOptions = cmdline.getOptions(RemoteOptions.class, remoteArgs);
    File distro = new File("generated/tmp/test.distro.jar");
    List<String> distroArgs = new ArrayList<>();
    distroArgs.add("-o");
    distroArgs.add(distro.getPath());
    distroArgs.add("test.distro");
    distroArgs.add("1.0.0");
    DistroOptions distroOptions = cmdline.getOptions(DistroOptions.class, distroArgs);
    new RemoteCommand(bnd, remoteOptions)._distro(distroOptions);
    assertTrue(distro.exists());
    ResolveProcess process = new ResolveProcess();
    ResolverLogger logger = new ResolverLogger();
    MockRegistry registry = new MockRegistry();
    Processor model = new Processor();
    model.setProperty("-distro", distro.getAbsolutePath() + ";version=file");
    model.setProperty("-runfw", "org.eclipse.osgi");
    model.setProperty("-runrequires", "osgi.wiring.package;filter:='(osgi.wiring.package=com.liferay.dynamic.data.mapping.taglib.servlet.taglib)'");
    Map<Resource, List<Wire>> requiredResources = process.resolveRequired(model, null, registry, new BndResolver(logger), Collections.<ResolutionCallback>emptyList(), logger);
    assertEquals(1, requiredResources.size());
}
Also used : Processor(aQute.bnd.osgi.Processor) ResolverLogger(biz.aQute.resolve.ResolverLogger) RemoteOptions(aQute.bnd.main.RemoteCommand.RemoteOptions) ArrayList(java.util.ArrayList) MockRegistry(aQute.bnd.main.testlib.MockRegistry) Resource(org.osgi.resource.Resource) CommandLine(aQute.lib.getopt.CommandLine) DistroOptions(aQute.bnd.main.RemoteCommand.DistroOptions) ResolveProcess(biz.aQute.resolve.ResolveProcess) ArrayList(java.util.ArrayList) List(java.util.List) BndResolver(biz.aQute.resolve.BndResolver) File(java.io.File)

Example 3 with BndResolver

use of biz.aQute.resolve.BndResolver 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 4 with BndResolver

use of biz.aQute.resolve.BndResolver in project bndtools by bndtools.

the class ResolveOperation method run.

@Override
public void run(IProgressMonitor monitor) {
    MultiStatus status = new MultiStatus(Plugin.PLUGIN_ID, 0, Messages.ResolveOperation_errorOverview, null);
    // Start a coordination
    BundleContext bc = Plugin.getDefault().getBundleContext();
    ServiceReference<Coordinator> coordSvcRef = bc.getServiceReference(Coordinator.class);
    Coordinator coordinator = coordSvcRef != null ? (Coordinator) bc.getService(coordSvcRef) : null;
    Coordination coordination = coordinator != null ? coordinator.begin(ResolveOperation.class.getName(), 0) : null;
    // Begin resolve
    ResolveProcess resolve = new ResolveProcess();
    ResolverLogger logger = new ResolverLogger();
    try {
        BndResolver bndResolver = new BndResolver(logger);
        ReporterLogService log = new ReporterLogService(model.getWorkspace());
        Map<Resource, List<Wire>> wirings = resolve.resolveRequired(model, model.getWorkspace(), bndResolver, callbacks, log);
        Map<Resource, List<Wire>> optionalResources = new HashMap<Resource, List<Wire>>(resolve.getOptionalResources().size());
        for (Resource optional : resolve.getOptionalResources()) {
            optionalResources.put(optional, new ArrayList<Wire>(resolve.getOptionalReasons(optional)));
        }
        result = new ResolutionResult(Outcome.Resolved, wirings, optionalResources, null, status, logger.getLog());
        if (coordination != null)
            coordination.end();
    } catch (ResolveCancelledException e) {
        result = new ResolutionResult(Outcome.Cancelled, null, null, null, status, logger.getLog());
        if (coordination != null)
            coordination.fail(e);
    } catch (ResolutionException e) {
        status.add(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, e.getLocalizedMessage(), e));
        result = new ResolutionResult(Outcome.Unresolved, null, null, e, status, logger.getLog());
        if (coordination != null)
            coordination.fail(e);
    } catch (Exception e) {
        status.add(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, "Exception during resolution.", e));
        result = new ResolutionResult(Outcome.Error, null, null, null, status, logger.getLog());
        if (coordination != null)
            coordination.fail(e);
    } finally {
        if (coordinator != null)
            bc.ungetService(coordSvcRef);
    }
}
Also used : ReporterLogService(aQute.bnd.deployer.repository.ReporterLogService) MultiStatus(org.eclipse.core.runtime.MultiStatus) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) Coordination(org.osgi.service.coordinator.Coordination) ResolverLogger(biz.aQute.resolve.ResolverLogger) HashMap(java.util.HashMap) Resource(org.osgi.resource.Resource) MultiStatus(org.eclipse.core.runtime.MultiStatus) Coordinator(org.osgi.service.coordinator.Coordinator) Wire(org.osgi.resource.Wire) ResolutionException(org.osgi.service.resolver.ResolutionException) ResolutionException(org.osgi.service.resolver.ResolutionException) ResolveProcess(biz.aQute.resolve.ResolveProcess) ArrayList(java.util.ArrayList) List(java.util.List) BndResolver(biz.aQute.resolve.BndResolver) BundleContext(org.osgi.framework.BundleContext)

Aggregations

BndResolver (biz.aQute.resolve.BndResolver)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Resource (org.osgi.resource.Resource)4 ResolutionException (org.osgi.service.resolver.ResolutionException)3 BndEditModel (aQute.bnd.build.model.BndEditModel)2 CapReqBuilder (aQute.bnd.osgi.resource.CapReqBuilder)2 InfoRepository (aQute.bnd.service.repository.InfoRepository)2 BndrunResolveContext (biz.aQute.resolve.BndrunResolveContext)2 ResolveProcess (biz.aQute.resolve.ResolveProcess)2 ResolverLogger (biz.aQute.resolve.ResolverLogger)2 Collection (java.util.Collection)2 Requirement (org.osgi.resource.Requirement)2 Repository (org.osgi.service.repository.Repository)2 Resolver (org.osgi.service.resolver.Resolver)2 ReporterLogService (aQute.bnd.deployer.repository.ReporterLogService)1 DistroOptions (aQute.bnd.main.RemoteCommand.DistroOptions)1 RemoteOptions (aQute.bnd.main.RemoteCommand.RemoteOptions)1 MockRegistry (aQute.bnd.main.testlib.MockRegistry)1 Processor (aQute.bnd.osgi.Processor)1