diff options
author | Tobias Schwarz | 2013-08-13 11:47:11 +0000 |
---|---|---|
committer | Tobias Schwarz | 2013-08-13 11:47:11 +0000 |
commit | b8550e331a5a35fc6635cf0e66f9f18a1fad7ec0 (patch) | |
tree | 945b082a215a23014b374bff2388402bf2230350 /target_explorer/plugins/org.eclipse.tcf.te.runtime.stepper | |
parent | 944a2ddfbe527b9adceaa47a07de6dde6e9f9d81 (diff) | |
download | org.eclipse.tcf-b8550e331a5a35fc6635cf0e66f9f18a1fad7ec0.tar.gz org.eclipse.tcf-b8550e331a5a35fc6635cf0e66f9f18a1fad7ec0.tar.xz org.eclipse.tcf-b8550e331a5a35fc6635cf0e66f9f18a1fad7ec0.zip |
Traget Explorer: rework stepper status handling
Diffstat (limited to 'target_explorer/plugins/org.eclipse.tcf.te.runtime.stepper')
6 files changed, 142 insertions, 124 deletions
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.stepper/META-INF/MANIFEST.MF b/target_explorer/plugins/org.eclipse.tcf.te.runtime.stepper/META-INF/MANIFEST.MF index a50610791..0a8c6965d 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.runtime.stepper/META-INF/MANIFEST.MF +++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime.stepper/META-INF/MANIFEST.MF @@ -1,30 +1,31 @@ -Manifest-Version: 1.0
-Bundle-ManifestVersion: 2
-Bundle-Name: %pluginName
-Bundle-SymbolicName: org.eclipse.tcf.te.runtime.stepper;singleton:=true
-Bundle-Version: 1.1.0.qualifier
-Bundle-Activator: org.eclipse.tcf.te.runtime.stepper.activator.CoreBundleActivator
-Bundle-Vendor: %providerName
-Require-Bundle: org.eclipse.core.runtime;bundle-version="3.8.0",
- org.eclipse.core.expressions;bundle-version="3.4.400",
- org.eclipse.tcf.te.runtime;bundle-version="1.1.0",
- org.eclipse.tcf.te.runtime.concurrent;bundle-version="1.1.0",
- org.eclipse.tcf.te.runtime.model;bundle-version="1.1.0",
- org.eclipse.tcf.te.runtime.services;bundle-version="1.1.0"
-Bundle-RequiredExecutionEnvironment: JavaSE-1.6
-Bundle-ActivationPolicy: lazy
-Bundle-Localization: plugin
-Export-Package: org.eclipse.tcf.te.runtime.stepper,
- org.eclipse.tcf.te.runtime.stepper.activator;x-internal:=true,
- org.eclipse.tcf.te.runtime.stepper.context,
- org.eclipse.tcf.te.runtime.stepper.extensions,
- org.eclipse.tcf.te.runtime.stepper.extensions.manager,
- org.eclipse.tcf.te.runtime.stepper.interfaces,
- org.eclipse.tcf.te.runtime.stepper.interfaces.tracing,
- org.eclipse.tcf.te.runtime.stepper.internal,
- org.eclipse.tcf.te.runtime.stepper.iterators,
- org.eclipse.tcf.te.runtime.stepper.job,
- org.eclipse.tcf.te.runtime.stepper.nls;x-internal:=true,
- org.eclipse.tcf.te.runtime.stepper.services,
- org.eclipse.tcf.te.runtime.stepper.stepper,
- org.eclipse.tcf.te.runtime.stepper.steps
+Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %pluginName +Bundle-SymbolicName: org.eclipse.tcf.te.runtime.stepper;singleton:=true +Bundle-Version: 1.1.0.qualifier +Bundle-Activator: org.eclipse.tcf.te.runtime.stepper.activator.CoreBundleActivator +Bundle-Vendor: %providerName +Require-Bundle: org.eclipse.core.runtime;bundle-version="3.8.0", + org.eclipse.core.expressions;bundle-version="3.4.400", + org.eclipse.tcf.te.runtime;bundle-version="1.1.0", + org.eclipse.tcf.te.runtime.concurrent;bundle-version="1.1.0", + org.eclipse.tcf.te.runtime.model;bundle-version="1.1.0", + org.eclipse.tcf.te.runtime.services;bundle-version="1.1.0", + org.eclipse.tcf.te.runtime.statushandler;bundle-version="1.1.0" +Bundle-RequiredExecutionEnvironment: JavaSE-1.6 +Bundle-ActivationPolicy: lazy +Bundle-Localization: plugin +Export-Package: org.eclipse.tcf.te.runtime.stepper, + org.eclipse.tcf.te.runtime.stepper.activator;x-internal:=true, + org.eclipse.tcf.te.runtime.stepper.context, + org.eclipse.tcf.te.runtime.stepper.extensions, + org.eclipse.tcf.te.runtime.stepper.extensions.manager, + org.eclipse.tcf.te.runtime.stepper.interfaces, + org.eclipse.tcf.te.runtime.stepper.interfaces.tracing, + org.eclipse.tcf.te.runtime.stepper.internal, + org.eclipse.tcf.te.runtime.stepper.iterators, + org.eclipse.tcf.te.runtime.stepper.job, + org.eclipse.tcf.te.runtime.stepper.nls;x-internal:=true, + org.eclipse.tcf.te.runtime.stepper.services, + org.eclipse.tcf.te.runtime.stepper.stepper, + org.eclipse.tcf.te.runtime.stepper.steps diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.stepper/src/org/eclipse/tcf/te/runtime/stepper/extensions/StepExecutor.java b/target_explorer/plugins/org.eclipse.tcf.te.runtime.stepper/src/org/eclipse/tcf/te/runtime/stepper/extensions/StepExecutor.java index f91289475..79bb5f838 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.runtime.stepper/src/org/eclipse/tcf/te/runtime/stepper/extensions/StepExecutor.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime.stepper/src/org/eclipse/tcf/te/runtime/stepper/extensions/StepExecutor.java @@ -29,6 +29,7 @@ import org.eclipse.tcf.te.runtime.stepper.interfaces.IFullQualifiedId; import org.eclipse.tcf.te.runtime.stepper.interfaces.IStep; import org.eclipse.tcf.te.runtime.stepper.interfaces.IStepContext; import org.eclipse.tcf.te.runtime.stepper.interfaces.IStepExecutor; +import org.eclipse.tcf.te.runtime.stepper.interfaces.IStepper; import org.eclipse.tcf.te.runtime.stepper.interfaces.tracing.ITraceIds; import org.eclipse.tcf.te.runtime.stepper.nls.Messages; import org.eclipse.tcf.te.runtime.utils.ProgressHelper; @@ -59,6 +60,15 @@ import org.eclipse.tcf.te.runtime.utils.StatusHelper; */ public class StepExecutor implements IStepExecutor { + private final IStepper stepper; + + /** + * Constructor. + */ + public StepExecutor(IStepper stepper) { + this.stepper = stepper; + } + /* (non-Javadoc) * @see org.eclipse.tcf.te.runtime.stepper.interfaces.IStepExecutor#execute(org.eclipse.tcf.te.runtime.stepper.interfaces.IStep, org.eclipse.tcf.te.runtime.stepper.interfaces.IFullQualifiedId, org.eclipse.tcf.te.runtime.stepper.interfaces.IStepContext, org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer, org.eclipse.core.runtime.IProgressMonitor) */ @@ -87,6 +97,8 @@ public class StepExecutor implements IStepExecutor { // Catch any exception that might occur during execution. // Errors are passed through by definition. + CoreException result = null; + boolean canceled = false; try { step.initializeFrom(context, data, id, progress); step.validateExecute(context, data, id, progress); @@ -96,28 +108,26 @@ public class StepExecutor implements IStepExecutor { // user hit cancel on the progress monitor. ExecutorsUtil.waitAndExecute(0, callback.getDoneConditionTester(progress, step.getCancelTimeout())); - // Check the status of the step - normalizeStatus(step, id, context, data, callback.getStatus()); - } - catch (Exception e) { - CoreBundleActivator.getTraceHandler().trace("StepExecutor#execute: Exception catched: class ='" + e.getClass().getName() + "'" //$NON-NLS-1$ //$NON-NLS-2$ - + ", message = '" + e.getLocalizedMessage() + "'" //$NON-NLS-1$ //$NON-NLS-2$ - + ", cause = " //$NON-NLS-1$ - + (e instanceof CoreException ? ((CoreException)e).getStatus().getException() : e.getCause()), - 0, ITraceIds.TRACE_STEPPING, IStatus.WARNING, this); + if (callback.getStatus() == null || callback.getStatus().isOK()) { + return; + } - // If the exception is a CoreException by itself, just re-throw - if (e instanceof CoreException) { - // Check if the message does need normalization - if (isExceptionMessageFormatted(e.getLocalizedMessage())) { - throw (CoreException)e; - } - // We have to normalize the status message first - normalizeStatus(step, id, context, data, ((CoreException)e).getStatus()); - } else { - // all other exceptions are repackaged within a CoreException - normalizeStatus(step, id, context, data, StatusHelper.getStatus(e)); + if (callback.getStatus().matches(IStatus.CANCEL) || (progress != null && progress.isCanceled())) { + throw new OperationCanceledException(callback.getStatus().getMessage()); } + + // Check the info/warning/error status of the step + result = normalizeStatus(step, id, context, data, callback.getStatus(), progress); + } + catch (OperationCanceledException e) { + CoreBundleActivator.getTraceHandler().trace("StepExecutor#execute: *** CANCEL (" + step.getLabel() + ")" //$NON-NLS-1$ //$NON-NLS-2$ + + ", message = '" + e.getMessage() + "'", //$NON-NLS-1$ //$NON-NLS-2$ + 0, ITraceIds.TRACE_STEPPING, IStatus.WARNING, this); + canceled = true; + throw e; + } + catch (Exception e) { + result = normalizeStatus(step, id, context, data, StatusHelper.getStatus(e), progress); } finally { if (!progress.isCanceled()) { @@ -128,12 +138,24 @@ public class StepExecutor implements IStepExecutor { step.cleanup(context, data, id, progress); long endTime = System.currentTimeMillis(); - CoreBundleActivator.getTraceHandler().trace("StepExecutor#execute: *** DONE (" + step.getLabel() + ")", //$NON-NLS-1$ //$NON-NLS-2$ - 0, ITraceIds.TRACE_STEPPING, IStatus.WARNING, this); CoreBundleActivator.getTraceHandler().trace(" [" + ISharedConstants.TIME_FORMAT.format(new Date(endTime)) //$NON-NLS-1$ + " , delay = " + (endTime - startTime) + " ms]" //$NON-NLS-1$ //$NON-NLS-2$ + " ***", //$NON-NLS-1$ 0, ITraceIds.PROFILE_STEPPING, IStatus.WARNING, this); + + if (!canceled) { + if (result == null) { + CoreBundleActivator.getTraceHandler().trace("StepExecutor#execute: *** DONE (" + step.getLabel() + ")", //$NON-NLS-1$ //$NON-NLS-2$ + 0, ITraceIds.TRACE_STEPPING, IStatus.WARNING, this); + } + else { + CoreBundleActivator.getTraceHandler().trace("StepExecutor#execute: *** ERROR (" + step.getLabel() + ")" //$NON-NLS-1$ //$NON-NLS-2$ + + ", message = '" + result.getLocalizedMessage() + "'" //$NON-NLS-1$ //$NON-NLS-2$ + + ", cause = " + result.getStatus().getException(), //$NON-NLS-1$ + 0, ITraceIds.TRACE_STEPPING, IStatus.WARNING, this); + throw result; + } + } } } @@ -146,37 +168,17 @@ public class StepExecutor implements IStepExecutor { * @param data The step data. * @param status The status. * - * @throws CoreException - if the operation fails + * @return CoreException if the operation failed */ - private void normalizeStatus(IStep step, IFullQualifiedId id, IStepContext context , IPropertiesContainer data, IStatus status) throws CoreException { + private CoreException normalizeStatus(IStep step, IFullQualifiedId id, IStepContext context , IPropertiesContainer data, IStatus status, IProgressMonitor progress) { Assert.isNotNull(context); Assert.isNotNull(data); Assert.isNotNull(id); Assert.isNotNull(step); - if (status == null || status.isOK()) { - return; - } - - switch (status.getSeverity()) { - case IStatus.CANCEL: - throw new OperationCanceledException(status.getMessage()); - default: - String message = formatMessage(status.getMessage(), status.getSeverity(), step, id, context, data); - status = new Status(status.getSeverity(), status.getPlugin(), status.getCode(), message != null ? message : status.getMessage(), status.getException()); - throw new CoreException(status); - } - } - - /** - * Checks if the given message is already formatted to get displayed to the user. - * - * @param message The message. Must not be <code>null</code>. - * @return <code>True</code> if the message is already formatted to get displayed to the user, <code>false</code> otherwise. - */ - protected boolean isExceptionMessageFormatted(String message) { - Assert.isNotNull(message); - return message.startsWith(Messages.StepExecutor_checkPoint_normalizationNeeded); + String message = formatMessage(status, step, id, context, data); + status = new Status(status.getSeverity(), status.getPlugin(), status.getCode(), message != null ? message : status.getMessage(), status.getException()); + return new CoreException(status); } /** @@ -191,10 +193,10 @@ public class StepExecutor implements IStepExecutor { * * @return Formatted message. */ - protected String formatMessage(String message, int severity, IStep step, IFullQualifiedId id, IStepContext context, IPropertiesContainer data) { + protected String formatMessage(IStatus status, IStep step, IFullQualifiedId id, IStepContext context, IPropertiesContainer data) { String template = null; - switch (severity) { + switch (status.getSeverity()) { case IStatus.INFO: template = Messages.StepExecutor_info_stepFailed; break; @@ -208,46 +210,23 @@ public class StepExecutor implements IStepExecutor { // If we cannot determine the formatted message template, just return the message as is if (template == null) { - return message; + return status.getMessage(); } - // Check the message for additions - message = checkMessage(message); - - // Split the message. The first sentence is shown more prominent on the top, - // the rest as additional information below the step information. - String[] splittedMsg = message != null ? message.split("[\t\n\r\f]+", 2) : new String[] { null, null }; //$NON-NLS-1$ - // Format the core message String formattedMessage = NLS.bind(template, - new String[] { splittedMsg[0], - context.getName(), - context.getInfo(data), - (step.getLabel() != null && step.getLabel().trim().length() > 0 ? step.getLabel() : step.getId()) - }); - - // If we have more information available, append them - if (splittedMsg.length > 1 && splittedMsg[1] != null && !"".equals(splittedMsg[1])) { //$NON-NLS-1$ - formattedMessage += "\n\n" + splittedMsg[1]; //$NON-NLS-1$ - } + new String[] { + stepper.getLabel(), + status.getMessage(), + (step.getLabel() != null && step.getLabel().trim().length() > 0 ? step.getLabel() : step.getId()), + context.getName() + }); // In debug mode, there is even more information to add if (Platform.inDebugMode()) { - formattedMessage += "\n\n" + NLS.bind(Messages.StepExecutor_stepFailed_debugInfo, id.toString()); //$NON-NLS-1$ + formattedMessage += NLS.bind(Messages.StepExecutor_stepFailed_debugInfo, id.toString()); } return formattedMessage; } - - /** - * Check for additions to add to the message. - * <p> - * <i>Reserved for future use. Currently returns the message unmodified.</i> - * - * @param message The message or <code>null</code>. - * @return The checked message. - */ - protected String checkMessage(String message) { - return message; - } } diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.stepper/src/org/eclipse/tcf/te/runtime/stepper/job/StepperJob.java b/target_explorer/plugins/org.eclipse.tcf.te.runtime.stepper/src/org/eclipse/tcf/te/runtime/stepper/job/StepperJob.java index bd388b989..6edded23a 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.runtime.stepper/src/org/eclipse/tcf/te/runtime/stepper/job/StepperJob.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime.stepper/src/org/eclipse/tcf/te/runtime/stepper/job/StepperJob.java @@ -14,12 +14,17 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.IJobChangeEvent; +import org.eclipse.core.runtime.jobs.IJobChangeListener; import org.eclipse.core.runtime.jobs.ISchedulingRule; import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.core.runtime.jobs.JobChangeAdapter; import org.eclipse.tcf.te.runtime.interfaces.callback.ICallback; import org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer; import org.eclipse.tcf.te.runtime.services.ServiceManager; import org.eclipse.tcf.te.runtime.services.interfaces.IPropertiesAccessService; +import org.eclipse.tcf.te.runtime.statushandler.StatusHandlerManager; +import org.eclipse.tcf.te.runtime.statushandler.interfaces.IStatusHandler; import org.eclipse.tcf.te.runtime.stepper.interfaces.IStepContext; import org.eclipse.tcf.te.runtime.stepper.interfaces.IStepper; import org.eclipse.tcf.te.runtime.stepper.stepper.Stepper; @@ -38,6 +43,7 @@ public class StepperJob extends Job { private boolean isFinished = false; private boolean isCanceled = false; private final boolean isCancelable; + private boolean statusHandled = false; private class NotCancelableProgressMonitor implements IProgressMonitor { @@ -88,6 +94,25 @@ public class StepperJob extends Job { } } + private class JobChangeListener extends JobChangeAdapter { + + /** + * Constructor. + */ + public JobChangeListener() { + } + + /* (non-Javadoc) + * @see org.eclipse.core.runtime.jobs.JobChangeAdapter#done(org.eclipse.core.runtime.jobs.IJobChangeEvent) + */ + @Override + public void done(IJobChangeEvent event) { + handleStatus(event.getResult()); + + removeJobChangeListener(this); + } + } + /** * Constructor. * @@ -160,6 +185,9 @@ public class StepperJob extends Job { monitor = new NotCancelableProgressMonitor(monitor); } + IJobChangeListener listener = new JobChangeListener(); + addJobChangeListener(listener); + // The stepper instance to be used IStepper stepper = new Stepper(getName()); IStatus status = Status.OK_STATUS; @@ -188,7 +216,19 @@ public class StepperJob extends Job { isFinished = true; - return status; + handleStatus(status); + + return statusHandled ? Status.OK_STATUS : status; + } + + protected void handleStatus(IStatus status) { + if (!statusHandled && status != null && status.matches(IStatus.ERROR|IStatus.WARNING|IStatus.INFO)) { + IStatusHandler[] handler = StatusHandlerManager.getInstance().getHandler(StepperJob.this); + if (handler != null && handler.length > 0) { + handler[0].handleStatus(status, null, null); + } + } + statusHandled = true; } public boolean isFinished() { diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.stepper/src/org/eclipse/tcf/te/runtime/stepper/nls/Messages.java b/target_explorer/plugins/org.eclipse.tcf.te.runtime.stepper/src/org/eclipse/tcf/te/runtime/stepper/nls/Messages.java index 00d20e149..f742234c5 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.runtime.stepper/src/org/eclipse/tcf/te/runtime/stepper/nls/Messages.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime.stepper/src/org/eclipse/tcf/te/runtime/stepper/nls/Messages.java @@ -59,7 +59,6 @@ public class Messages extends NLS { public static String StepGroup_error_referencedStepOrGroup; public static String StepGroup_error_requiredStepOrGroup; - public static String StepExecutor_checkPoint_normalizationNeeded; public static String StepExecutor_info_stepFailed; public static String StepExecutor_warning_stepFailed; public static String StepExecutor_error_stepFailed; diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.stepper/src/org/eclipse/tcf/te/runtime/stepper/nls/Messages.properties b/target_explorer/plugins/org.eclipse.tcf.te.runtime.stepper/src/org/eclipse/tcf/te/runtime/stepper/nls/Messages.properties index c9e9d9891..3dd227558 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.runtime.stepper/src/org/eclipse/tcf/te/runtime/stepper/nls/Messages.properties +++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime.stepper/src/org/eclipse/tcf/te/runtime/stepper/nls/Messages.properties @@ -38,15 +38,14 @@ StepGroup_error_referencedBaseGroup=Referenced Base Step Group:\n\t{0} StepGroup_error_referencedStepOrGroup=Referenced Step or Step Group:\n\t{0} StepGroup_error_requiredStepOrGroup=Required Step or Step Group:\n\t{0} -StepExecutor_checkPoint_normalizationNeeded=Step finished with this -StepExecutor_info_stepFailed=Step finished with this information: {0}\n\n\ -Context: {1}\n\{2}\n\ -Step: {3} -StepExecutor_warning_stepFailed=Step finished with this warning: {0}\n\n\ -Context: {1}\n\{2}\n\ -Step: {3} -StepExecutor_error_stepFailed=Step finished with this error: {0}\n\n\ -Context: {1}\n\{2}\n\ -Step: {3} -StepExecutor_stepFailed_debugInfo=Debug info:\n{0} +StepExecutor_info_stepFailed={0} finished with this information:\n\n{1}\n\n\ +Step:\t{2}\n\ +Context:\t{3} +StepExecutor_warning_stepFailed={0} finished with this warning:\n\n{1}\n\n\ +Step:\t{2}\n\ +Context:\t{3} +StepExecutor_error_stepFailed={0} finished with this error:\n\n{1}\n\n\ +Step:\t{2}\n\ +Context:\t{3} +StepExecutor_stepFailed_debugInfo=\nDebug info:\n{0} StepExecutor_warning_rollbackTimeout=Step rollback was aborted due to timeout. diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.stepper/src/org/eclipse/tcf/te/runtime/stepper/stepper/Stepper.java b/target_explorer/plugins/org.eclipse.tcf.te.runtime.stepper/src/org/eclipse/tcf/te/runtime/stepper/stepper/Stepper.java index d285f4955..16d313e0d 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.runtime.stepper/src/org/eclipse/tcf/te/runtime/stepper/stepper/Stepper.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime.stepper/src/org/eclipse/tcf/te/runtime/stepper/stepper/Stepper.java @@ -142,7 +142,7 @@ public class Stepper implements IStepper { protected IStepExecutor doCreateStepExecutor(IStep step, String secondaryId, IFullQualifiedId fullQualifiedStepId) { Assert.isNotNull(step); Assert.isNotNull(fullQualifiedStepId); - return new StepExecutor(); + return new StepExecutor(this); } /* (non-Javadoc) |