Search in sources :

Example 26 with ResolutionException

use of org.osgi.service.resolver.ResolutionException in project rt.equinox.framework by eclipse.

the class Module method start.

/**
 * Starts this module
 * @param options the options for starting
 * @throws BundleException if an errors occurs while starting
 */
public void start(StartOptions... options) throws BundleException {
    revisions.getContainer().checkAdminPermission(getBundle(), AdminPermission.EXECUTE);
    if (options == null) {
        options = new StartOptions[0];
    }
    ModuleEvent event;
    if (StartOptions.LAZY_TRIGGER.isContained(options)) {
        setTrigger();
        if (stateChangeLock.getHoldCount() > 0 && stateTransitionEvents.contains(ModuleEvent.STARTED)) {
            // nothing to do here; the current thread is activating the bundle.
            return;
        }
    }
    BundleException startError = null;
    boolean lockedStarted = false;
    // Indicate we are in the middle of a start.
    // This must be incremented before we acquire the STARTED lock the first time.
    inStart.incrementAndGet();
    try {
        lockStateChange(ModuleEvent.STARTED);
        lockedStarted = true;
        checkValid();
        if (StartOptions.TRANSIENT_IF_AUTO_START.isContained(options) && !settings.contains(Settings.AUTO_START)) {
            // Do nothing; this is a request to start only if the module is set for auto start
            return;
        }
        checkFragment();
        persistStartOptions(options);
        if (getStartLevel() > getRevisions().getContainer().getStartLevel()) {
            if (StartOptions.TRANSIENT.isContained(options)) {
                // it is an error to attempt to transient start a bundle without its start level met
                throw new BundleException(Msg.Module_Transient_StartError, BundleException.START_TRANSIENT_ERROR);
            }
            // Do nothing; start level is not met
            return;
        }
        if (State.ACTIVE.equals(getState()))
            return;
        if (getState().equals(State.INSTALLED)) {
            ResolutionReport report;
            // must unlock to avoid out of order locks when multiple unresolved
            // bundles are started at the same time from different threads
            unlockStateChange(ModuleEvent.STARTED);
            lockedStarted = false;
            try {
                report = getRevisions().getContainer().resolve(Arrays.asList(this), true);
            } finally {
                lockStateChange(ModuleEvent.STARTED);
                lockedStarted = true;
            }
            // need to check valid again in case someone uninstalled the bundle
            checkValid();
            ResolutionException e = report.getResolutionException();
            if (e != null) {
                if (e.getCause() instanceof BundleException) {
                    throw (BundleException) e.getCause();
                }
            }
            if (State.ACTIVE.equals(getState()))
                return;
            if (getState().equals(State.INSTALLED)) {
                String reportMessage = report.getResolutionReportMessage(getCurrentRevision());
                throw new BundleException(Msg.Module_ResolveError + reportMessage, BundleException.RESOLVE_ERROR);
            }
        }
        try {
            event = doStart(options);
        } catch (BundleException e) {
            // must return state to resolved
            setState(State.RESOLVED);
            startError = e;
            // must always publish the STOPPED event on error
            event = ModuleEvent.STOPPED;
        }
    } finally {
        if (lockedStarted) {
            unlockStateChange(ModuleEvent.STARTED);
        }
        inStart.decrementAndGet();
    }
    if (event != null) {
        if (!EnumSet.of(ModuleEvent.STARTED, ModuleEvent.LAZY_ACTIVATION, ModuleEvent.STOPPED).contains(event))
            // $NON-NLS-1$
            throw new IllegalStateException("Wrong event type: " + event);
        publishEvent(event);
    }
    if (startError != null) {
        throw startError;
    }
}
Also used : ResolutionException(org.osgi.service.resolver.ResolutionException) ModuleEvent(org.eclipse.osgi.container.ModuleContainerAdaptor.ModuleEvent) ResolutionReport(org.eclipse.osgi.report.resolution.ResolutionReport)

Example 27 with ResolutionException

use of org.osgi.service.resolver.ResolutionException in project intellij-plugins by JetBrains.

the class ResolveAction method actionPerformed.

