WEB-18808 'Rerun tests' (Alt+Shift+R) doesn't re-run tests
authorSergey Simonchik <sergey.simonchik@jetbrains.com>
Wed, 28 Oct 2015 21:12:03 +0000 (00:12 +0300)
committerSergey Simonchik <sergey.simonchik@jetbrains.com>
Wed, 28 Oct 2015 21:12:03 +0000 (00:12 +0300)
platform/lang-impl/src/com/intellij/execution/runners/RerunTestsAction.java

index 473a64c165396bbab8901a54709f9be0e040dcb7..144af31ab914b98a351acc4daa2b7a874366922e 100644 (file)
@@ -1,13 +1,18 @@
 package com.intellij.execution.runners;
 
+import com.intellij.execution.ExecutionManager;
+import com.intellij.execution.ui.RunContentDescriptor;
+import com.intellij.execution.ui.RunContentManager;
 import com.intellij.openapi.Disposable;
 import com.intellij.openapi.actionSystem.AnAction;
 import com.intellij.openapi.actionSystem.AnActionEvent;
 import com.intellij.openapi.project.DumbAwareAction;
+import com.intellij.openapi.project.Project;
 import com.intellij.openapi.util.Disposer;
 import com.intellij.util.containers.ContainerUtil;
 import org.jetbrains.annotations.NotNull;
 
+import java.util.List;
 import java.util.Set;
 
 /**
@@ -18,38 +23,52 @@ import java.util.Set;
  * Thus it can be convenient for rerunning tests, because running non-test execution session after
  * running test execution session won't hide the latter.
  *
- * @author Sergey Simonchik
+ * @see RerunTestsNotification
  */
 public class RerunTestsAction extends DumbAwareAction implements AnAction.TransparentUpdate {
   public static final String ID = "RerunTests";
-  private static final Set<ExecutionEnvironment> REGISTRY = ContainerUtil.newHashSet();
+  private static final Set<RunContentDescriptor> REGISTRY = ContainerUtil.newHashSet();
 
-  public static void register(@NotNull final ExecutionEnvironment environment) {
-    if (REGISTRY.add(environment)) {
-      Disposer.register(environment, new Disposable() {
+  public static void register(@NotNull final RunContentDescriptor descriptor) {
+    if (!Disposer.isDisposed(descriptor) && REGISTRY.add(descriptor)) {
+      Disposer.register(descriptor, new Disposable() {
         @Override
         public void dispose() {
-          REGISTRY.remove(environment);
+          REGISTRY.remove(descriptor);
         }
       });
     }
   }
 
+  /**
+   * @deprecated use {@link #register(RunContentDescriptor)} instead
+   */
+  @SuppressWarnings("UnusedParameters")
+  public static void register(@NotNull ExecutionEnvironment environment) {
+  }
+
   @Override
   public void actionPerformed(@NotNull AnActionEvent e) {
-    ExecutionEnvironment[] environments = REGISTRY.toArray(new ExecutionEnvironment[REGISTRY.size()]);
-    for (ExecutionEnvironment environment : environments) {
-      if (Disposer.isDisposed(environment)) {
-        REGISTRY.remove(environment);
+    List<RunContentDescriptor> descriptors = ContainerUtil.newArrayList(REGISTRY);
+    for (RunContentDescriptor descriptor : descriptors) {
+      if (Disposer.isDisposed(descriptor)) {
+        REGISTRY.remove(descriptor);
       }
-      else if (environment.getProject() == e.getProject()) {
-        ExecutionUtil.restart(environment);
+      else {
+        Project project = e.getProject();
+        if (project != null) {
+          RunContentManager runContentManager = ExecutionManager.getInstance(project).getContentManager();
+          // check if the descriptor belongs to the current project
+          if (runContentManager.getToolWindowByDescriptor(descriptor) != null) {
+            ExecutionUtil.restart(descriptor);
+          }
+        }
       }
     }
   }
 
   @Override
   public void update(@NotNull AnActionEvent e) {
-    e.getPresentation().setEnabled(true);
+    e.getPresentation().setEnabled(e.getProject() != null);
   }
 }