import java.util.List;
import java.util.stream.Collectors;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.tracecompass.internal.provisional.analysis.lami.core.module.LamiAnalysis;
import org.eclipse.tracecompass.internal.provisional.analysis.lami.core.module.LamiChartModel;
-import org.eclipse.tracecompass.tmf.core.analysis.ondemand.OnDemandAnalysisException;
import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
import com.google.common.collect.ImmutableMultimap;
@Override
protected String getResultsFromCommand(List<String> command, IProgressMonitor monitor)
- throws OnDemandAnalysisException {
-
+ throws CoreException {
return readLamiFile(fResultFilename);
}
import java.util.List;
import java.util.Map;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.tracecompass.internal.provisional.analysis.lami.core.aspect.LamiTableEntryAspect;
import org.eclipse.tracecompass.internal.provisional.analysis.lami.core.module.LamiResultTable;
import org.eclipse.tracecompass.internal.provisional.analysis.lami.core.types.LamiSize;
import org.eclipse.tracecompass.internal.provisional.analysis.lami.core.types.LamiSystemCall;
import org.eclipse.tracecompass.internal.provisional.analysis.lami.core.types.LamiTimeRange;
-import org.eclipse.tracecompass.tmf.core.analysis.ondemand.OnDemandAnalysisException;
import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
/**
* Test the results parsing.
*
- * @throws OnDemandAnalysisException when execute() fails.
+ * @throws CoreException when execute() fails.
*/
@Test
- public void testResults() throws OnDemandAnalysisException {
+ public void testResults() throws CoreException {
LamiAnalysisStub analysis = new LamiAnalysisStub("test-metadata.json", "test-results.json");
List<LamiResultTable> resultTables = analysis.execute(fTrace, null, "", new NullProgressMonitor());
/**
* Test the error parsing of the results.
*
- * @throws OnDemandAnalysisException when execute() fails.
+ * @throws CoreException when execute() fails.
*/
- @Test (expected = OnDemandAnalysisException.class)
- public void testResultsError() throws OnDemandAnalysisException {
+ @Test (expected = CoreException.class)
+ public void testResultsError() throws CoreException {
LamiAnalysisStub analysis = new LamiAnalysisStub("test-metadata.json", "test-error.json");
analysis.execute(fTrace, null, "", new NullProgressMonitor());
import java.util.stream.Collectors;
import java.util.stream.Stream;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.MultiStatus;
+import org.eclipse.core.runtime.Status;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.tracecompass.internal.analysis.lami.core.Activator;
import org.eclipse.tracecompass.internal.provisional.analysis.lami.core.types.LamiData.DataType;
import org.eclipse.tracecompass.internal.provisional.analysis.lami.core.types.LamiTimeRange;
import org.eclipse.tracecompass.tmf.core.analysis.ondemand.IOnDemandAnalysis;
-import org.eclipse.tracecompass.tmf.core.analysis.ondemand.OnDemandAnalysisException;
import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
import org.json.JSONArray;
* @param monitor
* The progress monitor used to report progress
* @return The script's output, formatted into {@link LamiTableEntry}'s.
- * @throws OnDemandAnalysisException
+ * @throws CoreException
* If execution did not terminate normally
*/
@Override
public List<LamiResultTable> execute(ITmfTrace trace, @Nullable TmfTimeRange timeRange,
- String extraParams, IProgressMonitor monitor) throws OnDemandAnalysisException {
+ String extraParams, IProgressMonitor monitor) throws CoreException {
/* Should have been called already, but in case it was not */
initialize();
String output = getResultsFromCommand(command, monitor);
if (output.isEmpty()) {
- throw new OnDemandAnalysisException(Messages.LamiAnalysis_NoResults);
+ IStatus status = new Status(IStatus.INFO, Activator.instance().getPluginId(), Messages.LamiAnalysis_NoResults);
+ throw new CoreException(status);
}
/*
* No results were reported. This may be normal, but warn the
* user why a report won't be created.
*/
- throw new OnDemandAnalysisException(Messages.LamiAnalysis_NoResults);
+ IStatus status = new Status(IStatus.INFO, Activator.instance().getPluginId(), Messages.LamiAnalysis_NoResults);
+ throw new CoreException(status);
}
for (int i = 0; i < results.length(); i++) {
}
} catch (JSONException e) {
- throw new OnDemandAnalysisException(e.getMessage());
+ IStatus status = new Status(IStatus.ERROR, Activator.instance().getPluginId(), e.getMessage(), e);
+ throw new CoreException(status);
}
return resultsBuilder.build();
* @param monitor
* The progress monitor
* @return The analysis results
- * @throws OnDemandAnalysisException
+ * @throws CoreException
* If the command ended abnormally, and normal results were not
* returned
*/
@VisibleForTesting
protected String getResultsFromCommand(List<String> command, IProgressMonitor monitor)
- throws OnDemandAnalysisException {
+ throws CoreException {
final int scale = 1000;
double workedSoFar = 0.0;
if (monitor.isCanceled()) {
/* We were interrupted by the canceller thread. */
- throw new OnDemandAnalysisException(null);
+ IStatus status = new Status(IStatus.CANCEL, Activator.instance().getPluginId(), null);
+ throw new CoreException(status);
}
if (ret != 0) {
* gather the stderr and report it to the user.
*/
BufferedReader br = new BufferedReader(new InputStreamReader(p.getErrorStream()));
- String stdErrOutput = br.lines().collect(Collectors.joining("\n")); //$NON-NLS-1$
- throw new OnDemandAnalysisException(stdErrOutput);
+ List<String> stdErrOutput = br.lines().collect(Collectors.toList());
+
+ MultiStatus status = new MultiStatus(Activator.instance().getPluginId(),
+ IStatus.ERROR, Messages.LamiAnalysis_ErrorDuringExecution, null);
+ for (String str : stdErrOutput) {
+ status.add(new Status(IStatus.ERROR, Activator.instance().getPluginId(), str));
+ }
+ if (stdErrOutput.isEmpty()) {
+ /*
+ * At least say "no output", so an error message actually
+ * shows up.
+ */
+ status.add(new Status(IStatus.ERROR, Activator.instance().getPluginId(), Messages.LamiAnalysis_ErrorNoOutput));
+ }
+ throw new CoreException(status);
}
/* External script ended successfully, all is fine! */
return checkNotNull(resultsStr);
} catch (IOException | InterruptedException e) {
- throw new OnDemandAnalysisException(Messages.LamiAnalysis_ExecutionInterrupted);
+ IStatus status = new Status(IStatus.ERROR, Activator.instance().getPluginId(), Messages.LamiAnalysis_ExecutionInterrupted, e);
+ throw new CoreException(status);
} finally {
if (cancellerRunnable != null) {
public static String LamiAnalysis_MainTaskName;
public static String LamiAnalysis_NoResults;
+ public static String LamiAnalysis_ErrorDuringExecution;
+ public static String LamiAnalysis_ErrorNoOutput;
public static String LamiAnalysis_ExecutionInterrupted;
public static String LamiAnalysis_ExtendedTableNamePrefix;
LamiAnalysis_MainTaskName = Invoking external analysis script
LamiAnalysis_NoResults = No results were returned.
+LamiAnalysis_ErrorDuringExecution = Error during execution of the script.
+LamiAnalysis_ErrorNoOutput = (No output)
LamiAnalysis_ExecutionInterrupted = Execution was interrupted.
LamiAnalysis_ExtendedTableNamePrefix = Extended
public static String ParameterDialog_ExternalParametersDescription;
public static String ParameterDialog_StringValidatorMessage;
public static String ParameterDialog_ReportNameSuffix;
- public static String ParameterDialog_Error;
- public static String ParameterDialog_ErrorMessage;
+
+ public static String ErrorDialog_Info;
+ public static String ErrorDialog_InfoMessage;
+ public static String ErrorDialog_Error;
+ public static String ErrorDialog_ErrorMessage;
+
public static String AddAnalysisDialog_Name;
public static String AddAnalysisDialog_Command;
public static String AddAnalysisDialog_NameEmptyErrorMessage;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.dialogs.IInputValidator;
-import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.window.Window;
import org.eclipse.tracecompass.internal.provisional.analysis.lami.ui.views.LamiReportViewFactory;
import org.eclipse.tracecompass.tmf.core.analysis.ondemand.IOnDemandAnalysis;
import org.eclipse.tracecompass.tmf.core.analysis.ondemand.IOnDemandAnalysisReport;
-import org.eclipse.tracecompass.tmf.core.analysis.ondemand.OnDemandAnalysisException;
import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
});
return Status.OK_STATUS;
- } catch (OnDemandAnalysisException e) {
- String errMsg = e.getMessage();
-
- if (errMsg != null) {
- /* The analysis execution yielded an error */
- Display.getDefault().asyncExec(() -> {
- MessageDialog.openError(shell,
- /* Dialog title */
- Messages.ParameterDialog_Error,
- /* Dialog message */
- Messages.ParameterDialog_ErrorMessage + ":\n\n" + //$NON-NLS-1$
- errMsg);
- });
+ } catch (CoreException e) {
+ /*
+ * The analysis execution did not complete normally, we will
+ * report it to the user.
+ */
+ IStatus status = e.getStatus();
+
+ /* Don't display a dialog if it was simply cancelled by the user */
+ if (status.matches(IStatus.CANCEL)) {
+ return status;
+ }
+
+ String dialogTitle;
+ String dialogMessage;
+ if (status.matches(IStatus.ERROR)) {
+ dialogTitle = Messages.ErrorDialog_Error;
+ dialogMessage = Messages.ErrorDialog_ErrorMessage;
+ } else {
+ dialogTitle = Messages.ErrorDialog_Info;
+ dialogMessage = Messages.ErrorDialog_InfoMessage;
}
- return Status.CANCEL_STATUS;
+ Display.getDefault().asyncExec(() -> {
+ ErrorDialog.openError(shell, dialogTitle, dialogMessage, status);
+ });
+
+ /*
+ * We showed our own error message, no need for the Job to
+ * show another one.
+ */
+ return Status.OK_STATUS;
}
}
};
ParameterDialog_ExternalParametersDescription = Extra parameters to pass to the external analysis. Leave empty for none.
ParameterDialog_StringValidatorMessage = Allowed characters are letters, numbers, ',' and '-'
ParameterDialog_ReportNameSuffix = Report
-ParameterDialog_Error = Error running external script
-ParameterDialog_ErrorMessage = The script terminated abnormally
+
+ErrorDialog_Info = External script completed
+ErrorDialog_InfoMessage = The script finished executing.
+ErrorDialog_Error = Error running external script
+ErrorDialog_ErrorMessage = The script terminated abnormally.
AddAnalysisDialog_Title = Add External Analysis
AddAnalysisDialog_Name = Name
package org.eclipse.tracecompass.tmf.core.analysis.ondemand;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
* for a default monitor.
* @return The results of this analysis. Exact object type is
* analysis-dependent, a more specific return type is encouraged.
- * @throws OnDemandAnalysisException
+ * @throws CoreException
* If something went wrong with the execution, and expected
* results will not be returned
*/
Object execute(ITmfTrace trace, TmfTimeRange range, String extraParams,
- IProgressMonitor monitor) throws OnDemandAnalysisException;
+ IProgressMonitor monitor) throws CoreException;
}
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2016 EfficiOS Inc., Alexandre Montplaisir
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *******************************************************************************/
-
-package org.eclipse.tracecompass.tmf.core.analysis.ondemand;
-
-import org.eclipse.jdt.annotation.Nullable;
-
-/**
- * Exceptions resulting from the execution of on-demand analyses.
- *
- * The suggested behavior is to display the reported messages to the end user,
- * so they know why execution did not end normally.
- *
- * @author Alexandre Montplaisir
- * @since 2.0
- */
-public class OnDemandAnalysisException extends Exception {
-
- private static final long serialVersionUID = 7296987172562152876L;
-
- /**
- * Build a new exception. If the message is not null, it should be reported
- * to the user.
- *
- * @param message
- * The message to display, if any
- */
- public OnDemandAnalysisException(@Nullable String message) {
- super(message);
- }
-
- @Override
- public @Nullable String getMessage() {
- return super.getMessage();
- }
-
-}