Search in sources :

Example 16 with ResolutionException

use of org.osgi.service.resolver.ResolutionException 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)

Example 17 with ResolutionException

use of org.osgi.service.resolver.ResolutionException in project bndtools by bndtools.

the class ResolutionFailurePanel method setInput.

//
// TODO pkr: To Neil. I think this is where we need to change
//
public void setInput(ResolutionResult resolutionResult) {
    if (composite == null)
        throw new IllegalStateException("Control not created");
    else if (composite.isDisposed())
        throw new IllegalStateException("Control already disposed");
    ResolutionException resolutionException = resolutionResult.getResolutionException();
    Collection<Requirement> unresolved = resolutionException != null ? resolutionException.getUnresolvedRequirements() : Collections.<Requirement>emptyList();
    if (resolutionException != null && resolutionException.getUnresolvedRequirements() != null && !resolutionException.getUnresolvedRequirements().isEmpty()) {
        //
        // In this case I think we need to close the upper sash (right name?) with the exception
        // and only show the bottom one (the resolution result. The previous exception trace was
        // kind of silly
        //
        String diagnostic = formatFailureStatus(resolutionResult.getStatus(), false, "").replaceAll(":", ":\n  ");
        processingErrorsText.setText(diagnostic);
        sectUnresolved.setExpanded(true);
    } else {
        processingErrorsText.setText(formatFailureStatus(resolutionResult.getStatus(), true, ""));
    }
    //
    // This might be a bit more fundamental. First,
    // the URL to search on JPM can be found on {@link RequirementLabelProvider.java#requirementToUrl(Requirement)}.
    // However, we have an alternative option. The JPM Repo implements SearchableRepository which
    // has a findRequirement(Requirement,boolean) method. This would allow us to click on a requirement
    // and show a list of resources as a consequence, and allow people to add it to the repository.
    //
    unresolvedViewer.setInput(unresolved);
    unresolvedViewer.expandToLevel(2);
}
Also used : ResolutionException(org.osgi.service.resolver.ResolutionException) Requirement(org.osgi.resource.Requirement)

Example 18 with ResolutionException

use of org.osgi.service.resolver.ResolutionException in project ddf by codice.

the class ProfileInstallCommandTest method testExtraProfileInvalidFeatureUninstall.

@Test(expected = ResolutionException.class)
public void testExtraProfileInvalidFeatureUninstall() throws Exception {
    profileInstallCommand.profileName = "invalidFeatureUninstall";
    doThrow(new ResolutionException("")).when(featuresService).uninstallFeature("badFeature", "0.0.0", NO_AUTO_REFRESH);
    profileInstallCommand.doExecute(applicationService, featuresService, bundleService);
    verify(featuresService, times(2)).uninstallFeature(anyString(), eq(NO_AUTO_REFRESH));
}
Also used : ResolutionException(org.osgi.service.resolver.ResolutionException) Test(org.junit.Test)

Example 19 with ResolutionException

use of org.osgi.service.resolver.ResolutionException in project ddf by codice.

the class ProfileInstallCommandTest method testExtraProfileInvalidFeatureInstall.

@Test(expected = ResolutionException.class)
public void testExtraProfileInvalidFeatureInstall() throws Exception {
    profileInstallCommand.profileName = "invalidFeatureInstall";
    doThrow(new ResolutionException("")).when(featuresService).installFeature("badFeature", NO_AUTO_REFRESH);
    profileInstallCommand.doExecute(applicationService, featuresService, bundleService);
    verify(featuresService, times(2)).installFeature(anyString(), eq(NO_AUTO_REFRESH));
}
Also used : ResolutionException(org.osgi.service.resolver.ResolutionException) Test(org.junit.Test)

Aggregations

ResolutionException (org.osgi.service.resolver.ResolutionException)19 List (java.util.List)10 Resource (org.osgi.resource.Resource)10 ArrayList (java.util.ArrayList)9 Requirement (org.osgi.resource.Requirement)9 File (java.io.File)6 Resolver (org.osgi.service.resolver.Resolver)5 Workspace (aQute.bnd.build.Workspace)4 BndEditModel (aQute.bnd.build.model.BndEditModel)4 Collection (java.util.Collection)4 CapReqBuilder (aQute.bnd.osgi.resource.CapReqBuilder)3 RepositoryPlugin (aQute.bnd.service.RepositoryPlugin)3 BndResolver (biz.aQute.resolve.BndResolver)3 Bndrun (biz.aQute.resolve.Bndrun)3 HashMap (java.util.HashMap)3 LinkedHashSet (java.util.LinkedHashSet)3 Test (org.junit.Test)3 Wire (org.osgi.resource.Wire)3 Repository (org.osgi.service.repository.Repository)3 Processor (aQute.bnd.osgi.Processor)2