CR-IC-6033#CFR-89039 fix usages instead of just use "fix" method, remove it from...
authorVladimir Krivosheev <vladimir.krivosheev@jetbrains.com>
Tue, 12 Aug 2014 17:54:53 +0000 (19:54 +0200)
committerVladimir Krivosheev <vladimir.krivosheev@jetbrains.com>
Tue, 12 Aug 2014 17:57:35 +0000 (19:57 +0200)
27 files changed:
java/debugger/impl/src/com/intellij/debugger/DebuggerManagerEx.java
java/debugger/impl/src/com/intellij/debugger/DefaultDebugUIEnvironment.java
java/debugger/impl/src/com/intellij/debugger/impl/DebuggerManagerImpl.java
java/debugger/impl/src/com/intellij/debugger/impl/GenericDebuggerRunner.java
java/debugger/impl/src/com/intellij/debugger/ui/DebuggerPanelsManager.java
java/debugger/impl/src/com/intellij/debugger/ui/DebuggerSessionTab.java
platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/execution/ExternalSystemTaskDebugRunner.java
platform/lang-api/src/com/intellij/execution/runners/ExecutionEnvironment.java
platform/lang-api/src/com/intellij/execution/runners/ExecutionEnvironmentBuilder.java
platform/lang-api/src/com/intellij/execution/runners/ExecutionUtil.java
platform/lang-api/src/com/intellij/execution/ui/RunContentManager.java
platform/lang-impl/src/com/intellij/execution/ProgramRunnerUtil.java
platform/lang-impl/src/com/intellij/execution/impl/ExecutionManagerImpl.java
platform/lang-impl/src/com/intellij/execution/runners/AbstractConsoleRunnerWithHistory.java
platform/lang-impl/src/com/intellij/execution/runners/FakeRerunAction.java
platform/lang-impl/src/com/intellij/execution/runners/RerunTestsAction.java
platform/lang-impl/src/com/intellij/execution/runners/RestartAction.java
platform/lang-impl/src/com/intellij/execution/runners/RunContentBuilder.java
platform/lang-impl/src/com/intellij/execution/ui/RunContentManagerImpl.java
platform/platform-impl/src/com/intellij/ui/content/impl/ContentImpl.java
platform/xdebugger-impl/src/com/intellij/xdebugger/impl/XDebuggerManagerImpl.java
platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/XDebugSessionTab.java
plugins/groovy/src/org/jetbrains/plugins/groovy/griffon/GriffonDebuggerRunner.java
plugins/maven/src/main/java/org/jetbrains/idea/maven/execution/MavenRunConfigurationType.java
plugins/maven/src/main/java/org/jetbrains/idea/maven/navigator/actions/MavenRunConfigurationMenu.java
plugins/terminal/src/org/jetbrains/plugins/terminal/AbstractTerminalRunner.java
python/src/com/jetbrains/python/console/PythonToolWindowConsoleRunner.java

index 12c26117216eeecca66d62974996afc78824cbfd..d14e554fd99edae0fc314520aac95921e7daec81 100644 (file)
@@ -24,6 +24,7 @@ import com.intellij.debugger.ui.breakpoints.BreakpointManager;
 import com.intellij.execution.ExecutionException;
 import com.intellij.openapi.project.Project;
 import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
 
 import java.util.Collection;
 
@@ -42,5 +43,6 @@ public abstract class DebuggerManagerEx extends DebuggerManager {
   public abstract void addDebuggerManagerListener(DebuggerManagerListener debuggerManagerListener);
   public abstract void removeDebuggerManagerListener(DebuggerManagerListener debuggerManagerListener);
 
+  @Nullable
   public abstract DebuggerSession attachVirtualMachine(@NotNull DebugEnvironment environment) throws ExecutionException;
 }
index b664da2f6e6eb6bb3cd590a67ca9fbd2a0928553..ef2af94a48c88c1543608f0739295a3560db9250 100644 (file)
@@ -44,10 +44,7 @@ public class DefaultDebugUIEnvironment implements DebugUIEnvironment {
                                    RemoteConnection remoteConnection,
                                    boolean pollConnection) {
     myExecutionEnvironment = environment;
-    myModelEnvironment = new DefaultDebugEnvironment(environment,
-                                                     state,
-                                                     remoteConnection,
-                                                     pollConnection);
+    myModelEnvironment = new DefaultDebugEnvironment(environment, state, remoteConnection, pollConnection);
   }
 
   @Override
index a5c40cc4b45ddd69386c675caa662254d5bd1144..60c0d2dded3dcc420a8182a01cc01abd70c8d0ca 100644 (file)
@@ -205,6 +205,7 @@ public class DebuggerManagerImpl extends DebuggerManagerEx implements Persistent
   }
 
   @Override
+  @Nullable
   public DebuggerSession attachVirtualMachine(@NotNull DebugEnvironment environment) throws ExecutionException {
     ApplicationManager.getApplication().assertIsDispatchThread();
     final DebugProcessEvents debugProcess = new DebugProcessEvents(myProject);
@@ -282,7 +283,6 @@ public class DebuggerManagerImpl extends DebuggerManagerEx implements Persistent
     return session;
   }
 
