RIDER-77734 Compound run configs are duplicated if it's started out of the toolbar
authoranna.gromova <anna.gromova@jetbrains.com>
Wed, 25 May 2022 15:45:54 +0000 (18:45 +0300)
committerintellij-monorepo-bot <intellij-monorepo-bot-no-reply@jetbrains.com>
Wed, 25 May 2022 16:06:50 +0000 (16:06 +0000)
GitOrigin-RevId: a3d44069ba7d4f0db37efc0347d870ee41dadaf2

15 files changed:
platform/execution-impl/src/com/intellij/execution/ExecutorRegistryImpl.java
platform/execution-impl/src/com/intellij/execution/actions/ChooseRunConfigurationPopup.java
platform/execution-impl/src/com/intellij/execution/compound/CompoundRunConfiguration.kt
platform/execution-impl/src/com/intellij/execution/runToolbar/RunToolbarData.kt
platform/execution-impl/src/com/intellij/execution/runToolbar/RunToolbarExtraSlotPane.kt
platform/execution-impl/src/com/intellij/execution/runToolbar/RunToolbarMainWidgetComponent.kt
platform/execution-impl/src/com/intellij/execution/runToolbar/RunToolbarProcessAction.kt
platform/execution-impl/src/com/intellij/execution/runToolbar/RunToolbarProcessMainAction.kt
platform/execution-impl/src/com/intellij/execution/runToolbar/RunToolbarRerunAction.kt
platform/execution-impl/src/com/intellij/execution/runToolbar/RunToolbarSlotManager.kt
platform/execution-impl/src/com/intellij/execution/runToolbar/data/RWWaitingForAProcesses.kt [deleted file]
platform/execution/src/com/intellij/execution/runToolbar/RunToolbarProcessData.kt [new file with mode: 0644]
platform/execution/src/com/intellij/execution/runners/ExecutionEnvironment.java
platform/execution/src/com/intellij/execution/runners/ExecutionUtil.java
platform/lang-impl/src/com/intellij/execution/dashboard/actions/ExecutorAction.java

index 3a59a516a80d90eb5dfe5eb74f2bb146ea69276d..fa3b7c1afb035bd9c857325fa3655e9b48405260 100644 (file)
@@ -11,6 +11,7 @@ import com.intellij.execution.impl.ExecutionManagerImpl;
 import com.intellij.execution.impl.ExecutionManagerImplKt;
 import com.intellij.execution.impl.RunnerAndConfigurationSettingsImpl;
 import com.intellij.execution.runToolbar.*;
+import com.intellij.execution.runners.ExecutionEnvironment;
 import com.intellij.execution.runners.ExecutionEnvironmentBuilder;
 import com.intellij.execution.runners.ExecutionUtil;
 import com.intellij.execution.runners.ProgramRunner;
@@ -49,6 +50,7 @@ import java.awt.event.InputEvent;
 import java.awt.event.MouseEvent;
 import java.util.List;
 import java.util.*;
