Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpelder2009-04-28 08:46:06 -0400
committerpelder2009-04-28 08:46:06 -0400
commit5db0f2aac8774745e3982db2ab07ec0f51e8eb3f (patch)
treef3dc11baa3c27b5beffab2ecc0f270b2f15bfd2e
parent6f895cb3e1ac8e9cd37cbc83a29604c1233d87f3 (diff)
downloadorg.eclipse.jet-5db0f2aac8774745e3982db2ab07ec0f51e8eb3f.tar.gz
org.eclipse.jet-5db0f2aac8774745e3982db2ab07ec0f51e8eb3f.tar.xz
org.eclipse.jet-5db0f2aac8774745e3982db2ab07ec0f51e8eb3f.zip
[273913] JET should better handle templates that throw OperationCanceledException
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/JET2Platform.java19
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/SafeCustomRuntimeTag.java12
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/workspace/ActionsUtil.java7
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/workspace/WorkspaceContextExtender.java36
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/transform/TransformContextExtender.java100
5 files changed, 142 insertions, 32 deletions
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/JET2Platform.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/JET2Platform.java
index f049ddf..4dfcb43 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/JET2Platform.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/JET2Platform.java
@@ -39,6 +39,7 @@ import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.SubProgressMonitor;
@@ -420,6 +421,8 @@ public class JET2Platform
public void run(IJETBundleDescriptor descriptor, JET2TemplateLoader templateLoader, IProgressMonitor monitor)
{
monitor.beginTask(JET2Messages.JET2Platform_Executing, 100);
+ monitor.setTaskName(JET2Messages.JET2Platform_Executing);
+ monitor.subTask(descriptor.getId());
final TransformContextExtender tce = TransformContextExtender.getInstance(context);
if(tce.getShellContext() == null )
{
@@ -443,16 +446,8 @@ public class JET2Platform
BodyContentWriter bodyContentWriter = new BodyContentWriter();
- final SubProgressMonitor templateMonitor = new SubProgressMonitor(monitor, 50);
- templateMonitor.beginTask(JET2Messages.JET2Platform_ExecutingTemplates, IProgressMonitor.UNKNOWN);
- try
- {
- tce.execute(descriptor.getMainTemplate(), bodyContentWriter);
- }
- finally
- {
- templateMonitor.done();
- }
+ tce.setProgressMonitor(new SubProgressMonitor(monitor, 50));
+ tce.execute(descriptor.getMainTemplate(), bodyContentWriter);
monitor.subTask(JET2Messages.JET2Platform_CommittingResults);
tce.commit(new SubProgressMonitor(monitor, 50));
}
@@ -472,6 +467,10 @@ public class JET2Platform
processResults(id, contextLog);
result = toIStatus(contextLog);
}
+ catch (OperationCanceledException e)
+ {
+ result = Status.CANCEL_STATUS;
+ }
catch (BundleException e)
{
result = new Status(IStatus.ERROR, PLUGIN_ID, IStatus.OK, e.getLocalizedMessage(), e);
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/SafeCustomRuntimeTag.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/SafeCustomRuntimeTag.java
index c54230b..90066ff 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/SafeCustomRuntimeTag.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/SafeCustomRuntimeTag.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2006 IBM Corporation and others.
+ * Copyright (c) 2005, 2009 IBM Corporation and others.
* 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
@@ -20,7 +20,9 @@ package org.eclipse.jet.internal.runtime;
import java.text.MessageFormat;
import org.eclipse.core.runtime.ISafeRunnable;
+import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.SafeRunner;
import org.eclipse.jet.JET2Context;
import org.eclipse.jet.JET2Writer;
import org.eclipse.jet.internal.l10n.JET2Messages;
@@ -46,7 +48,11 @@ public abstract class SafeCustomRuntimeTag implements RuntimeTagElement
public void handleException(Throwable exception)
{
- if (exception instanceof RuntimeException && !(exception instanceof JET2TagException))
+ if(exception instanceof OperationCanceledException)
+ {
+ throw ((OperationCanceledException) exception);
+ }
+ else if (exception instanceof RuntimeException && !(exception instanceof JET2TagException))
{
// we make the assumption that runtime exceptions we're unintended results of
// tag execution, and that a clearer message should be issued.
@@ -111,7 +117,7 @@ public abstract class SafeCustomRuntimeTag implements RuntimeTagElement
customParent = null;
}
- Platform.run(new TagSafeRunnable()
+ SafeRunner.run(new TagSafeRunnable()
{
public void doRun() throws Exception
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/workspace/ActionsUtil.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/workspace/ActionsUtil.java
index 319129f..910fe7d 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/workspace/ActionsUtil.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/workspace/ActionsUtil.java
@@ -172,6 +172,7 @@ public final class ActionsUtil
new Object []{ file.getFullPath().toString() });
monitor.beginTask(fileMessage, 5);
+ monitor.setTaskName(fileMessage);
if (file.exists() && !replace)
{
@@ -285,9 +286,11 @@ public final class ActionsUtil
boolean foldersCreated = false;
IProject project = folder.getProject();
IPath relPath = folder.getProjectRelativePath();
+ final String taskMessage = MessageFormat.format(JET2Messages.WsFolderAction_CreatingFolder, new Object []{ folder.getFullPath().toString() });
monitor.beginTask(
- MessageFormat.format(JET2Messages.WsFolderAction_CreatingFolder, new Object []{ folder.getFullPath().toString() }),
+ taskMessage,
relPath.segmentCount());
+ monitor.setTaskName(taskMessage);
for (int i = 1; i <= relPath.segmentCount(); i++)
{
IPath subPath = relPath.uptoSegment(i);
@@ -669,7 +672,7 @@ public final class ActionsUtil
{
monitor.beginTask(JET2Messages.ProjectTemplateBundleDescriptor_WaitingForBuild, 1);
try {
- ResourcesPlugin.getWorkspace().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, monitor);
+ ResourcesPlugin.getWorkspace().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, new SubProgressMonitor(monitor, 1));
}
catch (CoreException e)
{
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/workspace/WorkspaceContextExtender.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/workspace/WorkspaceContextExtender.java
index bef92ad..562419b 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/workspace/WorkspaceContextExtender.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/workspace/WorkspaceContextExtender.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2008 IBM Corporation and others.
+ * Copyright (c) 2005, 2009 IBM Corporation and others.
* 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
@@ -35,6 +35,7 @@ import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.ISafeRunnable;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.SafeRunner;
import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.jet.CoreJETException;
@@ -162,6 +163,12 @@ public final class WorkspaceContextExtender
// do nothing
}
+ private void checkCanceled(IProgressMonitor monitor) {
+ if(monitor != null && monitor.isCanceled()) {
+ throw new OperationCanceledException();
+ }
+ }
+
public void commit(final JET2Context context, IProgressMonitor monitor) throws JET2TagException
{
final int actionsToExecuteCount = workspaceActions.size() + finalWorkspaceActions.size();
@@ -171,13 +178,14 @@ public final class WorkspaceContextExtender
TransformContextExtender tce = TransformContextExtender.getInstance(context);
monitor.beginTask(JET2Messages.WorkspaceContextExtender_Commiting, 1 + actionsToExecuteCount);
-
+ monitor.setTaskName(JET2Messages.WorkspaceContextExtender_Commiting);
try
{
monitor.subTask(JET2Messages.WorkspaceContextExtender_ConfirmingTeamAccess);
final List filesToValidateEdit = new ArrayList(actionsToExecute.size());
for (Iterator i = actionsToExecute.iterator(); i.hasNext();)
{
+ checkCanceled(monitor);
final IWorkspaceAction action = (IWorkspaceAction)i.next();
if(isActionRequired(context, action)) {
doActionRequiresValidateEdit(context, action, filesToValidateEdit);
@@ -202,22 +210,23 @@ public final class WorkspaceContextExtender
ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable()
{
- public void run(final IProgressMonitor submon) throws CoreException
+ public void run(final IProgressMonitor writingMonitor) throws CoreException
{
- submon.beginTask(null, actionsToExecute.size());
+ writingMonitor.beginTask(JET2Messages.WorkspaceContextExtender_WritingFiles, actionsToExecute.size());
+ writingMonitor.setTaskName(JET2Messages.WorkspaceContextExtender_WritingFiles);
try
{
for (Iterator i = actionsToExecute.iterator(); i.hasNext();)
{
+ checkCanceled(writingMonitor);
final IWorkspaceAction action = (IWorkspaceAction)i.next();
-
- doActionPerformAction(context, action, submon);
- submon.worked(1);
+ writingMonitor.subTask(action.getTagInfo().displayString());
+ doActionPerformAction(context, action, new SubProgressMonitor(writingMonitor, 1));
}
}
finally
{
- submon.done();
+ writingMonitor.done();
}
}
}, new SubProgressMonitor(monitor, actionsToExecute.size()));
@@ -350,9 +359,9 @@ public final class WorkspaceContextExtender
/**
* @param context
* @param action
- * @param submon
+ * @param monitor
*/
- protected void doActionPerformAction(final JET2Context context, final IWorkspaceAction action, final IProgressMonitor submon)
+ protected void doActionPerformAction(final JET2Context context, final IWorkspaceAction action, final IProgressMonitor monitor)
{
SafeRunner.run(new ISafeRunnable() {
@@ -367,9 +376,9 @@ public final class WorkspaceContextExtender
{
boolean written;
if(action instanceof IWorkspaceAction2) {
- written = ((IWorkspaceAction2)action).performActionIfRequired(new SubProgressMonitor(submon, 1));
+ written = ((IWorkspaceAction2)action).performActionIfRequired(monitor);
} else {
- action.performAction(new SubProgressMonitor(submon, 1));
+ action.performAction(monitor);
written = true;
}
if(written) {
@@ -380,6 +389,9 @@ public final class WorkspaceContextExtender
{
handleException(e);
}
+ finally {
+ monitor.done();
+ }
}});
}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/transform/TransformContextExtender.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/transform/TransformContextExtender.java
index 8348cf8..1fc7d41 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/transform/TransformContextExtender.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/transform/TransformContextExtender.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2007 IBM Corporation and others.
+ * Copyright (c) 2006, 2009 IBM Corporation and others.
* 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
@@ -28,6 +28,7 @@ import java.util.Stack;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.jet.BodyContentWriter;
import org.eclipse.jet.CoreJETException;
@@ -58,7 +59,6 @@ public final class TransformContextExtender
private static String PRIVATE_CONTEXT_DATA_KEY = TransformContextExtender.class.getName();
private final org.eclipse.jet.transform.TransformContextExtender.ContextData contextData;
private final JET2Context context;
-
private static final class ContextData
{
@@ -73,6 +73,9 @@ public final class TransformContextExtender
public IJETBundleDescriptor descriptor = null;
public final List connectedTransforms = new ArrayList();
+
+ public IProgressMonitor monitor;
+
}
/**
@@ -108,24 +111,111 @@ public final class TransformContextExtender
/**
* Execute the named template, writing all template output to the passed writer.
- * @param templatePath
- * @param writer
+ * Equivalent to execute(templatePath, false, writer).
+ * @param templatePath the project relative path of the template to load
+ * @param writer the writer to which the template output will be written
* @throws JET2TagException if an execution error occurs
+ * @see #execute(String, boolean, JET2Writer)
*/
public void execute(String templatePath, JET2Writer writer) throws JET2TagException
{
execute(templatePath, false, writer);
}
+
+ /**
+ * Execute the named template, writing all template output to the passed writer.
+ * If the passed progress monitor is canceled, an {@link OperationCanceledException} will
+ * be thrown.
+ * @param templatePath the project relative path of the template to load
+ * @param useSuper if true, attempt to load the template from override transformation, if it exists
+ * @param writer the writer to which the template output will be written
+ * @param monitor A progress monitor
+ * @throws JET2TagException if an execution error occurs or the template cannot be found
+ * @throws OperationCanceledException if the monitor is canceled.
+ */
+ private void executeWithMonitor(String templatePath, boolean useSuper, JET2Writer writer, IProgressMonitor monitor) throws JET2TagException
+ {
+ final IProgressMonitor savedMonitor = this.contextData.monitor;
+ this.contextData.monitor = monitor;
+ try {
+ monitor.beginTask(JET2Messages.JET2Platform_ExecutingTemplates, IProgressMonitor.UNKNOWN);
+ monitor.setTaskName(JET2Messages.JET2Platform_ExecutingTemplates);
+ monitor.subTask(templatePath);
+ doExecute(templatePath, useSuper, writer);
+ checkCanceled();
+ } finally {
+ monitor.done();
+ this.contextData.monitor = savedMonitor;
+ }
+ }
+
+ /**
+ * Check whether the transformation has been canceled and throw a {@link OperationCanceledException}
+ * if so.
+ *
+ */
+ public void checkCanceled() {
+ if(this.contextData.monitor != null && this.contextData.monitor.isCanceled()) {
+ throw new OperationCanceledException();
+ }
+ }
+
+ /**
+ * Test whether the transformation has been canceled.
+ * @return <code>true</code> if the transformation has been canceled, <code>false</code> otherwise
+ */
+ public boolean isCanceled() {
+ return this.contextData.monitor != null && this.contextData.monitor.isCanceled();
+ }
+
+ /**
+ * Provide a progress monitor for template execution. If provided, templates are executed with
+ * a progress monitor and may through an {@link OperationCanceledException}.
+ * Note that clients typically do not need to call this method as it is initialized from
+ * {@link JET2Platform#runTransform(String, JET2Context, IProgressMonitor)} and its variants.
+ * @param monitor a progress monitor
+ * @throws IllegalStateException if a progress monitor has already been installed
+ * @see #execute(String, JET2Writer)
+ * @see #execute(String, boolean, JET2Writer)
+ * @see #checkCanceled()
+ * @see #isCanceled()
+ */
+ public void setProgressMonitor(IProgressMonitor monitor) {
+ if(this.contextData.monitor != null) {
+ throw new IllegalStateException();
+ }
+ this.contextData.monitor = monitor;
+ }
+
/**
* Execute the named template, writing all template output to the passed writer.
+ * If the transformation context executing this method has passed a progress monitor, then an
+ * appropriate subprogress monitor will be created for this template.
* @param templatePath the project relative path of the template to load
* @param useSuper if true, attempt to load the template from override transformation, if it exists
* @param writer the writer to which the template output will be written
* @throws JET2TagException if an execution error occurs or the template cannot be found
+ * @see #setProgressMonitor(IProgressMonitor)
*/
public void execute(String templatePath, boolean useSuper, JET2Writer writer) throws JET2TagException
{
+ if(this.contextData.monitor != null) {
+ executeWithMonitor(templatePath, useSuper, writer, new SubProgressMonitor(this.contextData.monitor, 1));
+ } else {
+ doExecute(templatePath, useSuper, writer);
+ }
+
+ }
+
+ /**
+ * @param templatePath
+ * @param useSuper
+ * @param writer
+ * @throws JET2TagException
+ */
+ private void doExecute(String templatePath, boolean useSuper, JET2Writer writer) throws JET2TagException
+ {
contextData.templateStack.push(templatePath);
context.setTemplatePath(getTemplatePath());
try
@@ -148,7 +238,6 @@ public final class TransformContextExtender
contextData.templateStack.pop();
context.setTemplatePath(getTemplatePath());
}
-
}
public JET2TemplateLoader getLoader()
@@ -206,6 +295,7 @@ public final class TransformContextExtender
{
for (Iterator i = contextData.listeners.iterator(); i.hasNext();)
{
+ checkCanceled();
TransformContextListener listener = (TransformContextListener)i.next();
try

Back to the top