Skip to content

Commit

Permalink
[all] Display error message when the code mining feature crashed.
Browse files Browse the repository at this point in the history
The code mining feature is also disabled in the case of an error
occurred when running it.

close #1041

Signed-off-by: Stéphane Galland <galland@arakhne.org>
  • Loading branch information
gallandarakhneorg committed Dec 22, 2020
1 parent a47cbda commit 8aab3f5
Show file tree
Hide file tree
Showing 19 changed files with 270 additions and 36 deletions.
Expand Up @@ -224,16 +224,17 @@
<requires>
<import plugin="io.sarl.eclipse" version="0.12.0" match="greaterOrEqual"/>
<import plugin="io.sarl.m2e" version="0.12.0" match="greaterOrEqual"/>
<import plugin="org.eclipse.emf.common.ui" version="2.18.0" match="greaterOrEqual"/>
<import plugin="javax.inject" version="1.0.0" match="greaterOrEqual"/>
<import plugin="com.google.inject" version="4.2.3" match="greaterOrEqual"/>
<import plugin="org.eclipse.xtext.ui" version="2.22.0" match="greaterOrEqual"/>
<import plugin="org.eclipse.ui" version="3.117.0" match="greaterOrEqual"/>
<import plugin="org.eclipse.core.runtime" version="3.18.0" match="greaterOrEqual"/>
<import plugin="org.eclipse.emf.common.ui" version="2.18.0" match="greaterOrEqual"/>
<import plugin="org.eclipse.ui.ide" version="3.17.100" match="greaterOrEqual"/>
<import plugin="org.eclipse.debug.ui" version="3.14.500" match="greaterOrEqual"/>
<import plugin="org.eclipse.core.resources" version="3.13.700" match="greaterOrEqual"/>
<import plugin="org.eclipse.jdt.launching" version="3.17.100" match="greaterOrEqual"/>
<import plugin="javax.inject" version="1.0.0" match="greaterOrEqual"/>
<import plugin="com.google.inject" version="4.2.3" match="greaterOrEqual"/>
<import plugin="org.eclipse.jdt.core" version="3.22.0" match="greaterOrEqual"/>
</requires>

<plugin
Expand Down
Expand Up @@ -93,15 +93,17 @@ public IStatus log(Throwable exception) {
* @param shell the parent container.
* @param title the title of the dialog box.
* @param message the message to display into the dialog box.
* @param reason the reason to display into the dialog box.
* @param exception the exception to be logged.
* @since 0.6
* @since 0.12
* @see #log(Throwable)
*/
public void openError(Shell shell, String title, String message, Throwable exception) {
public void openError(Shell shell, String title, String message, String reason, Throwable exception) {
final Throwable ex = (exception != null) ? Throwables.getRootCause(exception) : null;
if (ex != null) {
log(ex);
final IStatus status = createStatus(IStatus.ERROR, 0, message, ex);
final String rmessage = Strings.isNullOrEmpty(reason) ? message : reason;
final IStatus status = createStatus(IStatus.ERROR, 0, rmessage, ex);
ErrorDialog.openError(shell, title, message, status);
} else {
MessageDialog.openError(shell, title, message);
Expand Down
Expand Up @@ -258,17 +258,17 @@ protected void postProjectInstallation(ProjectDescriptor projectDescriptor, IPro
} catch (CoreException exception) {
SARLExamplePlugin.getDefault().openError(getShell(),
io.sarl.eclipse.util.Messages.AbstractSarlScriptInteractiveSelector_1,
exception.getStatus().getMessage(), exception);
exception.getStatus().getMessage(), exception.getStatus().getMessage(), exception);
}
}
} catch (CoreException exception) {
SARLExamplePlugin.getDefault().openError(getShell(),
io.sarl.eclipse.util.Messages.AbstractSarlScriptInteractiveSelector_1,
exception.getStatus().getMessage(), exception);
exception.getStatus().getMessage(), null, exception);
} catch (Exception exception) {
SARLExamplePlugin.getDefault().openError(getShell(),
io.sarl.eclipse.util.Messages.AbstractSarlScriptInteractiveSelector_1,
exception.getMessage(), exception);
exception.getMessage(), exception.getMessage(), exception);
}
}

