From 59781af46af5fe1345d60db2a7a7853edc915789 Mon Sep 17 00:00:00 2001 From: Vassiliy Kudryashov Date: Sat, 14 Jul 2012 21:25:12 +0400 Subject: [PATCH] IDEA-88820 Wrong button behavior in JUnit execution --- .../AbstractRerunFailedTestsAction.java | 5 +- .../execution/runners/RestartAction.java | 228 +++++++++--------- 2 files changed, 118 insertions(+), 115 deletions(-) diff --git a/java/execution/impl/src/com/intellij/execution/actions/AbstractRerunFailedTestsAction.java b/java/execution/impl/src/com/intellij/execution/actions/AbstractRerunFailedTestsAction.java index 37da6d4417d1..88d1a6bd3165 100644 --- a/java/execution/impl/src/com/intellij/execution/actions/AbstractRerunFailedTestsAction.java +++ b/java/execution/impl/src/com/intellij/execution/actions/AbstractRerunFailedTestsAction.java @@ -69,7 +69,7 @@ public class AbstractRerunFailedTestsAction extends AnAction { } public void update(AnActionEvent e) { - e.getPresentation().setEnabled(isActive(e)); + e.getPresentation().setEnabled(isActive(e) && !getModel().isRunning()); } private boolean isActive(AnActionEvent e) { @@ -92,7 +92,6 @@ public class AbstractRerunFailedTestsAction extends AnAction { } public void actionPerformed(AnActionEvent e) { - final DataContext dataContext = e.getDataContext(); boolean isDebug = myConsoleProperties.isDebug(); final MyRunProfile profile = getRunProfile(); try { @@ -104,7 +103,7 @@ public class AbstractRerunFailedTestsAction extends AnAction { profile.getProject(), myEnvironment.getRunnerSettings(), myEnvironment.getConfigurationSettings(), - null, + myEnvironment.getContentToReuse(), myEnvironment.getRunnerAndConfigurationSettings())); } catch (ExecutionException e1) { diff --git a/platform/lang-impl/src/com/intellij/execution/runners/RestartAction.java b/platform/lang-impl/src/com/intellij/execution/runners/RestartAction.java index 22b29784be92..70e138e8416b 100644 --- a/platform/lang-impl/src/com/intellij/execution/runners/RestartAction.java +++ b/platform/lang-impl/src/com/intellij/execution/runners/RestartAction.java @@ -1,112 +1,116 @@ -/* - * Copyright 2000-2009 JetBrains s.r.o. - * - * 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 com.intellij.execution.runners; - -import com.intellij.execution.*; -import com.intellij.execution.process.ProcessHandler; -import com.intellij.execution.ui.RunContentDescriptor; -import com.intellij.icons.AllIcons; -import com.intellij.ide.DataManager; -import com.intellij.openapi.actionSystem.*; -import com.intellij.openapi.keymap.KeymapManager; -import com.intellij.openapi.project.DumbAware; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.ui.Messages; -import org.jetbrains.annotations.NotNull; - -import javax.swing.*; - -/** - * @author dyoma - */ -public class RestartAction extends AnAction implements DumbAware { - private static final Icon STOP_AND_START_ICON = AllIcons.Actions.Restart; - - private ProcessHandler myProcessHandler; - private final ProgramRunner myRunner; - private final RunContentDescriptor myDescriptor; - private final Executor myExecutor; - private final Icon myIcon; - private final ExecutionEnvironment myEnvironment; - - public RestartAction(final Executor executor, - final ProgramRunner runner, - final ProcessHandler processHandler, - final Icon icon, - final RunContentDescriptor descritor, - @NotNull final ExecutionEnvironment env) { - super(null, null, icon); - myIcon = icon; - myEnvironment = env; - getTemplatePresentation().setEnabled(false); - myProcessHandler = processHandler; - myRunner = runner; - myDescriptor = descritor; - myExecutor = executor; - // see IDEADEV-698 - } - - public void actionPerformed(final AnActionEvent e) { - ExecutionManager.getInstance(myEnvironment.getProject()).restartRunProfile(myEnvironment.getProject(), - myExecutor, - myEnvironment.getExecutionTarget(), - myEnvironment.getRunnerAndConfigurationSettings()); - } - - public void restart() { - doRestart(DataManager.getInstance().getDataContext(myDescriptor.getComponent())); - } - - private void doRestart(final DataContext dataContext) { - final Project project = PlatformDataKeys.PROJECT.getData(dataContext); - if (ExecutorRegistry.getInstance().isStarting(project, myExecutor.getId(), myRunner.getRunnerId())) { - return; - } - try { - final ExecutionEnvironment old = myEnvironment; - myRunner.execute(myExecutor, new ExecutionEnvironment(old.getRunProfile(), - old.getExecutionTarget(), - project, - old.getRunnerSettings(), - old.getConfigurationSettings(), - myDescriptor, - old.getRunnerAndConfigurationSettings())); - } - catch (RunCanceledByUserException ignore) { - } - catch (ExecutionException e1) { - Messages.showErrorDialog(project, e1.getMessage(), ExecutionBundle.message("restart.error.message.title")); - } - } - - public void update(final AnActionEvent event) { - final Presentation presentation = event.getPresentation(); - presentation.setText(ExecutionBundle.message("rerun.configuration.action.name", myEnvironment.getRunProfile().getName())); - final boolean isRunning = myProcessHandler != null && !myProcessHandler.isProcessTerminated(); - if (myProcessHandler != null && !isRunning) { - myProcessHandler = null; // already terminated - } - presentation.setIcon(isRunning ? STOP_AND_START_ICON : myIcon); - boolean isTerminating = myProcessHandler != null && myProcessHandler.isProcessTerminating(); - boolean isStarting = ExecutorRegistry.getInstance().isStarting(myEnvironment.getProject(), myExecutor.getId(), myRunner.getRunnerId()); - presentation.setEnabled(!isStarting && !isTerminating); - } - - public void registerShortcut(final JComponent component) { - registerCustomShortcutSet(new CustomShortcutSet(KeymapManager.getInstance().getActiveKeymap().getShortcuts(IdeActions.ACTION_RERUN)), - component); - } -} +/* + * Copyright 2000-2009 JetBrains s.r.o. + * + * 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 com.intellij.execution.runners; + +import com.intellij.execution.*; +import com.intellij.execution.process.ProcessHandler; +import com.intellij.execution.ui.RunContentDescriptor; +import com.intellij.icons.AllIcons; +import com.intellij.ide.DataManager; +import com.intellij.idea.ActionsBundle; +import com.intellij.openapi.actionSystem.*; +import com.intellij.openapi.keymap.KeymapManager; +import com.intellij.openapi.project.DumbAware; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.ui.Messages; +import org.jetbrains.annotations.NotNull; + +import javax.swing.*; + +/** + * @author dyoma + */ +public class RestartAction extends AnAction implements DumbAware { + private static final Icon STOP_AND_START_ICON = AllIcons.Actions.Restart; + + private ProcessHandler myProcessHandler; + private final ProgramRunner myRunner; + private final RunContentDescriptor myDescriptor; + @NotNull private final Executor myExecutor; + private final Icon myIcon; + private final ExecutionEnvironment myEnvironment; + + public RestartAction(@NotNull final Executor executor, + final ProgramRunner runner, + final ProcessHandler processHandler, + final Icon icon, + final RunContentDescriptor descriptor, + @NotNull final ExecutionEnvironment env) { + super(null, null, icon); + myIcon = icon; + myEnvironment = env; + getTemplatePresentation().setEnabled(false); + myProcessHandler = processHandler; + myRunner = runner; + myDescriptor = descriptor; + myExecutor = executor; + // see IDEADEV-698 + } + + public void actionPerformed(final AnActionEvent e) { + ExecutionManager.getInstance(myEnvironment.getProject()).restartRunProfile(myEnvironment.getProject(), + myExecutor, + myEnvironment.getExecutionTarget(), + myEnvironment.getRunnerAndConfigurationSettings()); + } + + public void restart() { + doRestart(DataManager.getInstance().getDataContext(myDescriptor.getComponent())); + } + + private void doRestart(final DataContext dataContext) { + final Project project = PlatformDataKeys.PROJECT.getData(dataContext); + if (ExecutorRegistry.getInstance().isStarting(project, myExecutor.getId(), myRunner.getRunnerId())) { + return; + } + try { + final ExecutionEnvironment old = myEnvironment; + myRunner.execute(myExecutor, new ExecutionEnvironment(old.getRunProfile(), + old.getExecutionTarget(), + project, + old.getRunnerSettings(), + old.getConfigurationSettings(), + myDescriptor, + old.getRunnerAndConfigurationSettings())); + } + catch (RunCanceledByUserException ignore) { + } + catch (ExecutionException e1) { + Messages.showErrorDialog(project, e1.getMessage(), ExecutionBundle.message("restart.error.message.title")); + } + } + + public void update(final AnActionEvent event) { + final Presentation presentation = event.getPresentation(); + String name = myEnvironment.getRunProfile().getName(); + if (name.startsWith(ActionsBundle.message("action.RerunFailedTests.text"))) + name = myEnvironment.getRunnerAndConfigurationSettings().getName(); + presentation.setText(ExecutionBundle.message("rerun.configuration.action.name", name)); + final boolean isRunning = myProcessHandler != null && !myProcessHandler.isProcessTerminated(); + if (myProcessHandler != null && !isRunning) { + myProcessHandler = null; // already terminated + } + presentation.setIcon(isRunning ? STOP_AND_START_ICON : myIcon); + boolean isTerminating = myProcessHandler != null && myProcessHandler.isProcessTerminating(); + boolean isStarting = ExecutorRegistry.getInstance().isStarting(myEnvironment.getProject(), myExecutor.getId(), myRunner.getRunnerId()); + presentation.setEnabled(!isStarting && !isTerminating); + } + + public void registerShortcut(final JComponent component) { + registerCustomShortcutSet(new CustomShortcutSet(KeymapManager.getInstance().getActiveKeymap().getShortcuts(IdeActions.ACTION_RERUN)), + component); + } +}