-
   @Override
   public DebugProcessImpl getDebugProcess(final ProcessHandler processHandler) {
     synchronized (mySessions) {
index 3140423a0f62324d0905f5213e933e0e485bf933..c6491a2b8a3fbed0d5600c488322b4ac18a4113c 100644 (file)
@@ -59,56 +59,43 @@ public class GenericDebuggerRunner extends JavaPatchableProgramRunner<GenericDeb
   }
 
   @Override
-  protected RunContentDescriptor doExecute(@NotNull final Project project,
-                                           @NotNull final RunProfileState state,
-                                           final RunContentDescriptor contentToReuse,
-                                           @NotNull final ExecutionEnvironment env) throws ExecutionException {
+  protected RunContentDescriptor doExecute(@NotNull Project project,
+                                           @NotNull RunProfileState state,
+                                           @Nullable RunContentDescriptor contentToReuse,
+                                           @NotNull ExecutionEnvironment env) throws ExecutionException {
     FileDocumentManager.getInstance().saveAllDocuments();
-    return createContentDescriptor(project, state, contentToReuse, env);
+    return createContentDescriptor(state, contentToReuse == null || env.getContentToReuse() == contentToReuse
+                                          ? env
+                                          : new ExecutionEnvironmentBuilder(env).contentToReuse(contentToReuse).build());
   }
 
   @Nullable
-  protected RunContentDescriptor createContentDescriptor(Project project, RunProfileState state,
-                                                         RunContentDescriptor contentToReuse,
-                                                         ExecutionEnvironment environment) throws ExecutionException {
-    environment = ExecutionEnvironmentBuilder.fix(environment, contentToReuse);
+  protected RunContentDescriptor createContentDescriptor(@NotNull RunProfileState state, @NotNull ExecutionEnvironment environment) throws ExecutionException {
     if (state instanceof JavaCommandLine) {
       final JavaParameters parameters = ((JavaCommandLine)state).getJavaParameters();
       runCustomPatchers(parameters, environment.getExecutor(), environment.getRunProfile());
       RemoteConnection connection = DebuggerManagerImpl.createDebugParameters(parameters, true, DebuggerSettings.getInstance().DEBUGGER_TRANSPORT, "", false);
-      return attachVirtualMachine(project, state, environment, connection, true);
+      return attachVirtualMachine(state, environment, connection, true);
     }
     if (state instanceof PatchedRunnableState) {
       final RemoteConnection connection = doPatch(new JavaParameters(), environment.getRunnerSettings());
-      return attachVirtualMachine(project, state, environment, connection, true);
+      return attachVirtualMachine(state, environment, connection, true);
     }
     if (state instanceof RemoteState) {
       final RemoteConnection connection = createRemoteDebugConnection((RemoteState)state, environment.getRunnerSettings());
-      return attachVirtualMachine(project, state, environment, connection, false);
+      return attachVirtualMachine(state, environment, connection, false);
     }
 
     return null;
   }
 
   @Nullable
-  @Deprecated
-  protected RunContentDescriptor attachVirtualMachine(@NotNull Project project,
-                                                      RunProfileState state,
-                                                      RunContentDescriptor contentToReuse,
-                                                      ExecutionEnvironment environment,
-                                                      RemoteConnection connection,
-                                                      boolean pollConnection) throws ExecutionException {
-    return attachVirtualMachine(project, state, ExecutionEnvironmentBuilder.fix(environment, contentToReuse), connection, pollConnection);
-  }
-
-  @Nullable
-  protected RunContentDescriptor attachVirtualMachine(@NotNull Project project,
-                                                      RunProfileState state,
-                                                      ExecutionEnvironment env,
+  protected RunContentDescriptor attachVirtualMachine(RunProfileState state,
+                                                      @NotNull ExecutionEnvironment env,
                                                       RemoteConnection connection,
                                                       boolean pollConnection) throws ExecutionException {
     DebugEnvironment environment = new DefaultDebugUIEnvironment(env, state, connection, pollConnection).getEnvironment();
-    final DebuggerSession debuggerSession = DebuggerManagerEx.getInstanceEx(project).attachVirtualMachine(environment);
+    final DebuggerSession debuggerSession = DebuggerManagerEx.getInstanceEx(env.getProject()).attachVirtualMachine(environment);
     if (debuggerSession == null) {
       return null;
     }
@@ -124,7 +111,7 @@ public class GenericDebuggerRunner extends JavaPatchableProgramRunner<GenericDeb
       debugProcess.putUserData(BatchEvaluator.REMOTE_SESSION_KEY, Boolean.TRUE);
     }
 
-    return XDebuggerManager.getInstance(project).startSession(env, new XDebugProcessStarter() {
+    return XDebuggerManager.getInstance(env.getProject()).startSession(env, new XDebugProcessStarter() {
       @Override
       @NotNull
       public XDebugProcess start(@NotNull XDebugSession session) {
index 76c2aa4e1d6f06ab70cc132d5081a8e14cb0fcff..895adf5c82892563028befd42a04d221cac03bd3 100644 (file)
@@ -108,13 +108,11 @@ public class DebuggerPanelsManager implements ProjectComponent {
                                                    RunContentDescriptor reuseContent,
                                                    RemoteConnection remoteConnection,
                                                    boolean pollConnection) throws ExecutionException {
-    if (executor != environment.getExecutor()) {
-      // fix invalid environment
-      environment = new ExecutionEnvironmentBuilder(environment).executor(executor).build();
-    }
-    environment = ExecutionEnvironmentBuilder.fix(environment, runner);
-    environment = ExecutionEnvironmentBuilder.fix(environment, reuseContent);
-    return attachVirtualMachine(environment, state, remoteConnection, pollConnection);
+    return attachVirtualMachine(new ExecutionEnvironmentBuilder(environment)
+                                  .executor(executor)
+                                  .runner(runner)
+                                  .contentToReuse(reuseContent)
+                                  .build(), state, remoteConnection, pollConnection);
   }
 
   @Nullable
index 600efd834e56e31f8de8db34f76bbf87798f3935..1878d842f602c1c6acf9f850e34f33930b7ade11 100644 (file)
@@ -72,7 +72,7 @@ import javax.swing.tree.TreePath;
 import java.util.List;
 
 public class DebuggerSessionTab extends DebuggerSessionTabBase implements Disposable {
-  private static final Logger LOG = Logger.getInstance("#com.intellij.debugger.ui.DebuggerSessionTab");
+  private static final Logger LOG = Logger.getInstance(DebuggerSessionTab.class);
 
   private final VariablesPanel myVariablesPanel;
   private final MainWatchPanel myWatchPanel;
@@ -90,6 +90,7 @@ public class DebuggerSessionTab extends DebuggerSessionTabBase implements Dispos
   public DebuggerSessionTab(final Project project, final String sessionName, @NotNull final DebugUIEnvironment environment,
                             @NotNull DebuggerSession debuggerSession) {
     super(project, "JavaDebugger", sessionName, debuggerSession.getSearchScope());
+
     myDebuggerSession = debuggerSession;
     myDebugUIEnvironment = environment;
 
@@ -129,11 +130,9 @@ public class DebuggerSessionTab extends DebuggerSessionTabBase implements Dispos
     topToolbar.add(Separator.getInstance(), new Constraints(Anchor.AFTER, DebuggerActions.POP_FRAME));
     myUi.getOptions().setTopToolbar(topToolbar, ActionPlaces.DEBUGGER_TOOLBAR);
 
-
     myWatchPanel = new MainWatchPanel(getProject(), getContextManager());
     myFramesPanel = new FramesPanel(getProject(), getContextManager());
 
-
     final AlertIcon breakpointAlert = new AlertIcon(AllIcons.Debugger.BreakpointAlert);
 
     // watches
@@ -348,7 +347,6 @@ public class DebuggerSessionTab extends DebuggerSessionTabBase implements Dispos
     if (action != null) group.add(action);
   }
 
-
   @Override
   public void dispose() {
     disposeSession();
index 1d18bf96bef829b9e36c4dcd5aeb3c88022566d4..86d1b6138f0db4c0a93e0683b75956d54bc534f2 100644 (file)
@@ -25,7 +25,6 @@ import com.intellij.execution.runners.ExecutionEnvironment;
 import com.intellij.execution.ui.RunContentDescriptor;
 import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.externalSystem.util.ExternalSystemConstants;
-import com.intellij.openapi.project.Project;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
@@ -34,8 +33,7 @@ import org.jetbrains.annotations.Nullable;
  * @since 6/7/13 11:18 AM
  */
 public class ExternalSystemTaskDebugRunner extends GenericDebuggerRunner {
-
-  private static final Logger LOG = Logger.getInstance("#" + ExternalSystemTaskDebugRunner.class.getName());
+  private static final Logger LOG = Logger.getInstance(ExternalSystemTaskDebugRunner.class);
 
   @NotNull
   @Override
@@ -50,16 +48,12 @@ public class ExternalSystemTaskDebugRunner extends GenericDebuggerRunner {
 
   @Nullable
   @Override
-  protected RunContentDescriptor createContentDescriptor(Project project,
-                                                         RunProfileState state,
-                                                         RunContentDescriptor contentToReuse,
-                                                         ExecutionEnvironment environment) throws ExecutionException
-  {
+  protected RunContentDescriptor createContentDescriptor(@NotNull RunProfileState state, @NotNull ExecutionEnvironment environment) throws ExecutionException {
     if (state instanceof ExternalSystemRunConfiguration.MyRunnableState) {
       int port = ((ExternalSystemRunConfiguration.MyRunnableState)state).getDebugPort();
       if (port > 0) {
         RemoteConnection connection = new RemoteConnection(true, "127.0.0.1", String.valueOf(port), true);
-        return attachVirtualMachine(project, state, contentToReuse, environment, connection, true);
+        return attachVirtualMachine(state, environment, connection, true);
       }
       else {
         LOG.warn("Can't attach debugger to external system task execution. Reason: target debug port is unknown");
index 99b6bda8f566fc5739fad6a515db0dc0c06773b2..cbec1b0fd0492e93f8e6def465cb5e838ded5c99 100644 (file)
@@ -38,7 +38,7 @@ import java.util.concurrent.atomic.AtomicLong;
 
 import static com.intellij.openapi.actionSystem.LangDataKeys.*;
 
-public class ExecutionEnvironment extends UserDataHolderBase {
+public class ExecutionEnvironment extends UserDataHolderBase implements Disposable {
   private static final AtomicLong myIdHolder = new AtomicLong(1L);
 
   @NotNull private final Project myProject;
@@ -52,7 +52,7 @@ public class ExecutionEnvironment extends UserDataHolderBase {
   @Nullable private final RunnerAndConfigurationSettings myRunnerAndConfigurationSettings;
   @Nullable private RunContentDescriptor myContentToReuse;
   @Nullable private String myRunnerId;
-  @Nullable final ProgramRunner<?> runner;
+  @Nullable final ProgramRunner<?> myRunner;
   private long myExecutionId = 0;
   @Nullable private DataContext myDataContext;
 
@@ -62,7 +62,7 @@ public class ExecutionEnvironment extends UserDataHolderBase {
     myContentToReuse = null;
     myRunnerAndConfigurationSettings = null;
     myExecutor = null;
-    runner = null;
+    myRunner = null;
   }
 
   public ExecutionEnvironment(@NotNull Executor executor,
@@ -133,20 +133,16 @@ public class ExecutionEnvironment extends UserDataHolderBase {
     myRunnerSettings = runnerSettings;
     myConfigurationSettings = configurationSettings;
     myProject = project;
-    myContentToReuse = contentToReuse;
+    setContentToReuse(contentToReuse);
     myRunnerAndConfigurationSettings = settings;
 
-    this.runner = runner;
+    myRunner = runner;
     myRunnerId = runner == null ? runnerId : runner.getRunnerId();
+  }
 
-    if (myContentToReuse != null) {
-      Disposer.register(myContentToReuse, new Disposable() {
-        @Override
-        public void dispose() {
-          myContentToReuse = null;
-        }
-      });
-    }
+  @Override
+  public void dispose() {
+    myContentToReuse = null;
   }
 
   @NotNull
@@ -174,6 +170,14 @@ public class ExecutionEnvironment extends UserDataHolderBase {
     return myContentToReuse;
   }
 
+  public void setContentToReuse(@Nullable RunContentDescriptor contentToReuse) {
+    myContentToReuse = contentToReuse;
+
+    if (contentToReuse != null) {
+      Disposer.register(contentToReuse, this);
+    }
+  }
+
   @Nullable
   public String getRunnerId() {
     return myRunnerId;
@@ -181,7 +185,7 @@ public class ExecutionEnvironment extends UserDataHolderBase {
 
   @Nullable
   public ProgramRunner<?> getRunner() {
-    return runner == null ? RunnerRegistry.getInstance().findRunnerById(getRunnerId()) : runner;
+    return myRunner == null ? RunnerRegistry.getInstance().findRunnerById(getRunnerId()) : myRunner;
   }
 
   @Nullable
index 43cf7d44373f82d86563bc536e3806cb14dcfa41..ae45632459aa0d4ae221d527ef4d0bf7fa5bfeed 100644 (file)
@@ -39,7 +39,7 @@ public final class ExecutionEnvironmentBuilder {
   @Nullable private RunContentDescriptor myContentToReuse;
   @Nullable private RunnerAndConfigurationSettings myRunnerAndConfigurationSettings;
   @Nullable private String myRunnerId;
-  private ProgramRunner<?> runner;
+  private ProgramRunner<?> myRunner;
   private boolean myAssignNewId;
   @NotNull private Executor myExecutor;
   @Nullable private DataContext myDataContext;
@@ -61,7 +61,7 @@ public final class ExecutionEnvironmentBuilder {
   @NotNull
   public static ExecutionEnvironmentBuilder create(@NotNull Executor executor, @NotNull RunnerAndConfigurationSettings settings) throws ExecutionException {
     ExecutionEnvironmentBuilder builder = create(settings.getConfiguration().getProject(), executor, settings.getConfiguration());
-    return builder.runnerAndSettings(builder.runner, settings);
+    return builder.runnerAndSettings(builder.myRunner, settings);
   }
 
   @NotNull
@@ -82,31 +82,11 @@ public final class ExecutionEnvironmentBuilder {
     myRunnerSettings = copySource.getRunnerSettings();
     myConfigurationSettings = copySource.getConfigurationSettings();
     myRunnerId = copySource.getRunnerId();
-    runner = copySource.runner;
+    myRunner = copySource.myRunner;
     myContentToReuse = copySource.getContentToReuse();
     myExecutor = copySource.getExecutor();
   }
 
-  @NotNull
-  public static ExecutionEnvironment fix(@NotNull ExecutionEnvironment environment, @Nullable RunContentDescriptor contentToReuse) {
-    if (contentToReuse == null || environment.getContentToReuse() == contentToReuse) {
-      return environment;
-    }
-    else {
-      return new ExecutionEnvironmentBuilder(environment).contentToReuse(contentToReuse).build();
-    }
-  }
-
-  @NotNull
-  public static ExecutionEnvironment fix(@NotNull ExecutionEnvironment environment, @Nullable ProgramRunner runner) {
-    if (runner == null || runner.getRunnerId().equals(environment.getRunnerId())) {
-      return environment;
-    }
-    else {
-      return new ExecutionEnvironmentBuilder(environment).runner(runner).build();
-    }
-  }
-
   @SuppressWarnings("UnusedDeclaration")
   @Deprecated
   /**
@@ -144,7 +124,7 @@ public final class ExecutionEnvironmentBuilder {
     myRunProfile = settings.getConfiguration();
     myRunnerSettings = settings.getRunnerSettings(runner);
     myConfigurationSettings = settings.getConfigurationSettings(runner);
-    this.runner = runner;
+    myRunner = runner;
     return this;
   }
 
@@ -208,7 +188,7 @@ public final class ExecutionEnvironmentBuilder {
   }
 
   public ExecutionEnvironmentBuilder runner(@NotNull ProgramRunner<?> runner) {
-    this.runner = runner;
+    myRunner = runner;
     return this;
   }
 
@@ -247,12 +227,12 @@ public final class ExecutionEnvironmentBuilder {
 
   @NotNull
   public ExecutionEnvironment build() {
-    if (runner == null && myRunnerId == null) {
-      runner = RunnerRegistry.getInstance().getRunner(myExecutor.getId(), myRunProfile);
+    if (myRunner == null && myRunnerId == null) {
+      myRunner = RunnerRegistry.getInstance().getRunner(myExecutor.getId(), myRunProfile);
     }
 
     ExecutionEnvironment environment = new ExecutionEnvironment(myRunProfile, myExecutor, myTarget, myProject, myRunnerSettings, myConfigurationSettings, myContentToReuse,
-                                                                myRunnerAndConfigurationSettings, myRunnerId, runner);
+                                                                myRunnerAndConfigurationSettings, myRunnerId, myRunner);
     if (myAssignNewId) {
       environment.assignNewExecutionId();
     }
index 29f0f1c59bc2c76a6bae54703b4e828e6a72133c..10640776ba9ae70d17e2bdc2e8db0510eb9706ed 100644 (file)
@@ -19,7 +19,6 @@ package com.intellij.execution.runners;
 import com.intellij.execution.*;
 import com.intellij.execution.configurations.RunProfile;
 import com.intellij.execution.process.ProcessNotCreatedException;
-import com.intellij.execution.ui.RunContentDescriptor;
 import com.intellij.ide.util.PropertiesComponent;
 import com.intellij.notification.NotificationGroup;
 import com.intellij.notification.NotificationListener;
@@ -113,12 +112,8 @@ public class ExecutionUtil {
   }
 
   public static void restart(@NotNull ExecutionEnvironment environment) {
-    restart(environment, null);
-  }
-
-  public static void restart(@NotNull ExecutionEnvironment environment, @Nullable RunContentDescriptor contentDescriptor) {
     if (!ExecutorRegistry.getInstance().isStarting(environment)) {
-      ExecutionManager.getInstance(environment.getProject()).restartRunProfile(ExecutionEnvironmentBuilder.fix(environment, contentDescriptor));
+      ExecutionManager.getInstance(environment.getProject()).restartRunProfile(environment);
     }
   }
 
index 94acfeebfbb9d183527c7a0d2efeb1a5293f1522..b9f649378acb48234f32b66805e830c805942335 100644 (file)
@@ -39,9 +39,11 @@ public interface RunContentManager {
 
   @NotNull
   List<RunContentDescriptor> getAllDescriptors();
+
   /**
    * to reduce number of open contents RunContentManager reuses
-   * some of them during showRunContent (for ex. if a process was stopped) 
+   * some of them during showRunContent (for ex. if a process was stopped)
+   *
    * @return content that will be reused by showRunContent
    * @deprecated use {@link #getReuseContent(com.intellij.execution.Executor, ExecutionEnvironment)}
    */
@@ -68,15 +70,20 @@ public interface RunContentManager {
   @Nullable
   RunContentDescriptor findContentDescriptor(Executor requestor, ProcessHandler handler);
 
-  void showRunContent(@NotNull Executor executor, RunContentDescriptor descriptor, RunContentDescriptor contentToReuse);
-  void showRunContent(@NotNull Executor executor, RunContentDescriptor descriptor);
+  void showRunContent(@NotNull Executor executor, @NotNull RunContentDescriptor descriptor, @Nullable RunContentDescriptor contentToReuse);
+
+  void showRunContent(@NotNull Executor executor, @NotNull RunContentDescriptor descriptor);
+
   void hideRunContent(@NotNull Executor executor, RunContentDescriptor descriptor);
+
   boolean removeRunContent(@NotNull Executor executor, RunContentDescriptor descriptor);
 
   void toFrontRunContent(Executor requestor, RunContentDescriptor descriptor);
+
   void toFrontRunContent(Executor requestor, ProcessHandler handler);
 
   void addRunContentListener(RunContentListener listener);
+
   void removeRunContentListener(RunContentListener listener);
 
   void addRunContentListener(RunContentListener myContentListener, Executor executor);
index fbe7b9aafaf62347557a3825f03645da63f59db8..b4334218ff24ae1623cbcc54aabe0b9d2a0c10eb 100644 (file)
@@ -113,21 +113,20 @@ public class ProgramRunnerUtil {
   public static void executeConfiguration(@NotNull Project project,
                                           @NotNull RunnerAndConfigurationSettings configuration,
                                           @NotNull Executor executor) {
-    ProgramRunner runner = getRunner(executor.getId(), configuration);
-    if (runner == null) {
-      LOG.error("Runner MUST not be null! Cannot find runner for " +
-                executor.getId() +
-                " and " +
-                configuration.getConfiguration().getFactory().getName());
+    ExecutionEnvironmentBuilder builder;
+    try {
+      builder = ExecutionEnvironmentBuilder.create(executor, configuration);
+    }
+    catch (ExecutionException e) {
+      LOG.error(e);
       return;
     }
-    ExecutionEnvironment environment = new ExecutionEnvironmentBuilder(project, executor)
-      .runnerAndSettings(runner, configuration)
-      .contentToReuse(null)
-      .dataContext(null)
-      .target(ExecutionTargetManager.getActiveTarget(project))
-      .build();
-    executeConfiguration(environment, true, true);
+
+    executeConfiguration(builder
+                           .contentToReuse(null)
+                           .dataContext(null)
+                           .activeTarget()
+                           .build(), true, true);
   }
 
   public static Icon getConfigurationIcon(final RunnerAndConfigurationSettings settings,
index 7dd4e119740e12ff459355fe9ad9ec1bff553e82..d0c8637af03a0375bb92d6bab21da630cb628b7f 100644 (file)
@@ -13,7 +13,6 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package com.intellij.execution.impl;
 
 import com.intellij.CommonBundle;
@@ -42,6 +41,7 @@ import com.intellij.openapi.project.DumbService;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.ui.DialogWrapper;
 import com.intellij.openapi.ui.Messages;
+import com.intellij.openapi.util.Condition;
 import com.intellij.openapi.util.Disposer;
 import com.intellij.openapi.util.Key;
 import com.intellij.openapi.util.Trinity;
@@ -51,12 +51,11 @@ import com.intellij.ui.docking.DockManager;
 import com.intellij.util.Alarm;
 import com.intellij.util.SmartList;
 import com.intellij.util.containers.ContainerUtil;
-import com.intellij.util.containers.Predicate;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
 import javax.swing.*;
-import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 
 /**
@@ -199,7 +198,7 @@ public class ExecutionManagerImpl extends ExecutionManager implements ProjectCom
                               @NotNull final RunProfileState state,
                               @NotNull final ExecutionEnvironment environment) {
     final Project project = environment.getProject();
-    final RunContentDescriptor reuseContent = ExecutionManager.getInstance(project).getContentManager().getReuseContent(environment);
+    final RunContentDescriptor reuseContent = getContentManager().getReuseContent(environment);
     if (reuseContent != null) {
       reuseContent.setExecutionId(environment.getExecutionId());
     }
@@ -220,8 +219,8 @@ public class ExecutionManagerImpl extends ExecutionManager implements ProjectCom
           project.getMessageBus().syncPublisher(EXECUTION_TOPIC).processStarting(executor.getId(), environment);
 
           final RunContentDescriptor descriptor = starter.execute(project, executor, state, reuseContent, environment);
-
           if (descriptor != null) {
+            environment.setContentToReuse(descriptor);
             final Trinity<RunContentDescriptor, RunnerAndConfigurationSettings, Executor> trinity =
               Trinity.create(descriptor, environment.getRunnerAndConfigurationSettings(), executor);
             myRunningConfigurations.add(trinity);
@@ -231,7 +230,7 @@ public class ExecutionManagerImpl extends ExecutionManager implements ProjectCom
                 myRunningConfigurations.remove(trinity);
               }
             });
-            ExecutionManager.getInstance(project).getContentManager().showRunContent(executor, descriptor, reuseContent);
+            getContentManager().showRunContent(executor, descriptor, reuseContent);
             final ProcessHandler processHandler = descriptor.getProcessHandler();
             if (processHandler != null) {
               if (!processHandler.isStartNotified()) {
@@ -325,53 +324,60 @@ public class ExecutionManagerImpl extends ExecutionManager implements ProjectCom
     restartRunProfile(builder.build());
   }
 
+  public static boolean isProcessRunning(@Nullable RunContentDescriptor descriptor) {
+    ProcessHandler processHandler = descriptor == null ? null : descriptor.getProcessHandler();
+    return processHandler != null && !processHandler.isProcessTerminated();
+  }
+
   @Override
   public void restartRunProfile(@NotNull final ExecutionEnvironment environment) {
-    final List<RunContentDescriptor> runningConfigurationsOfTheSameType = new ArrayList<RunContentDescriptor>();
-    final List<RunContentDescriptor> runningIncompatibleConfigurations = new ArrayList<RunContentDescriptor>();
-
     RunnerAndConfigurationSettings configuration = environment.getRunnerAndConfigurationSettings();
-    if (configuration != null) {
-      runningIncompatibleConfigurations.addAll(getIncompatibleRunningDescriptors(configuration));
+
+    List<RunContentDescriptor> runningIncompatible;
+    if (configuration == null) {
+      runningIncompatible = Collections.emptyList();
+    }
+    else {
+      runningIncompatible = getIncompatibleRunningDescriptors(configuration);
     }
+
+    RunContentDescriptor contentToReuse = environment.getContentToReuse();
+    final List<RunContentDescriptor> runningOfTheSameType = new SmartList<RunContentDescriptor>();
     if (configuration != null && configuration.isSingleton()) {
-      runningConfigurationsOfTheSameType.addAll(getRunningDescriptorsOfTheSameConfigType(configuration));
+      runningOfTheSameType.addAll(getRunningDescriptorsOfTheSameConfigType(configuration));
     }
-    else if (environment.getContentToReuse() != null) {
-      runningConfigurationsOfTheSameType.add(environment.getContentToReuse());
+    else if (isProcessRunning(contentToReuse)) {
+      runningOfTheSameType.add(contentToReuse);
     }
 
-    final List<RunContentDescriptor> runningConfigurationsToStop = ContainerUtil.concat(runningConfigurationsOfTheSameType,
-                                                                                        runningIncompatibleConfigurations);
-    if (!runningConfigurationsToStop.isEmpty()) {
+    List<RunContentDescriptor> runningToStop = ContainerUtil.concat(runningOfTheSameType, runningIncompatible);
+    if (!runningToStop.isEmpty()) {
       if (configuration != null) {
-        if (!runningConfigurationsOfTheSameType.isEmpty()
-            && (runningConfigurationsOfTheSameType.size() > 1 ||
-                environment.getContentToReuse() == null ||
-                runningConfigurationsOfTheSameType.get(0) != environment.getContentToReuse()) &&
-            !userApprovesStopForSameTypeConfigurations(environment.getProject(), configuration.getName(), runningConfigurationsOfTheSameType.size())) {
+        if (!runningOfTheSameType.isEmpty()
+            && (runningOfTheSameType.size() > 1 || contentToReuse == null || runningOfTheSameType.get(0) != contentToReuse) &&
+            !userApprovesStopForSameTypeConfigurations(environment.getProject(), configuration.getName(), runningOfTheSameType.size())) {
           return;
         }
-        if (!runningIncompatibleConfigurations.isEmpty()
-            && !userApprovesStopForIncompatibleConfigurations(myProject, configuration.getName(), runningIncompatibleConfigurations)) {
+        if (!runningIncompatible.isEmpty()
+            && !userApprovesStopForIncompatibleConfigurations(myProject, configuration.getName(), runningIncompatible)) {
           return;
         }
       }
-      for (RunContentDescriptor descriptor : runningConfigurationsToStop) {
+
+      for (RunContentDescriptor descriptor : runningToStop) {
         stop(descriptor);
       }
     }
 
-    Runnable runnable = new Runnable() {
-      ProgramRunner runner = environment.getRunner();
-
+    awaitingTerminationAlarm.addRequest(new Runnable() {
       @Override
       public void run() {
-        if (runner != null && ExecutorRegistry.getInstance().isStarting(environment)) {
+        if (environment.getRunner() != null && ExecutorRegistry.getInstance().isStarting(environment)) {
           awaitingTerminationAlarm.addRequest(this, 100);
           return;
         }
-        for (RunContentDescriptor descriptor : runningConfigurationsOfTheSameType) {
+
+        for (RunContentDescriptor descriptor : runningOfTheSameType) {
           ProcessHandler processHandler = descriptor.getProcessHandler();
           if (processHandler != null && !processHandler.isProcessTerminated()) {
             awaitingTerminationAlarm.addRequest(this, 100);
@@ -380,25 +386,20 @@ public class ExecutionManagerImpl extends ExecutionManager implements ProjectCom
         }
         start(environment);
       }
-    };
-    awaitingTerminationAlarm.addRequest(runnable, 50);
+    }, 50);
   }
 
   private static void start(@NotNull ExecutionEnvironment environment) {
-    if (environment.getRunner() != null) {
-      ProgramRunnerUtil.executeConfiguration(environment,
-                                             environment.getRunnerAndConfigurationSettings() != null && environment.getRunnerAndConfigurationSettings().isEditBeforeRun(),
-                                             false);
-    }
-    else if (environment.getRunnerAndConfigurationSettings() != null) {
-      ProgramRunnerUtil.executeConfiguration(environment, true, true);
-    }
-    else {
+    if (environment.getRunner() == null) {
       Runnable restarter = environment.getContentToReuse() == null ? null : environment.getContentToReuse().getRestarter();
       if (restarter != null) {
         restarter.run();
       }
     }
+    else {
+      RunnerAndConfigurationSettings settings = environment.getRunnerAndConfigurationSettings();
+      ProgramRunnerUtil.executeConfiguration(environment, settings != null && settings.isEditBeforeRun(), true);
+    }
   }
 
   private static boolean userApprovesStopForSameTypeConfigurations(Project project, String configName, int instancesCount) {
@@ -498,35 +499,36 @@ public class ExecutionManagerImpl extends ExecutionManager implements ProjectCom
       Messages.getQuestionIcon(), option) == Messages.OK;
   }
 
-  private List<RunContentDescriptor> getRunningDescriptorsOfTheSameConfigType(
-    @NotNull final RunnerAndConfigurationSettings configurationAndSettings) {
-    return getRunningDescriptors(new Predicate<RunnerAndConfigurationSettings>() {
+  @NotNull
+  private List<RunContentDescriptor> getRunningDescriptorsOfTheSameConfigType(@NotNull final RunnerAndConfigurationSettings configurationAndSettings) {
+    return getRunningDescriptors(new Condition<RunnerAndConfigurationSettings>() {
       @Override
-      public boolean apply(@Nullable RunnerAndConfigurationSettings runningConfigurationAndSettings) {
+      public boolean value(@Nullable RunnerAndConfigurationSettings runningConfigurationAndSettings) {
         return configurationAndSettings == runningConfigurationAndSettings;
       }
     });
   }
 
-  private List<RunContentDescriptor> getIncompatibleRunningDescriptors(
-    @NotNull final RunnerAndConfigurationSettings configurationAndSettings) {
+  @NotNull
+  private List<RunContentDescriptor> getIncompatibleRunningDescriptors(@NotNull RunnerAndConfigurationSettings configurationAndSettings) {
     final RunConfiguration configurationToCheckCompatibility = configurationAndSettings.getConfiguration();
-    return getRunningDescriptors(new Predicate<RunnerAndConfigurationSettings>() {
+    return getRunningDescriptors(new Condition<RunnerAndConfigurationSettings>() {
       @Override
-      public boolean apply(@Nullable RunnerAndConfigurationSettings runningConfigurationAndSettings) {
-        if (runningConfigurationAndSettings == null) return false;
-        RunConfiguration runningConfiguration = runningConfigurationAndSettings.getConfiguration();
-        if (runningConfiguration == null || !(runningConfiguration instanceof CompatibilityAwareRunProfile)) return false;
+      public boolean value(@Nullable RunnerAndConfigurationSettings runningConfigurationAndSettings) {
+        RunConfiguration runningConfiguration = runningConfigurationAndSettings == null ? null : runningConfigurationAndSettings.getConfiguration();
+        if (runningConfiguration == null || !(runningConfiguration instanceof CompatibilityAwareRunProfile)) {
+          return false;
+        }
         return ((CompatibilityAwareRunProfile)runningConfiguration).mustBeStoppedToRun(configurationToCheckCompatibility);
       }
     });
   }
 
-  private List<RunContentDescriptor> getRunningDescriptors(
-    Predicate<RunnerAndConfigurationSettings> condition) {
-    List<RunContentDescriptor> result = new ArrayList<RunContentDescriptor>();
+  @NotNull
+  private List<RunContentDescriptor> getRunningDescriptors(@NotNull Condition<RunnerAndConfigurationSettings> condition) {
+    List<RunContentDescriptor> result = new SmartList<RunContentDescriptor>();
     for (Trinity<RunContentDescriptor, RunnerAndConfigurationSettings, Executor> trinity : myRunningConfigurations) {
-      if (condition.apply(trinity.getSecond())) {
+      if (condition.value(trinity.getSecond())) {
         ProcessHandler processHandler = trinity.getFirst().getProcessHandler();
         if (processHandler != null && !processHandler.isProcessTerminating() && !processHandler.isProcessTerminated()) {
           result.add(trinity.getFirst());
@@ -536,21 +538,24 @@ public class ExecutionManagerImpl extends ExecutionManager implements ProjectCom
     return result;
   }
 
-  private static void stop(RunContentDescriptor runContentDescriptor) {
-    ProcessHandler processHandler = runContentDescriptor != null ? runContentDescriptor.getProcessHandler() : null;
+  private static void stop(@Nullable RunContentDescriptor descriptor) {
+    ProcessHandler processHandler = descriptor != null ? descriptor.getProcessHandler() : null;
     if (processHandler == null) {
       return;
     }
+
     if (processHandler instanceof KillableProcess && processHandler.isProcessTerminating()) {
       ((KillableProcess)processHandler).killProcess();
       return;
     }
 
-    if (processHandler.detachIsDefault()) {
-      processHandler.detachProcess();
-    }
-    else {
-      processHandler.destroyProcess();
+    if (!processHandler.isProcessTerminated()) {
+      if (processHandler.detachIsDefault()) {
+        processHandler.detachProcess();
+      }
+      else {
+        processHandler.destroyProcess();
+      }
     }
   }
 
index b4b3cd919ec47e13cd23d20874337ec3849a7c61..7bcabebf256a55a8531e106fe277124235a4c0a6 100644 (file)
@@ -173,7 +173,7 @@ public abstract class AbstractConsoleRunnerWithHistory<T extends LanguageConsole
     return false;
   }
 
-  protected void showConsole(Executor defaultExecutor, RunContentDescriptor contentDescriptor) {
+  protected void showConsole(Executor defaultExecutor, @NotNull RunContentDescriptor contentDescriptor) {
     // Show in run toolwindow
     ExecutionManager.getInstance(myProject).getContentManager().showRunContent(defaultExecutor, contentDescriptor);
   }
index 30058177c853028b9d88ed9beb8e5b76e7d7831d..ecc8fa553121e6cbbb003dbf15c3d10b8f1ab928 100644 (file)
@@ -17,6 +17,7 @@ package com.intellij.execution.runners;
 
 import com.intellij.execution.ExecutionBundle;
 import com.intellij.execution.ExecutorRegistry;
+import com.intellij.execution.impl.ExecutionManagerImpl;
 import com.intellij.execution.process.ProcessHandler;
 import com.intellij.execution.ui.RunContentDescriptor;
 import com.intellij.icons.AllIcons;
@@ -49,10 +50,7 @@ class FakeRerunAction extends AnAction implements DumbAware {
     ExecutionEnvironment environment = getEnvironment(event);
     if (environment != null) {
       presentation.setText(ExecutionBundle.message("rerun.configuration.action.name", environment.getRunProfile().getName()));
-
-      RunContentDescriptor descriptor = getDescriptor(event);
-      ProcessHandler processHandler = descriptor == null ? null : descriptor.getProcessHandler();
-      presentation.setIcon(processHandler != null && !processHandler.isProcessTerminated() ? AllIcons.Actions.Restart : environment.getExecutor().getIcon());
+      presentation.setIcon(ExecutionManagerImpl.isProcessRunning(getDescriptor(event)) ? AllIcons.Actions.Restart : environment.getExecutor().getIcon());
       presentation.setEnabledAndVisible(isEnabled(event));
       return;
     }
@@ -66,7 +64,7 @@ class FakeRerunAction extends AnAction implements DumbAware {
   public void actionPerformed(AnActionEvent event) {
     ExecutionEnvironment environment = getEnvironment(event);
     if (environment != null) {
-      ExecutionUtil.restart(environment, getDescriptor(event));
+      ExecutionUtil.restart(environment);
       return;
     }
 
index 1ab1f5b592d15b20d3e858f50c865bd95a9a5aac..e73cf8cd992fa1a3e5cc9ec492a551da5b0da943 100644 (file)
@@ -3,9 +3,9 @@ package com.intellij.execution.runners;
 import com.intellij.execution.process.ProcessHandler;
 import com.intellij.execution.ui.RunContentDescriptor;
 import com.intellij.openapi.Disposable;
-import com.intellij.openapi.actionSystem.*;
+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;
@@ -23,34 +23,28 @@ import java.util.List;
  * @author Sergey Simonchik
  */
 public class RerunTestsAction extends DumbAwareAction implements AnAction.TransparentUpdate {
-
   public static final String ID = "RerunTests";
-  private static final List<RerunInfo> REGISTRY = ContainerUtil.createLockFreeCopyOnWriteList();
+  private static final List<ExecutionEnvironment> REGISTRY = ContainerUtil.createLockFreeCopyOnWriteList();
 
-  public static void register(@NotNull RunContentDescriptor descriptor, @NotNull ExecutionEnvironment environment) {
-    final RerunInfo rerunInfo = new RerunInfo(descriptor, environment);
-    REGISTRY.add(rerunInfo);
-    Disposer.register(descriptor, new Disposable() {
+  public static void register(@NotNull final ExecutionEnvironment environment) {
+    assert environment.getContentToReuse() != null;
+    REGISTRY.add(environment);
+    Disposer.register(environment, new Disposable() {
       @Override
       public void dispose() {
-        REGISTRY.remove(rerunInfo);
+        REGISTRY.remove(environment);
       }
     });
   }
 
   @Override
   public void actionPerformed(AnActionEvent e) {
-    DataContext dataContext = e.getDataContext();
-    Project project = CommonDataKeys.PROJECT.getData(dataContext);
-    if (project == null) {
-      return;
-    }
-    for (RerunInfo rerunInfo : REGISTRY) {
-      RunContentDescriptor descriptor = rerunInfo.getDescriptor();
-      if (!Disposer.isDisposed(descriptor)) {
-        ProcessHandler processHandler = descriptor.getProcessHandler();
+    for (ExecutionEnvironment environment : REGISTRY) {
+      if (!Disposer.isDisposed(environment)) {
+        RunContentDescriptor descriptor = environment.getContentToReuse();
+        ProcessHandler processHandler = descriptor == null ? null : descriptor.getProcessHandler();
         if (processHandler != null && processHandler.isProcessTerminated()) {
-          ExecutionUtil.restart(rerunInfo.getEnvironment(), descriptor);
+          ExecutionUtil.restart(environment);
         }
       }
     }
@@ -58,25 +52,6 @@ public class RerunTestsAction extends DumbAwareAction implements AnAction.Transp
 
   @Override
   public void update(AnActionEvent e) {
-    Presentation presentation = e.getPresentation();
-    presentation.setEnabled(true);
-  }
-
-  private static class RerunInfo {
-    private final RunContentDescriptor myDescriptor;
-    private final ExecutionEnvironment myEnv;
-
-    public RerunInfo(@NotNull RunContentDescriptor descriptor, @NotNull ExecutionEnvironment env) {
-      myDescriptor = descriptor;
-      myEnv = env;
-    }
-
-    private RunContentDescriptor getDescriptor() {
-      return myDescriptor;
-    }
-
-    private ExecutionEnvironment getEnvironment() {
-      return myEnv;
-    }
+    e.getPresentation().setEnabled(true);
   }
 }
index 52d404eff8b8cc357e6910b4ee3574d5875b4082..1ab3cee3c8cb5dd7766e81926068082b7eb2eaa9 100644 (file)
@@ -35,8 +35,8 @@ import javax.swing.*;
  * to remove in IDEA 15
  */
 public class RestartAction extends FakeRerunAction implements DumbAware, AnAction.TransparentUpdate, Disposable {
-  private final RunContentDescriptor descriptor;
-  private final ExecutionEnvironment environment;
+  private final RunContentDescriptor myDescriptor;
+  private final ExecutionEnvironment myEnvironment;
 
   public RestartAction(@NotNull RunContentDescriptor descriptor, @NotNull ExecutionEnvironment environment) {
     //noinspection deprecation
@@ -55,9 +55,9 @@ public class RestartAction extends FakeRerunAction implements DumbAware, AnActio
     Disposer.register(descriptor, this);
     FakeRerunAction.registry.add(this);
 
-    this.environment = runner == null ? environment : ExecutionEnvironmentBuilder.fix(environment, runner);
+    myEnvironment = runner == null ? environment : RunContentBuilder.fix(environment, runner);
     getTemplatePresentation().setEnabled(false);
-    this.descriptor = descriptor;
+    myDescriptor = descriptor;
   }
 
   @Override
@@ -68,13 +68,13 @@ public class RestartAction extends FakeRerunAction implements DumbAware, AnActio
   @Override
   @NotNull
   protected RunContentDescriptor getDescriptor(AnActionEvent event) {
-    return descriptor;
+    return myDescriptor;
   }
 
   @Override
   @NotNull
   protected ExecutionEnvironment getEnvironment(AnActionEvent event) {
-    return environment;
+    return myEnvironment;
   }
 
   public void registerShortcut(JComponent component) {
index 06a24c2896488fc1421eebba53caef652669fda3..527e95d1bd5ea802dd0028c29e1b4d8fda5ac08f 100644 (file)
@@ -78,7 +78,7 @@ public class RunContentBuilder extends LogConsoleManagerBase {
   public RunContentBuilder(ProgramRunner runner,
                            ExecutionResult executionResult,
                            @NotNull ExecutionEnvironment environment) {
-    this(executionResult, ExecutionEnvironmentBuilder.fix(environment, runner));
+    this(executionResult, fix(environment, runner));
   }
 
   public RunContentBuilder(ExecutionResult executionResult, @NotNull ExecutionEnvironment environment) {
@@ -89,6 +89,16 @@ public class RunContentBuilder extends LogConsoleManagerBase {
     setEnvironment(environment);
   }
 
+  @NotNull
+  public static ExecutionEnvironment fix(@NotNull ExecutionEnvironment environment, @Nullable ProgramRunner runner) {
+    if (runner == null || runner.getRunnerId().equals(environment.getRunnerId())) {
+      return environment;
+    }
+    else {
+      return new ExecutionEnvironmentBuilder(environment).runner(runner).build();
+    }
+  }
+
   @Deprecated
   @NotNull
   public static GlobalSearchScope createSearchScope(Project project, RunProfile runProfile) {
@@ -195,7 +205,7 @@ public class RunContentBuilder extends LogConsoleManagerBase {
     consoleContent.setActions(consoleActions, ActionPlaces.UNKNOWN, console.getComponent());
   }
 
-  private ActionGroup createActionToolbar(final RunContentDescriptor contentDescriptor, final JComponent component) {
+  private ActionGroup createActionToolbar(RunContentDescriptor contentDescriptor, final JComponent component) {
     final DefaultActionGroup actionGroup = new DefaultActionGroup();
 
     final RestartAction restartAction = new RestartAction(contentDescriptor, getEnvironment());
@@ -204,7 +214,7 @@ public class RunContentBuilder extends LogConsoleManagerBase {
     contentDescriptor.setRestarter(new Runnable() {
       @Override
       public void run() {
-        ExecutionUtil.restart(getEnvironment(), contentDescriptor);
+        ExecutionUtil.restart(getEnvironment());
       }
     });
 
@@ -255,12 +265,7 @@ public class RunContentBuilder extends LogConsoleManagerBase {
    */
   public RunContentDescriptor showRunContent(@Nullable RunContentDescriptor reuseContent) {
     RunContentDescriptor descriptor = createDescriptor();
-    if (reuseContent != null) {
-      descriptor.setAttachedContent(reuseContent.getAttachedContent());
-      if (reuseContent.isReuseToolWindowActivation()) {
-        descriptor.setActivateToolWindowWhenAdded(reuseContent.isActivateToolWindowWhenAdded());
-      }
-    }
+    RunContentManagerImpl.copyContentAndBehavior(descriptor, reuseContent);
     return descriptor;
   }
 
index 07bb2184e1e4de6a1e38d99a1a3b334e3181003e..815122796028e20fa48205e683f17dda5fa7385e 100644 (file)
@@ -269,32 +269,30 @@ public class RunContentManagerImpl implements RunContentManager, Disposable {
   }
 
   @Override
-  public void showRunContent(@NotNull final Executor executor, final RunContentDescriptor descriptor) {
-    showRunContent(executor, descriptor, descriptor != null ? descriptor.getExecutionId() : 0L);
+  public void showRunContent(@NotNull Executor executor, @NotNull RunContentDescriptor descriptor) {
+    showRunContent(executor, descriptor, descriptor.getExecutionId());
   }
 
-  public void showRunContent(@NotNull final Executor executor, final RunContentDescriptor descriptor, long executionId) {
-    if (ApplicationManager.getApplication().isUnitTestMode()) return;
+  public void showRunContent(@NotNull final Executor executor, @NotNull final RunContentDescriptor descriptor, long executionId) {
+    if (ApplicationManager.getApplication().isUnitTestMode()) {
+      return;
+    }
 
     final ContentManager contentManager = getContentManagerForRunner(executor);
-    RunContentDescriptor oldDescriptor =
-      chooseReuseContentForDescriptor(contentManager, descriptor, executionId, descriptor != null ? descriptor.getDisplayName() : null);
-
+    RunContentDescriptor oldDescriptor = chooseReuseContentForDescriptor(contentManager, descriptor, executionId, descriptor.getDisplayName());
     final Content content;
-
     Content oldAttachedContent = oldDescriptor == null ? null : oldDescriptor.getAttachedContent();
-    if (oldDescriptor != null) {
-      content = oldAttachedContent;
-      getSyncPublisher().contentRemoved(oldDescriptor, executor);
-      Disposer.dispose(oldDescriptor); // is of the same category, can be reused
-    }
-    else if (oldAttachedContent == null || !oldAttachedContent.isValid() /*|| oldAttachedContent.getUserData(MARKED_TO_BE_REUSED) != null */) {
+    if (oldDescriptor == null) {
       content = createNewContent(contentManager, descriptor, executor);
-      final Icon icon = descriptor.getIcon();
+      Icon icon = descriptor.getIcon();
       content.setIcon(icon == null ? executor.getToolWindowIcon() : icon);
-    } else {
+    }
+    else {
       content = oldAttachedContent;
+      getSyncPublisher().contentRemoved(oldDescriptor, executor);
+      Disposer.dispose(oldDescriptor); // is of the same category, can be reused
     }
+
     content.setExecutionId(executionId);
     content.setComponent(descriptor.getComponent());
     content.setPreferredFocusedComponent(descriptor.getPreferredFocusComputable());
@@ -342,10 +340,10 @@ public class RunContentManagerImpl implements RunContentManager, Disposable {
     if (!descriptor.isActivateToolWindowWhenAdded()) {
       return;
     }
+
     ApplicationManager.getApplication().invokeLater(new Runnable() {
       @Override
       public void run() {
-        if (myProject.isDisposed()) return;
         ToolWindow window = ToolWindowManager.getInstance(myProject).getToolWindow(executor.getToolWindowId());
         // let's activate tool window, but don't move focus
         //
@@ -356,7 +354,7 @@ public class RunContentManagerImpl implements RunContentManager, Disposable {
         descriptor.getPreferredFocusComputable();
         window.activate(null, descriptor.isAutoFocusContent(), descriptor.isAutoFocusContent());
       }
-    });
+    }, myProject.getDisposed());
   }
 
   @Override
@@ -406,14 +404,21 @@ public class RunContentManagerImpl implements RunContentManager, Disposable {
   }
 
   @Override
-  public void showRunContent(@NotNull Executor info, RunContentDescriptor descriptor, @Nullable RunContentDescriptor contentToReuse) {
+  public void showRunContent(@NotNull Executor info, @NotNull RunContentDescriptor descriptor, @Nullable RunContentDescriptor contentToReuse) {
+    copyContentAndBehavior(descriptor, contentToReuse);
+    showRunContent(info, descriptor, descriptor.getExecutionId());
+  }
+
+  public static void copyContentAndBehavior(@NotNull RunContentDescriptor descriptor, @Nullable RunContentDescriptor contentToReuse) {
     if (contentToReuse != null) {
       Content attachedContent = contentToReuse.getAttachedContent();
-      if (attachedContent.getManager() != null) {
+      if (attachedContent.isValid()) {
         descriptor.setAttachedContent(attachedContent);
       }
+      if (contentToReuse.isReuseToolWindowActivation()) {
+        descriptor.setActivateToolWindowWhenAdded(contentToReuse.isActivateToolWindowWhenAdded());
+      }
     }
-    showRunContent(info, descriptor, descriptor != null ? descriptor.getExecutionId(): 0L);
   }
 
   @Nullable
@@ -429,7 +434,9 @@ public class RunContentManagerImpl implements RunContentManager, Disposable {
       }
       //Stage two: try to get content from descriptor itself
       final Content attachedContent = descriptor.getAttachedContent();
-      if (attachedContent != null && attachedContent.isValid() && contentManager.getIndexOfContent(attachedContent) != -1) content = attachedContent;
+      if (attachedContent != null && attachedContent.isValid() && contentManager.getIndexOfContent(attachedContent) != -1) {
+        content = attachedContent;
+      }
     }
     //Stage three: choose the content with name we prefer
     if (content == null) {
index 221aa694799040e7be96c98d63b91c5463c49524..595a93db592f88141339f77bfde5b90f85e0dd47 100644 (file)
@@ -44,7 +44,7 @@ public class ContentImpl extends UserDataHolderBase implements Content {
   private JComponent myComponent;
   private Icon myIcon;
   private final PropertyChangeSupport myChangeSupport = new PropertyChangeSupport(this);
-  private ContentManager myManager = null;
+  private ContentManager myManager;
   private boolean myIsLocked = false;
   private boolean myPinnable = true;
   private Icon myLayeredIcon = new LayeredIcon(2);
index 37baa02ca74e3d0b4c5817594a0578f7de1c164e..91e9194edcd32ff7718533195da960a99bee0c6a 100644 (file)
@@ -22,8 +22,8 @@ import com.intellij.execution.Executor;
 import com.intellij.execution.executors.DefaultDebugExecutor;
 import com.intellij.execution.process.ProcessHandler;
 import com.intellij.execution.runners.ExecutionEnvironment;
-import com.intellij.execution.runners.ExecutionEnvironmentBuilder;
 import com.intellij.execution.runners.ProgramRunner;
+import com.intellij.execution.runners.RunContentBuilder;
 import com.intellij.execution.ui.ExecutionConsole;
 import com.intellij.execution.ui.RunContentDescriptor;
 import com.intellij.execution.ui.RunContentManagerImpl;
@@ -174,7 +174,7 @@ public class XDebuggerManagerImpl extends XDebuggerManager
                                     @NotNull ExecutionEnvironment environment,
                                     @Nullable RunContentDescriptor contentToReuse,
                                     @NotNull XDebugProcessStarter processStarter) throws ExecutionException {
-    return startSession(contentToReuse, processStarter, new XDebugSessionImpl(ExecutionEnvironmentBuilder.fix(environment, runner), this));
+    return startSession(contentToReuse, processStarter, new XDebugSessionImpl(RunContentBuilder.fix(environment, runner), this));
   }
 
   @Override
index 6734edd3e8385e7c58cc11a1f859f3135eede03a..0a5fc9e18d9d2a62419e651726f9d70f8e06f9e7 100644 (file)
@@ -77,22 +77,21 @@ public class XDebugSessionTab extends DebuggerSessionTabBase implements DataProv
       if (component != null) {
         XDebugSessionTab oldTab = TAB_KEY.getData(DataManager.getInstance().getDataContext(component));
         if (oldTab != null) {
-          oldTab.setSession(session, environment, contentToReuse, icon);
+          oldTab.setSession(session, environment, icon);
           oldTab.attachToSession();
           return oldTab;
         }
       }
     }
-    return new XDebugSessionTab(session, icon, environment, contentToReuse);
+    return new XDebugSessionTab(session, icon, environment);
   }
 
   private XDebugSessionTab(@NotNull XDebugSessionImpl session,
-                          @Nullable Icon icon,
-                          @Nullable ExecutionEnvironment environment,
-                          @Nullable RunContentDescriptor contentToReuse) {
+                           @Nullable Icon icon,
+                           @Nullable ExecutionEnvironment environment) {
     super(session.getProject(), "Debug", session.getSessionName(), GlobalSearchScope.allScope(session.getProject()));
 
-    setSession(session, environment, contentToReuse, icon);
+    setSession(session, environment, icon);
 
     myUi.addContent(createFramesContent(), 0, PlaceInGrid.left, false);
     myUi.addContent(createVariablesContent(), 0, PlaceInGrid.center, false);
@@ -126,7 +125,7 @@ public class XDebugSessionTab extends DebuggerSessionTabBase implements DataProv
     rebuildViews();
   }
 
-  private void setSession(@NotNull XDebugSessionImpl session, @Nullable ExecutionEnvironment environment, @Nullable RunContentDescriptor contentToReuse, @Nullable Icon icon) {
+  private void setSession(@NotNull XDebugSessionImpl session, @Nullable ExecutionEnvironment environment, @Nullable Icon icon) {
     if (environment != null) {
       setEnvironment(environment);
     }
@@ -134,9 +133,6 @@ public class XDebugSessionTab extends DebuggerSessionTabBase implements DataProv
     this.session = session;
     myConsole = session.getConsoleView();
     myRunContentDescriptor = new RunContentDescriptor(myConsole, session.getDebugProcess().getProcessHandler(), myUi.getComponent(), session.getSessionName(), icon);
-    if (contentToReuse != null && contentToReuse.isReuseToolWindowActivation()) {
-      myRunContentDescriptor.setActivateToolWindowWhenAdded(contentToReuse.isActivateToolWindowWhenAdded());
-    }
   }
 
   @Nullable
index 2bdcf1c166e562f87c4fb0099cd01661afef137b..2d424b2f58d98abb85c9255fc042831fe3aeff15 100644 (file)
@@ -22,7 +22,6 @@ import com.intellij.execution.configurations.*;
 import com.intellij.execution.executors.DefaultDebugExecutor;
 import com.intellij.execution.runners.ExecutionEnvironment;
 import com.intellij.execution.ui.RunContentDescriptor;
-import com.intellij.openapi.project.Project;
 import org.jetbrains.annotations.NotNull;
 
 /**
@@ -42,10 +41,7 @@ public class GriffonDebuggerRunner extends GenericDebuggerRunner {
 
 
   @Override
-  protected RunContentDescriptor createContentDescriptor(Project project,
-                                                         RunProfileState state,
-                                                         RunContentDescriptor contentToReuse,
-                                                         ExecutionEnvironment environment) throws ExecutionException {
+  protected RunContentDescriptor createContentDescriptor(@NotNull RunProfileState state, @NotNull ExecutionEnvironment environment) throws ExecutionException {
     final JavaCommandLine javaCommandLine = (JavaCommandLine)state;
     final JavaParameters params = javaCommandLine.getJavaParameters();
 
@@ -68,11 +64,8 @@ public class GriffonDebuggerRunner extends GenericDebuggerRunner {
     }
 
     if (address == null) {
-      return super.createContentDescriptor(project, state, contentToReuse, environment);
+      return super.createContentDescriptor(state, environment);
     }
-
-    RemoteConnection connection = new RemoteConnection(true, "127.0.0.1", address, false);
-    return attachVirtualMachine(project, state, contentToReuse, environment, connection, true);
+    return attachVirtualMachine(state, environment, new RemoteConnection(true, "127.0.0.1", address, false), true);
   }
-
-}
+}
\ No newline at end of file
index 6dcb63b35478b3e21e6425a004caff8779108f28..bada6c04435405018efa6290546ef44834e6c3e3 100644 (file)
@@ -194,29 +194,26 @@ public class MavenRunConfigurationType implements ConfigurationType {
 
     ProgramRunner runner = DefaultJavaProgramRunner.getInstance();
     Executor executor = DefaultRunExecutor.getRunExecutorInstance();
-    ExecutionEnvironment env = new ExecutionEnvironment(executor, runner, configSettings, project);
-
     try {
-      runner.execute(env, callback);
+      runner.execute(new ExecutionEnvironment(executor, runner, configSettings, project), callback);
     }
     catch (ExecutionException e) {
       MavenUtil.showError(project, "Failed to execute Maven goal", e);
     }
   }
 
+  @NotNull
   public static RunnerAndConfigurationSettings createRunnerAndConfigurationSettings(@Nullable MavenGeneralSettings generalSettings,
-                                                                             @Nullable MavenRunnerSettings runnerSettings,
-                                                                             MavenRunnerParameters params,
-                                                                             Project project) {
+                                                                                    @Nullable MavenRunnerSettings runnerSettings,
+                                                                                    MavenRunnerParameters params,
+                                                                                    Project project) {
     MavenRunConfigurationType type = ConfigurationTypeUtil.findConfigurationType(MavenRunConfigurationType.class);
 
-    final RunnerAndConfigurationSettings settings = RunManagerEx.getInstanceEx(project)
-      .createConfiguration(generateName(project, params), type.myFactory);
+    RunnerAndConfigurationSettings settings = RunManager.getInstance(project).createRunConfiguration(generateName(project, params), type.myFactory);
     MavenRunConfiguration runConfiguration = (MavenRunConfiguration)settings.getConfiguration();
     runConfiguration.setRunnerParameters(params);
     runConfiguration.setGeneralSettings(generalSettings);
     runConfiguration.setRunnerSettings(runnerSettings);
-
     return settings;
   }
 }
index 4566689ed55ee54464058546fd26d2637e734565..48f376d1829f3ac34b1927c1829fba271e103d49 100644 (file)
@@ -57,9 +57,9 @@ public class MavenRunConfigurationMenu extends DefaultActionGroup implements Dum
 
     @Override
     public void actionPerformed(AnActionEvent event) {
-      if (!myEnabled) return;
-
-      ProgramRunnerUtil.executeConfiguration(myProject, mySettings, myExecutor);
+      if (myEnabled) {
+        ProgramRunnerUtil.executeConfiguration(myProject, mySettings, myExecutor);
+      }
     }
 
     @Override
index d252c93bcb34eecce127bb2552a5f2f995a0f5ef..f671b1a19fc6129f17a5a6be655685e7874c6720 100644 (file)
@@ -155,8 +155,7 @@ public abstract class AbstractTerminalRunner<T extends Process> {
     return new CloseAction(defaultExecutor, myDescriptor, myProject);
   }
 
-
-  protected void showConsole(Executor defaultExecutor, RunContentDescriptor myDescriptor, final Component toFocus) {
+  protected void showConsole(Executor defaultExecutor, @NotNull RunContentDescriptor myDescriptor, final Component toFocus) {
     // Show in run toolwindow
     ExecutionManager.getInstance(myProject).getContentManager().showRunContent(defaultExecutor, myDescriptor);
 
index 4fbb92964a0293f691ca129eeca0b740264bf76f..5c98bd5110b1f561b7afcf2b9880ac8f047653bc 100644 (file)
@@ -54,7 +54,7 @@ public class PythonToolWindowConsoleRunner extends PydevConsoleRunner {
   }
 
   @Override
-  protected void showConsole(Executor defaultExecutor, RunContentDescriptor contentDescriptor) {
+  protected void showConsole(Executor defaultExecutor, @NotNull RunContentDescriptor contentDescriptor) {
     PythonConsoleToolWindow terminalView = PythonConsoleToolWindow.getInstance(getProject());
     terminalView.init(getToolWindow(), contentDescriptor);
   }