Expand Down
Expand Up @@ -368,15 +368,16 @@ public void savePreferences() {
* @param shell the parent container.
* @param title the title of the dialog box.
* @param message the message to display into the dialog box.
* @param reason the reason to display into the dialog box.
* @param exception the exception to be logged.
* @since 0.6
* @since 0.12
* @see #log(Throwable)
*/
public void openError(Shell shell, String title, String message, Throwable exception) {
public void openError(Shell shell, String title, String message, String reason, Throwable exception) {
final Throwable ex = (exception != null) ? Throwables.getRootCause(exception) : null;
if (ex != null) {
log(ex);
final IStatus status = createStatus(IStatus.ERROR, message, ex);
final IStatus status = createStatus(IStatus.ERROR, reason, ex);
ErrorDialog.openError(shell, title, message, status);
} else {
MessageDialog.openError(shell, title, message);
Expand Down
Expand Up @@ -224,7 +224,7 @@ private void searchAndLaunch(String mode, Object... scope) {
} catch (CoreException e) {
SARLEclipsePlugin.getDefault().openError(getShell(),
io.sarl.eclipse.util.Messages.AbstractSarlScriptInteractiveSelector_1,
e.getStatus().getMessage(), e);
e.getStatus().getMessage(), null, e);
}
}
}
Expand Down
Expand Up @@ -102,7 +102,7 @@ protected ILaunchConfiguration createConfiguration(String projectName, String fu
} catch (CoreException exception) {
SARLEclipsePlugin.getDefault().openError(getShell(),
io.sarl.eclipse.util.Messages.AbstractSarlScriptInteractiveSelector_1,
exception.getStatus().getMessage(), exception);
exception.getStatus().getMessage(), null, exception);
return null;
}
}
Expand Down
Expand Up @@ -98,7 +98,7 @@ protected ILaunchConfiguration createConfiguration(String projectName, String fu
} catch (CoreException exception) {
SARLEclipsePlugin.getDefault().openError(getShell(),
io.sarl.eclipse.util.Messages.AbstractSarlScriptInteractiveSelector_1,
exception.getStatus().getMessage(), exception);
exception.getStatus().getMessage(), null, exception);
return null;
}
}
Expand Down
Expand Up @@ -282,7 +282,7 @@ public ElementDescription searchAndSelect(boolean showEmptySelectionError, Objec
SARLEclipsePlugin.getDefault().openError(getShell(),
Messages.AbstractSarlScriptInteractiveSelector_1,
MessageFormat.format(Messages.AbstractSarlScriptInteractiveSelector_2, getElementLabel()),
null);
null, null);
}
} else if (elements.size() > 1) {
element = chooseElement(elements);
Expand All @@ -294,7 +294,7 @@ public ElementDescription searchAndSelect(boolean showEmptySelectionError, Objec
//
} catch (Exception exception) {
SARLEclipsePlugin.getDefault().openError(getShell(), Messages.AbstractSarlScriptInteractiveSelector_1, null,
exception);
null, exception);
}
return null;
}
Expand Down
Expand Up @@ -754,7 +754,7 @@ protected void execute(IProgressMonitor monitor)
} catch (InvocationTargetException e) {
final Throwable realException = e.getTargetException();
SARLEclipsePlugin.getDefault().openError(getShell(), getTitle(),
realException.getMessage(), realException);
realException.getMessage(), null, realException);
}
return size[0];
}
Expand Down
Expand Up @@ -642,7 +642,7 @@ protected IProject createProvisonalProject() {
ErrorDialog.openError(
getShell(),
NewWizardMessages.NewJavaProjectWizardPageTwo_error_title,
null,
NewWizardMessages.NewJavaProjectWizardPageTwo_error_title,
status);
}
}
Expand Down
Expand Up @@ -44,7 +44,7 @@ public DelegateDynamicSkillProvider(DynamicSkillProvider[] delegates) {
assert delegates != null;
this.delegates = delegates;
}

@Pure
@Override
public Skill createSkill(Class<? extends Capacity> capacity) {
Expand Down
@@ -0,0 +1,87 @@
/*
* $Id$
*
* SARL is an general-purpose agent programming language.
* More details on http://www.sarl.io
*
* Copyright (C) 2014-2020 the original authors or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.sarl.lang.ui;

import com.google.common.base.Throwables;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.Shell;

import io.sarl.lang.ui.internal.LangActivator;

/**
* Utility functions for the plugin. The plugin activator is an instance of {@link LangActivator}.
*
* @author $Author: sgalland$
* @version $FullVersion$
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
* @since 0.12
* @see LangActivator
*/
public final class SARLUiPlugin {

/**
* Logs an internal error with the specified throwable.
*
* @param exception the exception to be logged
* @see #openError(Shell, String, String, Throwable)
*/
public static void log(Throwable exception) {
final LangActivator activator = LangActivator.getInstance();
if (exception instanceof CoreException) {
activator.getLog().log(new Status(IStatus.ERROR, LangActivator.PLUGIN_ID,
exception.getMessage(),
exception.getCause()));
} else if (exception != null) {
activator.getLog().log(new Status(IStatus.ERROR, LangActivator.PLUGIN_ID,
exception.getMessage(), exception));
} else {
activator.getLog().log(new Status(IStatus.ERROR, LangActivator.PLUGIN_ID,
"Internal Error", exception)); //$NON-NLS-1$
}
}

/**
* Display an error dialog and log the error.
*
* @param shell the parent container.
* @param title the title of the dialog box.
* @param message the message to display into the dialog box.
* @param reasonMessage the message that explain the reason to display into the dialog box.
* @see #log(Throwable)
*/
public static void openError(Shell shell, String title, String message, String reasonMessage, Throwable exception) {
final Throwable ex = (exception != null) ? Throwables.getRootCause(exception) : null;
if (ex != null) {
log(ex);
final IStatus status = new Status(IStatus.ERROR, LangActivator.PLUGIN_ID, reasonMessage, ex);
ErrorDialog.openError(shell, title, message, status);
} else {
MessageDialog.openError(shell, title, message);
}
}

}
@@ -0,0 +1,46 @@
/*
* $Id$
*
* SARL is an general-purpose agent programming language.
* More details on http://www.sarl.io
*
* Copyright (C) 2014-2020 the original authors or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.sarl.lang.ui.codemining;

import org.eclipse.osgi.util.NLS;

/** Localized Messages.
* @author $Author: sgalland$
* @version $FullVersion$
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
* @ExcludeFromApidoc
*/
@SuppressWarnings("all")
public class Messages extends NLS {
private static final String BUNDLE_NAME = Messages.class.getPackage().getName() + ".messages"; //$NON-NLS-1$
public static String SARLCodeMiningProvider_0;
public static String SARLCodeMiningProvider_1;
public static String SARLCodeMiningProvider_2;
static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
}

private Messages() {
}
}

0 comments on commit 8aab3f5

Please sign in to comment.