+import java.util.function.Consumer;
 import java.util.function.Function;
 
 public final class ExecutorRegistryImpl extends ExecutorRegistry {
@@ -622,16 +624,27 @@ public final class ExecutorRegistryImpl extends ExecutorRegistry {
 
   public static final class RunnerHelper {
     public static void run(@NotNull Project project,
-                            @Nullable RunConfiguration configuration,
-                            @Nullable RunnerAndConfigurationSettings settings,
-                            @NotNull DataContext dataContext,
-                            @NotNull Executor executor) {
+                           @Nullable RunConfiguration configuration,
+                           @Nullable RunnerAndConfigurationSettings settings,
+                           @NotNull DataContext dataContext,
+                           @NotNull Executor executor) {
+
+      runSubProcess(project, configuration, settings, dataContext, executor, RunToolbarProcessData.prepareBaseSettingCustomization(settings, null));
+    }
+
+    public static void runSubProcess(@NotNull Project project,
+                                     @Nullable RunConfiguration configuration,
+                                     @Nullable RunnerAndConfigurationSettings settings,
+                                     @NotNull DataContext dataContext,
+                                     @NotNull Executor executor,
+                                     @Nullable Consumer<ExecutionEnvironment> environmentCustomization) {
+
       if (configuration instanceof CompoundRunConfiguration) {
         RunManager runManager = RunManager.getInstance(project);
         for (SettingsAndEffectiveTarget settingsAndEffectiveTarget : ((CompoundRunConfiguration)configuration)
           .getConfigurationsWithEffectiveRunTargets()) {
           RunConfiguration subConfiguration = settingsAndEffectiveTarget.getConfiguration();
-          run(project, subConfiguration, runManager.findSettings(subConfiguration), dataContext, executor);
+          runSubProcess(project, subConfiguration, runManager.findSettings(subConfiguration), dataContext, executor, environmentCustomization);
         }
       }
       else {
@@ -639,7 +652,9 @@ public final class ExecutorRegistryImpl extends ExecutorRegistry {
         if (builder == null) {
           return;
         }
-        ExecutionManager.getInstance(project).restartRunProfile(builder.activeTarget().dataContext(dataContext).build());
+        ExecutionEnvironment environment = builder.activeTarget().dataContext(dataContext).build();
+        if(environmentCustomization != null) environmentCustomization.accept(environment);
+        ExecutionManager.getInstance(project).restartRunProfile(environment);
       }
     }
 
index 216579e039a39012cd4500466b85e9bfd4ad4bdf..e4847626ea2cee2cd0625df8b05d41d3e850bac1 100644 (file)
@@ -378,7 +378,10 @@ public final class ChooseRunConfigurationPopup implements ExecutorProvider {
         @Override
         public void perform(@NotNull Project project, @NotNull Executor executor, @NotNull DataContext context) {
           RunnerAndConfigurationSettings config = getValue();
-          RunManager.getInstance(project).setSelectedConfiguration(config);
+
+          final RunManager manager = RunManager.getInstance(project);
+
+          if (!manager.isRunWidgetActive()) RunManager.getInstance(project).setSelectedConfiguration(config);
           MacroManager.getInstance().cacheMacrosPreview(context);
           ExecutionUtil.doRunConfiguration(config, executor, null, null, context);
         }
index 93ac8d794a64054b015a191cda8cb707fbedf89b..cfa9a184d88d64a400522992e0e7a356e6a27d02 100644 (file)
@@ -7,6 +7,7 @@ import com.intellij.execution.executors.DefaultRunExecutor
 import com.intellij.execution.impl.ExecutionManagerImpl
 import com.intellij.execution.impl.RunManagerImpl
 import com.intellij.execution.impl.compareTypesForUi
+import com.intellij.execution.runToolbar.RunToolbarProcessData
 import com.intellij.execution.runners.ExecutionEnvironment
 import com.intellij.execution.runners.ExecutionUtil
 import com.intellij.icons.AllIcons
@@ -119,11 +120,14 @@ class CompoundRunConfiguration @JvmOverloads constructor(@NlsSafe name: String?
 
     return RunProfileState { _, _ ->
       ApplicationManager.getApplication().invokeLater {
+        val compoundSettings = RunManagerImpl.getInstanceImpl(project).findSettings(this)
+
         val groupId = ExecutionEnvironment.getNextUnusedExecutionId()
         for ((configuration, target) in getConfigurationsWithEffectiveRunTargets()) {
           val settings = RunManagerImpl.getInstanceImpl(project).findSettings(configuration) ?: continue
-          ExecutionUtil.runConfiguration(settings, executor, target, groupId)
-        }
+          ExecutionUtil.doRunConfiguration(settings, executor, target, groupId,
+                                           null, RunToolbarProcessData.prepareBaseSettingCustomization(compoundSettings))}
+
       }
       null
     }
index 4bc27a27d89ce0021232dec392c47a8c59d22f84..9f0e2a394bdded76e5106f3ae93c7f2794fcf115 100644 (file)
@@ -7,7 +7,6 @@ import com.intellij.execution.impl.EditConfigurationsDialog
 import com.intellij.execution.impl.ProjectRunConfigurationConfigurable
 import com.intellij.execution.impl.RunConfigurable
 import com.intellij.execution.impl.SingleConfigurationConfigurable
-import com.intellij.execution.runToolbar.data.RWWaitingForAProcesses
 import com.intellij.execution.runners.ExecutionEnvironment
 import com.intellij.execution.ui.RunContentDescriptor
 import com.intellij.icons.AllIcons
@@ -31,9 +30,6 @@ interface RunToolbarData {
     @JvmField val RUN_TOOLBAR_POPUP_STATE_KEY: DataKey<Boolean> = DataKey.create("RUN_TOOLBAR_POPUP_STATE_KEY")
     @JvmField val RUN_TOOLBAR_MAIN_STATE: DataKey<RunToolbarMainSlotState> = DataKey.create("RUN_TOOLBAR_MAIN_STATE")
 
-    @ApiStatus.Internal
-    @JvmField val RUN_TOOLBAR_SUPPRESS_MAIN_SLOT_USER_DATA_KEY = Key<Boolean>("RUN_TOOLBAR_SUPPRESS_MAIN_SLOT_USER_DATA_KEY")
-
     internal fun prepareDescription(@Nls text: String, @Nls description: String): @Nls String {
       return HtmlBuilder().append(text)
           .br()
@@ -48,7 +44,6 @@ interface RunToolbarData {
   val id: String
   var configuration: RunnerAndConfigurationSettings?
   val environment: ExecutionEnvironment?
-  val waitingForAProcesses: RWWaitingForAProcesses
 
   fun clear()
 }
@@ -83,10 +78,6 @@ internal fun AnActionEvent.isActiveProcess(): Boolean {
   return this.environment() != null
 }
 
-fun RunToolbarData.startWaitingForAProcess(project: Project, settings: RunnerAndConfigurationSettings, executorId: String) {
-  RunToolbarSlotManager.getInstance(project).startWaitingForAProcess(this, settings, executorId)
-}
-
 internal fun AnActionEvent.setConfiguration(value: RunnerAndConfigurationSettings?) {
   this.runToolbarData()?.configuration = value
 }
index 3afada9bc9bd5d011292414e1fb09824c0bdb6ff..03fd7f75926bd3a696c790196308b357078c7509 100644 (file)
@@ -236,7 +236,9 @@ class RunToolbarExtraSlotPane(val project: Project, val baseWidth: () -> Int?):
       if(RunToolbarData.RUN_TOOLBAR_DATA_KEY.`is`(key)) {
         getData(component)
       }
-      else
+      else if(RunToolbarProcessData.RW_SLOT.`is`(key)) {
+        getData(component)?.id
+      } else
         null
     })
 
index 5647529c31ca33b2b184987ceb5ed3b1c56929dd..f775e2f8234d763228232613b8a75a599306c98a 100644 (file)
@@ -4,10 +4,7 @@ package com.intellij.execution.runToolbar
 import com.intellij.execution.runToolbar.data.RWSlotManagerState
 import com.intellij.execution.runToolbar.data.RWStateListener
 import com.intellij.ide.DataManager
-import com.intellij.openapi.actionSystem.ActionGroup
-import com.intellij.openapi.actionSystem.AnAction
-import com.intellij.openapi.actionSystem.DataProvider
-import com.intellij.openapi.actionSystem.Presentation
+import com.intellij.openapi.actionSystem.*
 import com.intellij.openapi.diagnostic.Logger
 import com.intellij.openapi.project.Project
 import com.intellij.openapi.util.Disposer
@@ -146,6 +143,9 @@ class RunToolbarMainWidgetComponent(val presentation: Presentation, place: Strin
     val slotManager = RunToolbarSlotManager.getInstance(project)
     DataManager.registerDataProvider(component, DataProvider { key ->
       when {
+        RunToolbarProcessData.RW_SLOT.`is`(key) -> {
+          slotManager.mainSlotData.id
+        }
         RunToolbarData.RUN_TOOLBAR_DATA_KEY.`is`(key) -> {
           slotManager.mainSlotData
         }
index a0703851d9c090f11879ad0028e6350d75aa89ea..8c8e192845b73f1f28304f8f3d23d00712752a8c 100644 (file)
@@ -25,9 +25,7 @@ open class RunToolbarProcessAction(override val process: RunToolbarProcess, val
     e.project?.let { project ->
       if (canRun(e)) {
         getSelectedConfiguration(e)?.let {
-          e.runToolbarData()?.startWaitingForAProcess(project, it, executor.id)
-
-          ExecutorRegistryImpl.RunnerHelper.run(project, it.configuration, it, e.dataContext, executor)
+           ExecutorRegistryImpl.RunnerHelper.run(project, it.configuration, it, e.dataContext, executor)
         }
       }
     }
index 39e0fd9da8a70d605cc20c342d0dd7837c28ada9..3871a60993f723301988f407c0b0d820a7dc71e1 100644 (file)
@@ -25,7 +25,6 @@ class RunToolbarProcessMainAction(process: RunToolbarProcess, executor: Executor
         getSelectedConfiguration(e)?.let {
           val slotManager = RunToolbarSlotManager.getInstance(project)
           val mainSlotData = slotManager.mainSlotData
-          mainSlotData.startWaitingForAProcess(project, it, executor.id)
 
           mainSlotData.environment?.let { environment ->
             MacroManager.getInstance().cacheMacrosPreview(e.getDataContext())
index 5592d90287ff25e402a6b5b7bd87209c27643897..47a3016b4d16322f2f5c4306b1c35b062574885f 100644 (file)
@@ -31,16 +31,6 @@ open class RunToolbarRerunAction : FakeRerunAction(), RTBarAction, DumbAware {
 
   override fun setShortcutSet(shortcutSet: ShortcutSet) {}
 
-  override fun actionPerformed(event: AnActionEvent) {
-    event.environment()?.let {
-      it.runnerAndConfigurationSettings?.let { settings ->
-        event.runToolbarData()?.startWaitingForAProcess(it.project, settings, it.executor.id)
-      }
-      super.actionPerformed(event)
-    }
-
-  }
-
   override fun getEnvironment(event: AnActionEvent): ExecutionEnvironment? {
     return event.environment()
   }
index 8ffe891f2e30caac779214ced7dadb5df64bdde3..fdb2089cf37de2be713eabd9858edcdd2a41e00b 100644 (file)
@@ -8,6 +8,7 @@ import com.intellij.execution.RunManagerListener
 import com.intellij.execution.RunnerAndConfigurationSettings
 import com.intellij.execution.compound.CompoundRunConfiguration
 import com.intellij.execution.impl.ExecutionManagerImpl
+import com.intellij.execution.impl.RunManagerImpl
 import com.intellij.execution.runToolbar.data.*
 import com.intellij.execution.runners.ExecutionEnvironment
 import com.intellij.ide.ActivityTracker
@@ -145,7 +146,7 @@ class RunToolbarSlotManager(val project: Project) {
 
   private fun getMoveNewOnTop(executionEnvironment: ExecutionEnvironment): Boolean {
     if (!runToolbarSettings.getMoveNewOnTop()) return false
-    val suppressValue = executionEnvironment.getUserData(RunToolbarData.RUN_TOOLBAR_SUPPRESS_MAIN_SLOT_USER_DATA_KEY) ?: false
+    val suppressValue = executionEnvironment.getUserData(RunToolbarProcessData.RUN_TOOLBAR_SUPPRESS_MAIN_SLOT_USER_DATA_KEY) ?: false
     return !suppressValue
   }
 
@@ -195,20 +196,6 @@ class RunToolbarSlotManager(val project: Project) {
     LOG.trace("!!!!!UPDATE RunToolbar")
   }
 
-  internal fun startWaitingForAProcess(slotDate: RunToolbarData, settings: RunnerAndConfigurationSettings, executorId: String) {
-    slotsData.values.forEach {
-      val waitingForAProcesses = it.waitingForAProcesses
-      if (slotDate == it) {
-        waitingForAProcesses.start(project, settings, executorId)
-      }
-      else {
-        if (waitingForAProcesses.isWaitingForASubProcess(settings, executorId)) {
-          waitingForAProcesses.clear()
-        }
-      }
-    }
-  }
-
   internal fun getMainOrFirstActiveProcess(): RunToolbarProcess? {
     return mainSlotData.environment?.getRunToolbarProcess() ?: activeProcesses.processes.keys.firstOrNull()
   }
@@ -254,18 +241,6 @@ class RunToolbarSlotManager(val project: Project) {
   }
 
   internal fun processNotStarted(env: ExecutionEnvironment) {
-    val config = env.runnerAndConfigurationSettings ?: return
-
-    val appropriateSettings = getAppropriateSettings(env)
-    val emptySlotsWithConfiguration = appropriateSettings.filter { it.environment == null }
-
-    emptySlotsWithConfiguration.map { it.waitingForAProcesses }.firstOrNull {
-      it.isWaitingForASingleProcess(config, env.executor.id)
-    }?.clear() ?: run {
-      slotsData.values.filter { it.configuration?.configuration is CompoundRunConfiguration }.firstOrNull { slotsData ->
-        slotsData.waitingForAProcesses.isWaitingForASubProcess(config, env.executor.id)
-      }?.clear()
-    }
   }
 
   internal fun processStarted(env: ExecutionEnvironment) {
@@ -284,7 +259,7 @@ class RunToolbarSlotManager(val project: Project) {
     val slot = appropriateSettings.firstOrNull { it.environment?.executionId == env.executionId }
                ?: emptySlotsWithConfiguration.firstOrNull { slotData ->
                  env.runnerAndConfigurationSettings?.let {
-                   slotData.waitingForAProcesses.isWaitingForASingleProcess(it, env.executor.id)
+                   slotData.id == env.dataContext?.getData(RunToolbarProcessData.RW_SLOT)
                  } ?: false
                }
                ?: emptySlotsWithConfiguration.firstOrNull()
@@ -297,11 +272,12 @@ class RunToolbarSlotManager(val project: Project) {
     activeProcesses.updateActiveProcesses(slotsData)
 
     if (newSlot) {
-      val isCompoundProcess = slotsData.values.filter { it.configuration?.configuration is CompoundRunConfiguration }.firstOrNull { slotsData ->
-        env.runnerAndConfigurationSettings?.let {
-          slotsData.waitingForAProcesses.checkAndUpdate(it, env.executor.id)
-        } ?: false
-      } != null
+
+      val runManager = RunManagerImpl.getInstanceImpl(project)
+
+      val isCompoundProcess = env.getUserData(RunToolbarProcessData.RW_MAIN_CONFIGURATION_ID)?.let {
+        runManager.getConfigurationById(it)?.configuration is CompoundRunConfiguration
+      } ?: false
 
       if (!isCompoundProcess) {
         if (getMoveNewOnTop(env)) {
@@ -516,16 +492,11 @@ internal open class SlotDate(override var id: String) : RunToolbarData {
         field = value
       value?.let {
         configuration = it.runnerAndConfigurationSettings
-      } ?: run {
-        waitingForAProcesses.clear()
       }
     }
 
-  override val waitingForAProcesses = RWWaitingForAProcesses()
-
   override fun clear() {
     environment = null
-    waitingForAProcesses.clear()
   }
 
   override fun toString(): String {
diff --git a/platform/execution-impl/src/com/intellij/execution/runToolbar/data/RWWaitingForAProcesses.kt b/platform/execution-impl/src/com/intellij/execution/runToolbar/data/RWWaitingForAProcesses.kt
deleted file mode 100644 (file)
index 8924ea6..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
-package com.intellij.execution.runToolbar.data
-
-import com.intellij.execution.RunManager
-import com.intellij.execution.RunnerAndConfigurationSettings
-import com.intellij.execution.compound.CompoundRunConfiguration
-import com.intellij.execution.configurations.RunConfiguration
-import com.intellij.openapi.project.Project
-
-class RWWaitingForAProcesses {
-  private var executorId: String? = null
-  private var settings: RunnerAndConfigurationSettings? = null
-  private val subSettingsList: MutableList<RunnerAndConfigurationSettings> = mutableListOf()
-
-  internal fun isWaitingForASingleProcess(settings: RunnerAndConfigurationSettings, executorId: String): Boolean {
-    return executorId == this.executorId && settings == this.settings && subSettingsList.isEmpty()
-  }
-
-  internal fun isWaitingForASubProcess(settings: RunnerAndConfigurationSettings, executorId: String): Boolean {
-    return subSettingsList.contains(settings) && executorId == this.executorId
-  }
-
-  internal fun start(project: Project, settings: RunnerAndConfigurationSettings, executorId: String) {
-    clear()
-    this.executorId = executorId
-    this.settings = settings
-    if (settings.configuration is CompoundRunConfiguration) {
-      collect(project, settings.configuration, settings)
-    }
-  }
-
-  internal fun clear() {
-    settings = null
-    executorId = null
-    subSettingsList.clear()
-  }
-
-  internal fun checkAndUpdate(settings: RunnerAndConfigurationSettings, executorId: String): Boolean {
-    if (executorId != this.executorId) return false
-    if (subSettingsList.remove(settings)) {
-      if (subSettingsList.isEmpty()) clear()
-      return true
-    }
-    return false
-  }
-
-  private fun collect(project: Project, configuration: RunConfiguration, settings: RunnerAndConfigurationSettings) {
-    if (configuration is CompoundRunConfiguration) {
-      val runManager = RunManager.getInstance(project)
-      for (settingsAndEffectiveTarget in configuration.getConfigurationsWithEffectiveRunTargets()) {
-        val subConfiguration: RunConfiguration = settingsAndEffectiveTarget.configuration
-        runManager.findSettings(subConfiguration)?.let {
-          collect(project, subConfiguration, it)
-        }
-      }
-    }
-    else {
-      subSettingsList.add(settings)
-    }
-  }
-}
\ No newline at end of file
diff --git a/platform/execution/src/com/intellij/execution/runToolbar/RunToolbarProcessData.kt b/platform/execution/src/com/intellij/execution/runToolbar/RunToolbarProcessData.kt
new file mode 100644 (file)
index 0000000..70381de
--- /dev/null
@@ -0,0 +1,56 @@
+// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
+package com.intellij.execution.runToolbar
+
+import com.intellij.execution.RunManager.Companion.getInstance
+import com.intellij.execution.RunnerAndConfigurationSettings
+import com.intellij.execution.runners.ExecutionEnvironment
+import com.intellij.openapi.actionSystem.DataKey
+import com.intellij.openapi.project.Project
+import com.intellij.openapi.util.Key
+import org.jetbrains.annotations.ApiStatus
+import java.util.function.Consumer
+
+class RunToolbarProcessData {
+  companion object {
+    @ApiStatus.Internal
+    @JvmField
+    val RW_SLOT = DataKey.create<String>("RunWidgetSlot")
+
+    @ApiStatus.Internal
+    @JvmField
+    val RW_MAIN_CONFIGURATION_ID = Key<String>("RunWidgetMainRunConfigurationId")
+
+    @ApiStatus.Internal
+    @JvmField
+    val RUN_TOOLBAR_SUPPRESS_MAIN_SLOT_USER_DATA_KEY = Key<Boolean>("RUN_TOOLBAR_SUPPRESS_MAIN_SLOT_USER_DATA_KEY")
+
+    @ApiStatus.Internal
+    @JvmStatic
+    fun prepareBaseSettingCustomization(settings: RunnerAndConfigurationSettings?, addition: Consumer<ExecutionEnvironment>? = null): Consumer<ExecutionEnvironment>? {
+      return settings?.let {
+        Consumer { ee: ExecutionEnvironment ->
+          ee.putUserData(RW_MAIN_CONFIGURATION_ID, settings.uniqueID)
+        }.mix(addition)
+      } ?: addition
+    }
+
+    @ApiStatus.Internal
+    @JvmStatic
+    fun prepareSuppressMainSlotCustomization(project: Project, addition: Consumer<ExecutionEnvironment>? = null): Consumer<ExecutionEnvironment> {
+      return Consumer { ee: ExecutionEnvironment ->
+        val runManager = getInstance(project)
+        if (runManager.isRunWidgetActive()) {
+          ee.putUserData(RUN_TOOLBAR_SUPPRESS_MAIN_SLOT_USER_DATA_KEY, true)
+        }
+      }
+    }
+
+    private fun Consumer<ExecutionEnvironment>.mix(addition: Consumer<ExecutionEnvironment>?): Consumer<ExecutionEnvironment> {
+      addition ?: return this
+      return Consumer { ee: ExecutionEnvironment ->
+        this.accept(ee)
+        addition.accept(ee)
+      }
+    }
+  }
+}
\ No newline at end of file
index 758a7e6b981d0e9ee2e3302cbe27dc2230e54ee2..275f3994fc80193647991394dc09ea713cd920b1 100644 (file)
@@ -6,6 +6,7 @@ import com.intellij.execution.configurations.ConfigurationPerRunnerSettings;
 import com.intellij.execution.configurations.RunProfile;
 import com.intellij.execution.configurations.RunProfileState;
 import com.intellij.execution.configurations.RunnerSettings;
+import com.intellij.execution.runToolbar.RunToolbarProcessData;
 import com.intellij.execution.target.*;
 import com.intellij.execution.ui.RunContentDescriptor;
 import com.intellij.openapi.Disposable;
@@ -279,7 +280,8 @@ public final class ExecutionEnvironment extends UserDataHolderBase implements Di
   }
 
   private static final class CachingDataContext implements DataContext {
-    private static final DataKey[] keys = {PROJECT, PROJECT_FILE_DIRECTORY, EDITOR, VIRTUAL_FILE, MODULE, PSI_FILE};
+    private static final DataKey[] keys = {PROJECT, PROJECT_FILE_DIRECTORY, EDITOR, VIRTUAL_FILE, MODULE, PSI_FILE,
+      RunToolbarProcessData.RW_SLOT};
     private final Map<String, Object> values = new HashMap<>();
 
     @NotNull
index a36114dbe9b172426c29d9f0db807584b641521f..40bfae83cd49b69f9172d4c50649ea59d1f42ed6 100644 (file)
@@ -36,6 +36,7 @@ import javax.swing.*;
 import javax.swing.event.HyperlinkEvent;
 import javax.swing.event.HyperlinkListener;
 import java.awt.*;
+import java.util.function.Consumer;
 import java.util.function.Function;
 
 public final class ExecutionUtil {
@@ -225,6 +226,15 @@ public final class ExecutionUtil {
                                         @Nullable ExecutionTarget targetOrNullForDefault,
                                         @Nullable Long executionId,
                                         @Nullable DataContext dataContext) {
+    doRunConfiguration(configuration, executor, targetOrNullForDefault, executionId, dataContext, null);
+  }
+
+  public static void doRunConfiguration(@NotNull RunnerAndConfigurationSettings configuration,
+                                        @NotNull Executor executor,
+                                        @Nullable ExecutionTarget targetOrNullForDefault,
+                                        @Nullable Long executionId,
+                                        @Nullable DataContext dataContext,
+                                        @Nullable Consumer<ExecutionEnvironment> environmentCustomization) {
     ExecutionEnvironmentBuilder builder = createEnvironment(executor, configuration);
     if (builder == null) {
       return;
@@ -242,7 +252,13 @@ public final class ExecutionUtil {
     if (dataContext != null) {
       builder.dataContext(dataContext);
     }
-    ExecutionManager.getInstance(configuration.getConfiguration().getProject()).restartRunProfile(builder.build());
+
+    ExecutionEnvironment environment = builder.build();
+    if(environmentCustomization != null) {
+      environmentCustomization.accept(environment);
+    }
+
+    ExecutionManager.getInstance(configuration.getConfiguration().getProject()).restartRunProfile(environment);
   }
 
   @Nullable
index dc5e8cdfd97b9a998a17d17cac0dff2c894240e6..a71832f63f8da3b224d110a37591b34e0853f2c4 100644 (file)
@@ -9,7 +9,7 @@ import com.intellij.execution.configurations.RuntimeConfigurationError;
 import com.intellij.execution.configurations.RuntimeConfigurationException;
 import com.intellij.execution.dashboard.RunDashboardRunConfigurationNode;
 import com.intellij.execution.process.ProcessHandler;
-import com.intellij.execution.runToolbar.RunToolbarData;
+import com.intellij.execution.runToolbar.RunToolbarProcessData;
 import com.intellij.execution.runners.ExecutionEnvironment;
 import com.intellij.execution.runners.ProgramRunner;
 import com.intellij.execution.ui.RunContentDescriptor;
@@ -27,6 +27,7 @@ import com.intellij.openapi.util.NlsActions;
 import com.intellij.ui.content.Content;
 import com.intellij.util.containers.JBIterable;
 import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
 
 import javax.swing.*;
 import java.util.List;
@@ -143,6 +144,10 @@ public abstract class ExecutorAction extends DumbAwareAction implements UpdateIn
   }
 
   private void run(RunnerAndConfigurationSettings settings, ExecutionTarget target, RunContentDescriptor descriptor) {
+    runSubProcess(settings, target, descriptor, RunToolbarProcessData.prepareBaseSettingCustomization(settings, null));
+  }
+
+  private void runSubProcess(RunnerAndConfigurationSettings settings, ExecutionTarget target, RunContentDescriptor descriptor, @Nullable Consumer<ExecutionEnvironment> envCustomization) {
     RunConfiguration configuration = settings.getConfiguration();
     Project project = configuration.getProject();
     RunManager runManager = RunManager.getInstance(project);
@@ -152,7 +157,7 @@ public abstract class ExecutorAction extends DumbAwareAction implements UpdateIn
       for (SettingsAndEffectiveTarget subConfiguration : subConfigurations) {
         RunnerAndConfigurationSettings subSettings = runManager.findSettings(subConfiguration.getConfiguration());
         if (subSettings != null) {
-          run(subSettings, subConfiguration.getTarget(), null);
+          runSubProcess(subSettings, subConfiguration.getTarget(), null, envCustomization);
         }
       }
     }
@@ -162,11 +167,8 @@ public abstract class ExecutorAction extends DumbAwareAction implements UpdateIn
         assert target != null : "No target for configuration of type " + configuration.getType().getDisplayName();
       }
       ProcessHandler processHandler = descriptor == null ? null : descriptor.getProcessHandler();
-      Consumer<ExecutionEnvironment> environmentCustomization =
-        runManager.isRunWidgetActive()
-        ? ee -> ee.putUserData(RunToolbarData.RUN_TOOLBAR_SUPPRESS_MAIN_SLOT_USER_DATA_KEY, true)
-        : null;
-      ExecutionManager.getInstance(project).restartRunProfile(project, getExecutor(), target, settings, processHandler, environmentCustomization);
+
+      ExecutionManager.getInstance(project).restartRunProfile(project, getExecutor(), target, settings, processHandler, RunToolbarProcessData.prepareSuppressMainSlotCustomization(project, envCustomization));
     }
   }