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;
}
}
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();
}
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));
}
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));
}
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);
}
Aggregations