use of org.eclipse.core.runtime.MultiStatus in project eclipse.platform.releng by eclipse.
the class AdvancedFixCopyrightAction method run.
/**
* @see IActionDelegate#run(IAction)
*/
@Override
public void run(IAction action) {
log = new HashMap<>();
console = new FixConsole();
ConsolePlugin.getDefault().getConsoleManager().addConsoles(new IConsole[] { console });
try {
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(IConsoleConstants.ID_CONSOLE_VIEW);
} catch (PartInitException e) {
// Don't fail if we can't show the console
RelEngPlugin.log(e);
}
final MessageConsoleStream stream = console.newMessageStream();
WorkspaceJob wJob = new // $NON-NLS-1$
WorkspaceJob(// $NON-NLS-1$
Messages.getString("AdvancedFixCopyrightAction.1")) {
@Override
public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
try {
long start = System.currentTimeMillis();
// $NON-NLS-1$
stream.println(Messages.getString("AdvancedFixCopyrightAction.2"));
IResource[] results = getSelectedResources();
stream.println(NLS.bind(Messages.getString("AdvancedFixCopyrightAction.3"), // $NON-NLS-1$
Integer.toString(results.length)));
// 'initializing' msg. //$NON-NLS-1$
monitor.subTask(Messages.getString("AdvancedFixCopyrightAction.22"));
// this generates ~5% overhead.
int totalFileCount = countFiles(results);
// $NON-NLS-1$
monitor.beginTask(Messages.getString("AdvancedFixCopyrightAction.4"), totalFileCount);
RepositoryProviderCopyrightAdapter adapter = createCopyrightAdapter(results);
if (adapter == null) {
if (!RelEngPlugin.getDefault().getPreferenceStore().getBoolean(RelEngCopyrightConstants.USE_DEFAULT_REVISION_YEAR_KEY)) {
// $NON-NLS-1$
throw new CoreException(new Status(IStatus.ERROR, RelEngPlugin.ID, 0, Messages.getString("AdvancedFixCopyrightAction.5"), null));
}
} else {
adapter.initialize(SubMonitor.convert(monitor, 100));
}
List<CoreException> exceptions = new ArrayList<>();
for (int i = 0; i < results.length; i++) {
IResource resource = results[i];
stream.println(NLS.bind(Messages.getString("AdvancedFixCopyrightAction.6"), // $NON-NLS-1$
resource.getName()));
try {
resource.accept(new FixCopyrightVisitor(adapter, monitor));
} catch (CoreException e1) {
exceptions.add(e1);
}
}
writeLogs();
displayLogs(stream);
// $NON-NLS-1$
stream.println(Messages.getString("AdvancedFixCopyrightAction.7"));
long end = System.currentTimeMillis();
stream.println(NLS.bind(Messages.getString("AdvancedFixCopyrightAction.8"), // $NON-NLS-1$
Long.toString(end - start)));
if (!exceptions.isEmpty()) {
// $NON-NLS-1$
stream.println(Messages.getString("AdvancedFixCopyrightAction.9"));
if (exceptions.size() == 1) {
throw exceptions.get(0);
} else {
List<Status> status = new ArrayList<>();
for (Iterator<CoreException> iterator = exceptions.iterator(); iterator.hasNext(); ) {
CoreException ce = iterator.next();
status.add(new Status(ce.getStatus().getSeverity(), ce.getStatus().getPlugin(), ce.getStatus().getCode(), ce.getStatus().getMessage(), ce));
}
throw new CoreException(new MultiStatus(RelEngPlugin.ID, 0, status.toArray(new IStatus[status.size()]), // $NON-NLS-1$
Messages.getString("AdvancedFixCopyrightAction.10"), null));
}
}
} finally {
monitor.done();
}
return Status.OK_STATUS;
}
private int countFiles(IResource[] results) {
int sum = 0;
for (IResource file : results) {
FileCountVisitor fileCountVisitor = new FileCountVisitor();
try {
file.accept(fileCountVisitor);
} catch (CoreException e) {
// This exception can be ignored.
// Here we are only counting files.
// It will be handled when files are actually
// proccessed.
}
sum += fileCountVisitor.getfileCount();
}
return sum;
}
};
wJob.setRule(ResourcesPlugin.getWorkspace().getRoot());
wJob.setUser(true);
wJob.schedule();
}
use of org.eclipse.core.runtime.MultiStatus in project eclipse-integration-commons by spring-projects.
the class ConfiguratorPreferencesPage method doInstall.
protected void doInstall(final ConfigurableExtension extension) {
// FIXME use directory where extension is installed
final File installDirectory = new File(userLocationText.getText());
if (!installDirectory.canWrite()) {
UiStatusHandler.logAndDisplay(new Status(IStatus.ERROR, Activator.PLUGIN_ID, NLS.bind("Installation failed. The directory ''{0}'' is not writeable.", userLocationText.getText())));
return;
}
try {
final IStatus[] status = new IStatus[1];
UiUtil.busyCursorWhile(new ICoreRunnable() {
public void run(IProgressMonitor monitor) throws CoreException {
status[0] = extension.install(installDirectory, monitor);
if (status[0].getSeverity() != IStatus.ERROR) {
IStatus configurationStatus = extension.configure(monitor);
if (status[0].getSeverity() != IStatus.OK) {
MultiStatus result = new MultiStatus(Activator.PLUGIN_ID, 0, NLS.bind("The installation of {0} generated warning. See error log for details.", extension.getLabel()), null);
result.add(status[0]);
result.add(configurationStatus);
status[0] = result;
} else {
status[0] = configurationStatus;
}
}
}
});
handleResult(extension, status);
doRefresh();
} catch (OperationCanceledException ignored) {
// cancelled
} catch (CoreException e) {
UiStatusHandler.logAndDisplay(e.getStatus());
}
}
use of org.eclipse.core.runtime.MultiStatus in project eclipse-integration-commons by spring-projects.
the class ExtensionsEditor method createPartControl.
/*
* (non-Javadoc)
*
* @see
* org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets
* .Composite)
*/
@Override
public void createPartControl(Composite parent) {
toolkit = new FormToolkit(parent.getDisplay());
form = toolkit.createScrolledForm(parent);
Composite body = form.getBody();
body.setLayout(new GridLayout(5, false));
discoveryViewer = new DashboardDiscoveryViewer(getSite(), this);
initialize(discoveryViewer);
discoveryViewer.setDirectoryUrl(ResourceProvider.getUrl(RESOURCE_DISCOVERY_DIRECTORY).replace("%VERSION%", IdeUiUtils.getShortVersion()));
discoveryViewer.setShowConnectorDescriptorKindFilter(false);
discoveryViewer.createControl(body);
adaptRecursively(discoveryViewer.getControl(), toolkit);
GridDataFactory.fillDefaults().span(5, 1).grab(true, true).applyTo(discoveryViewer.getControl());
findUpdatesButton = toolkit.createButton(body, "&Find Updates", SWT.NONE);
findUpdatesButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
IHandlerService handlerService = (IHandlerService) getSite().getService(IHandlerService.class);
try {
handlerService.executeCommand("org.eclipse.equinox.p2.ui.sdk.update", new Event());
} catch (Exception e) {
StatusManager.getManager().handle(new Status(IStatus.ERROR, IdeUiPlugin.PLUGIN_ID, "Find updates failed with an unexpected error.", e), StatusManager.SHOW | StatusManager.LOG);
}
}
});
Hyperlink configureLink = toolkit.createHyperlink(body, "Configure Extensions...", SWT.NONE);
configureLink.addHyperlinkListener(new HyperlinkAdapter() {
@Override
public void linkActivated(HyperlinkEvent event) {
PreferenceDialog dialog = PreferencesUtil.createPreferenceDialogOn(getSite().getShell(), ID_PREFERENCE_PAGE, new String[] { ID_PREFERENCE_PAGE }, null);
dialog.open();
}
});
progressMonitorPart = new ProgressMonitorPart(body, null);
monitor.attach(progressMonitorPart);
progressMonitorPart.addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent e) {
monitor.setCanceled(true);
monitor.detach(progressMonitorPart);
}
});
adaptRecursively(progressMonitorPart, toolkit);
GridDataFactory.fillDefaults().grab(true, false).applyTo(progressMonitorPart);
// Button refreshButton = toolkit.createButton(body, "Refresh",
// SWT.NONE);
// refreshButton.addSelectionListener(new SelectionAdapter() {
// @Override
// public void widgetSelected(SelectionEvent e) {
// pane.updateDiscovery();
// }
// });
cancelButton = toolkit.createButton(body, "&Cancel", SWT.NONE);
cancelButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
cancelButton.setEnabled(false);
progressMonitorPart.setCanceled(true);
}
});
installButton = toolkit.createButton(body, "&Install", SWT.NONE);
installButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
// check for conflicts
List<ConnectorDescriptor> selection = discoveryViewer.getInstallableConnectors();
IStatus conflictStatus = new MultiStatus(IdeUiPlugin.PLUGIN_ID, -1, new IStatus[] { checkForConflicts(SVN_FEATURES, " Please select only one SVN team provider.", selection), checkForConflicts(M2E_EXTENSION_IDS, " Please select only one m2e version to install.", selection) }, "Could not perform install due to conflicts.", null);
if (!conflictStatus.isOK()) {
StatusManager.getManager().handle(conflictStatus, StatusManager.SHOW | StatusManager.BLOCK);
return;
}
// now, if m2e is going to be installed, ensure that all other
// versions of m2e are uninstalled first.
Set<String> featuresToUninstall = chooseUnwantedFeatures(selection);
if (!featuresToUninstall.isEmpty()) {
IStatus uninstallResult = uninstallFeatures(featuresToUninstall);
if (!uninstallResult.isOK()) {
if (uninstallResult.getSeverity() != IStatus.CANCEL) {
StatusManager.getManager().handle(uninstallResult, StatusManager.SHOW | StatusManager.LOG | StatusManager.BLOCK);
}
return;
}
}
DiscoveryUi.install(discoveryViewer.getInstallableConnectors(), ExtensionsEditor.this);
}
private IStatus uninstallFeatures(final Set<String> featuresToUninstall) {
String allInstalled = findFeaturesToUninstall(featuresToUninstall, discoveryViewer.getInstalledFeatures());
if (allInstalled.length() == 0) {
return Status.OK_STATUS;
}
boolean res = MessageDialog.openQuestion(getEditorSite().getShell(), "Perform uninstall?", "In order to switch versions of m2eclipse, the following features will be uninstalled:\n" + allInstalled + "Do you want to continue?");
if (!res) {
return Status.CANCEL_STATUS;
}
// uninstall previous Maven tooling
AbstractInstallJob job = DiscoveryUi.createInstallJob();
try {
return job.uninstall(new UninstallRequest() {
/**
* Uninstall all features that are somehow related to
* m2eclipse
*/
@Override
public boolean select(@SuppressWarnings("rawtypes") InstalledItem item) {
String featureId = item.getId();
return isRelatedToM2e(featuresToUninstall, featureId);
}
}, new NullProgressMonitor());
} catch (Exception e) {
return new Status(IStatus.ERROR, IdeUiPlugin.PLUGIN_ID, NLS.bind("Could not uninstall features:\n{0},\n try uninstalling manually.", featuresToUninstall), e);
}
}
private String findFeaturesToUninstall(Set<String> featuresToUninstall, Set<String> installedFeatures) {
StringBuilder sb = new StringBuilder();
for (String featureId : installedFeatures) {
if (isRelatedToM2e(featuresToUninstall, featureId)) {
if (featureId.endsWith(".feature.group")) {
featureId = featureId.substring(0, featureId.length() - ".feature.group".length());
}
sb.append(" " + featureId + "\n");
}
}
return sb.toString();
}
private Set<String> chooseUnwantedFeatures(List<ConnectorDescriptor> selection) {
boolean uninstallOld = false;
boolean uninstallNew = false;
for (ConnectorDescriptor feature : selection) {
// first and vice versa
if (feature.getId().equals(NEW_M2E_EXTENSION_ID)) {
uninstallOld = true;
} else if (feature.getId().equals(OLD_M2E_EXTENSION_ID)) {
uninstallNew = true;
}
}
Set<String> maybeUninstall;
if (uninstallOld) {
maybeUninstall = OLD_M2E_FEATURES;
} else if (uninstallNew) {
maybeUninstall = NEW_M2E_FEATURES;
} else {
maybeUninstall = Collections.emptySet();
}
Set<String> installedFeatures = ExtensionsEditor.this.discoveryViewer.getInstalledFeatures();
Set<String> definitelyUninstall = new HashSet<String>();
for (String feature : maybeUninstall) {
if (installedFeatures.contains(feature)) {
definitelyUninstall.add(feature);
}
}
if (definitelyUninstall.size() > 0) {
IdeUiPlugin.log(new Status(IStatus.INFO, IdeUiPlugin.PLUGIN_ID, "To make way for a new version of m2eclipse, we will uninstall these features: " + definitelyUninstall));
}
return definitelyUninstall;
}
/**
* This method checks for conflicts with requested installs. If a
* conflict is found, this method will pop up a dialog explaining
* the conflict and it will return true.
*
* @param featuresToCheck set of features of which only one can be
* installed at once.
* @param message message to add if there is an error
* @param selection
*
* @return true iff there is a conflict.
*/
public IStatus checkForConflicts(Set<String> featuresToCheck, String prependedMessage, List<ConnectorDescriptor> selection) {
StringBuilder message = new StringBuilder();
List<ConnectorDescriptor> conflicting = new ArrayList<ConnectorDescriptor>();
for (ConnectorDescriptor descriptor : selection) {
if (featuresToCheck.contains(descriptor.getId())) {
conflicting.add(descriptor);
if (message.length() > 0) {
message.append(", ");
}
message.append(descriptor.getName());
}
}
if (conflicting.size() > 1) {
return new Status(IStatus.WARNING, IdeUiPlugin.PLUGIN_ID, NLS.bind("The following extensions can not be installed at the same time: {0}.", message.toString()));
} else {
return Status.OK_STATUS;
}
}
});
Display.getCurrent().asyncExec(new Runnable() {
public void run() {
if (form != null && !form.isDisposed()) {
discoveryViewer.updateDiscovery();
}
}
});
discoveryViewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
installButton.setEnabled(discoveryViewer.isComplete());
}
});
}
use of org.eclipse.core.runtime.MultiStatus in project eclipse-integration-commons by spring-projects.
the class TemplateDownloader method downloadTemplate.
public IStatus downloadTemplate(IProgressMonitor monitor) {
MultiStatus result = new MultiStatus(ContentPlugin.PLUGIN_ID, 0, NLS.bind("Download of ''{0}'' (''{1}'') failed", rootItem.getName(), rootItem.getId()), null);
SubMonitor progress = SubMonitor.convert(monitor, 20);
ContentManager manager = ContentPlugin.getDefault().getManager();
try {
List<ContentItem> dependencies = manager.getDependencies(rootItem);
for (ContentItem item : dependencies) {
String url = item.getRemoteDescriptor().getUrl();
File baseDirectory = manager.getInstallDirectory();
File archiveFile = new File(baseDirectory, item.getPathFromRemoteDescriptor() + ContentManager.ARCHIVE_EXTENSION);
File directory = new File(baseDirectory, item.getPathFromRemoteDescriptor());
startCountdownTimer(monitor);
IStatus status = HttpUtil.download(url, archiveFile, directory, progress);
stopCountdownTimer();
result.add(status);
}
// walk the file system to see if the file did get downloaded
manager.refresh(progress, false);
} catch (OperationCanceledException e) {
if (getTimerStatus().isOK()) {
throw e;
} else {
return new Status(IStatus.ERROR, ContentPlugin.PLUGIN_ID, 0, NLS.bind("Download ''{0}'' (''{1}'') timed out", rootItem.getName(), rootItem.getId()), e);
}
} catch (CoreException e) {
return new Status(IStatus.ERROR, ContentPlugin.PLUGIN_ID, 0, NLS.bind("Failed to determine dependencies of ''{0}'' (''{1}'')", rootItem.getName(), rootItem.getId()), e);
} finally {
progress.done();
result.add(getTimerStatus());
}
return result;
}
use of org.eclipse.core.runtime.MultiStatus in project eclipse-integration-commons by spring-projects.
the class LegacyProjectConverter method convert.
public IStatus convert(IProgressMonitor monitor) {
if (monitor == null) {
monitor = new NullProgressMonitor();
}
SubMonitor sub = SubMonitor.convert(monitor, selectedLegacyProjects.length);
IStatus[] statuses = new IStatus[selectedLegacyProjects.length];
int i = 0;
for (IProject project : selectedLegacyProjects) {
if (project.isAccessible()) {
// $NON-NLS-1$
sub.subTask("Converting " + project.getName());
if (sub.isCanceled()) {
throw new OperationCanceledException();
}
statuses[i++] = convert(project, monitor);
} else {
// project was closed before job started.
statuses[i++] = Status.OK_STATUS;
}
sub.worked(1);
}
// $NON-NLS-1$
return new MultiStatus(FrameworkCoreActivator.PLUGIN_ID, 0, statuses, "Result of converting legacy maven projects", null);
}
Aggregations