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;
public abstract void addDebuggerManagerListener(DebuggerManagerListener debuggerManagerListener);
public abstract void removeDebuggerManagerListener(DebuggerManagerListener debuggerManagerListener);
+ @Nullable
public abstract DebuggerSession attachVirtualMachine(@NotNull DebugEnvironment environment) throws ExecutionException;
}
RemoteConnection remoteConnection,
boolean pollConnection) {
myExecutionEnvironment = environment;
- myModelEnvironment = new DefaultDebugEnvironment(environment,
- state,
- remoteConnection,
- pollConnection);
+ myModelEnvironment = new DefaultDebugEnvironment(environment, state, remoteConnection, pollConnection);
}
@Override
}
@Override
+ @Nullable
public DebuggerSession attachVirtualMachine(@NotNull DebugEnvironment environment) throws ExecutionException {
ApplicationManager.getApplication().assertIsDispatchThread();
final DebugProcessEvents debugProcess = new DebugProcessEvents(myProject);
return session;
}
-
@Override
public DebugProcessImpl getDebugProcess(final ProcessHandler processHandler) {
synchronized (mySessions) {
}
@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;
}
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) {
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
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;
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;
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
if (action != null) group.add(action);
}
-
@Override
public void dispose() {
disposeSession();
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;
* @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
@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");
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;
@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;
myContentToReuse = null;
myRunnerAndConfigurationSettings = null;
myExecutor = null;
- runner = null;
+ myRunner = null;
}
public ExecutionEnvironment(@NotNull Executor executor,
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
return myContentToReuse;
}
+ public void setContentToReuse(@Nullable RunContentDescriptor contentToReuse) {
+ myContentToReuse = contentToReuse;
+
+ if (contentToReuse != null) {
+ Disposer.register(contentToReuse, this);
+ }
+ }
+
@Nullable
public String getRunnerId() {
return myRunnerId;
@Nullable
public ProgramRunner<?> getRunner() {
- return runner == null ? RunnerRegistry.getInstance().findRunnerById(getRunnerId()) : runner;
+ return myRunner == null ? RunnerRegistry.getInstance().findRunnerById(getRunnerId()) : myRunner;
}
@Nullable
@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;
@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
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
/**
myRunProfile = settings.getConfiguration();
myRunnerSettings = settings.getRunnerSettings(runner);
myConfigurationSettings = settings.getConfigurationSettings(runner);
- this.runner = runner;
+ myRunner = runner;
return this;
}
}
public ExecutionEnvironmentBuilder runner(@NotNull ProgramRunner<?> runner) {
- this.runner = runner;
+ myRunner = runner;
return this;
}
@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();
}
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;
}
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);
}
}
@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)}
*/
@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);
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,
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package com.intellij.execution.impl;
import com.intellij.CommonBundle;
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;
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;
/**
@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());
}
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);
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()) {
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);
}
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) {
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());
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();
+ }
}
}
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);
}
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;
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;
}
public void actionPerformed(AnActionEvent event) {
ExecutionEnvironment environment = getEnvironment(event);
if (environment != null) {
- ExecutionUtil.restart(environment, getDescriptor(event));
+ ExecutionUtil.restart(environment);
return;
}
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;
* @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);
}
}
}
@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);
}
}
* 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
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
@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) {
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) {
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) {
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());
contentDescriptor.setRestarter(new Runnable() {
@Override
public void run() {
- ExecutionUtil.restart(getEnvironment(), contentDescriptor);
+ ExecutionUtil.restart(getEnvironment());
}
});
*/
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;
}
}
@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());
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
//
descriptor.getPreferredFocusComputable();
window.activate(null, descriptor.isAutoFocusContent(), descriptor.isAutoFocusContent());
}
- });
+ }, myProject.getDisposed());
}
@Override
}
@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
}
//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) {
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);
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;
@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
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);
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);
}
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
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;
/**
@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();
}
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
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;
}
}
@Override
public void actionPerformed(AnActionEvent event) {
- if (!myEnabled) return;
-
- ProgramRunnerUtil.executeConfiguration(myProject, mySettings, myExecutor);
+ if (myEnabled) {
+ ProgramRunnerUtil.executeConfiguration(myProject, mySettings, myExecutor);
+ }
}
@Override
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);
}
@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);
}