@Override
public void actionPerformed(@NotNull AnActionEvent event) {
    VirtualFile virtualFile = event.getData(CommonDataKeys.VIRTUAL_FILE);
    Project project = event.getProject();
    if (virtualFile == null || project == null)
        return;
    Document document = FileDocumentManager.getInstance().getDocument(virtualFile);
    if (document == null)
        return;
    FileDocumentManager.getInstance().saveAllDocuments();
    new Task.Backgroundable(project, message("bnd.resolve.requirements.title"), true) {

        private Map<Resource, List<Wire>> resolveResult;

        private String updatedText;

        @Override
        public void run(@NotNull ProgressIndicator indicator) {
            indicator.setIndeterminate(true);
            File file = new File(virtualFile.getPath());
            try (Workspace workspace = Workspace.findWorkspace(file);
                Run run = Run.createRun(workspace, file);
                ProjectResolver projectResolver = new ProjectResolver(run)) {
                resolveResult = projectResolver.resolve();
                List<VersionedClause> versionedClauses = projectResolver.getRunBundles().stream().map(c -> {
                    Attrs attrs = new Attrs();
                    attrs.put(Constants.VERSION_ATTRIBUTE, c.getVersion());
                    return new VersionedClause(c.getBundleSymbolicName(), attrs);
                }).sorted(Comparator.comparing(VersionedClause::getName)).collect(Collectors.toList());
                BndEditModel editModel = new BndEditModel();
                IDocument bndDocument = new aQute.bnd.properties.Document(document.getImmutableCharSequence().toString());
                editModel.loadFrom(bndDocument);
                editModel.setRunBundles(versionedClauses);
                editModel.saveChangesTo(bndDocument);
                updatedText = bndDocument.get();
            } catch (ProcessCanceledException e) {
                throw e;
            } catch (Exception e) {
                throw new WrappingException(e);
            }
            indicator.checkCanceled();
        }

        @Override
        public void onSuccess() {
            if (new ResolutionSucceedDialog(project, resolveResult).showAndGet() && FileModificationService.getInstance().prepareVirtualFilesForWrite(project, Collections.singleton(virtualFile))) {
                writeCommandAction(project).withName("Bndrun Resolve").run(() -> document.setText(updatedText));
            }
        }

        @Override
        public void onThrowable(@NotNull Throwable t) {
            Throwable cause = t instanceof WrappingException ? t.getCause() : t;
            LOG.warn("Resolution failed", cause);
            if (cause instanceof ResolutionException) {
                new ResolutionFailedDialog(project, (ResolutionException) cause).show();
            } else {
                OsmorcBundle.notification(message("bnd.resolve.failed.title"), cause.getMessage(), NotificationType.ERROR).notify(project);
            }
        }
    }.queue();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) WriteCommandAction.writeCommandAction(com.intellij.openapi.command.WriteCommandAction.writeCommandAction) Constants(aQute.bnd.osgi.Constants) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Document(com.intellij.openapi.editor.Document) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) Task(com.intellij.openapi.progress.Task) Workspace(aQute.bnd.build.Workspace) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) Map(java.util.Map) Project(com.intellij.openapi.project.Project) CommonDataKeys(com.intellij.openapi.actionSystem.CommonDataKeys) Logger(com.intellij.openapi.diagnostic.Logger) OsmorcBundle.message(org.osmorc.i18n.OsmorcBundle.message) BndEditModel(aQute.bnd.build.model.BndEditModel) OsmorcBundle(org.osmorc.i18n.OsmorcBundle) ProjectResolver(biz.aQute.resolve.ProjectResolver) FileModificationService(com.intellij.codeInsight.FileModificationService) Resource(org.osgi.resource.Resource) AnAction(com.intellij.openapi.actionSystem.AnAction) FileDocumentManager(com.intellij.openapi.fileEditor.FileDocumentManager) Run(aQute.bnd.build.Run) Collectors(java.util.stream.Collectors) File(java.io.File) NotificationType(com.intellij.notification.NotificationType) BndFileType(org.jetbrains.osgi.bnd.BndFileType) Nullable(org.jetbrains.annotations.Nullable) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) List(java.util.List) IDocument(aQute.bnd.properties.IDocument) VersionedClause(aQute.bnd.build.model.clauses.VersionedClause) Attrs(aQute.bnd.header.Attrs) Wire(org.osgi.resource.Wire) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) ResolutionException(org.osgi.service.resolver.ResolutionException) NotNull(org.jetbrains.annotations.NotNull) Comparator(java.util.Comparator) Collections(java.util.Collections) javax.swing(javax.swing) Task(com.intellij.openapi.progress.Task) VersionedClause(aQute.bnd.build.model.clauses.VersionedClause) ProjectResolver(biz.aQute.resolve.ProjectResolver) Attrs(aQute.bnd.header.Attrs) Document(com.intellij.openapi.editor.Document) IDocument(aQute.bnd.properties.IDocument) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) List(java.util.List) BndEditModel(aQute.bnd.build.model.BndEditModel) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) Resource(org.osgi.resource.Resource) Run(aQute.bnd.build.Run) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) ResolutionException(org.osgi.service.resolver.ResolutionException) ResolutionException(org.osgi.service.resolver.ResolutionException) Project(com.intellij.openapi.project.Project) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) IDocument(aQute.bnd.properties.IDocument) Workspace(aQute.bnd.build.Workspace)

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

Example 29 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 30 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 = ResolveProcess.format(resolutionException, false);
        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)

Aggregations

ResolutionException (org.osgi.service.resolver.ResolutionException)32 List (java.util.List)17 ArrayList (java.util.ArrayList)16 Resource (org.osgi.resource.Resource)16 Requirement (org.osgi.resource.Requirement)14 HashMap (java.util.HashMap)8 Resolver (org.osgi.service.resolver.Resolver)8 Capability (org.osgi.resource.Capability)7 File (java.io.File)6 BundleException (org.osgi.framework.BundleException)6 IOException (java.io.IOException)5 Test (org.junit.Test)5 BundleRevision (org.osgi.framework.wiring.BundleRevision)5 Workspace (aQute.bnd.build.Workspace)4 BndEditModel (aQute.bnd.build.model.BndEditModel)4 Collection (java.util.Collection)4 LinkedHashSet (java.util.LinkedHashSet)4 Logger (org.apache.felix.resolver.Logger)4 ResolverImpl (org.apache.felix.resolver.ResolverImpl)4 BundleCapability (org.apache.felix.resolver.test.util.BundleCapability)4