diff --git a/python/python-rest/src/com/jetbrains/rest/run/RestRunConfiguration.java b/python/python-rest/src/com/jetbrains/rest/run/RestRunConfiguration.java index 147861f5857f..1467fc19bec6 100644 --- a/python/python-rest/src/com/jetbrains/rest/run/RestRunConfiguration.java +++ b/python/python-rest/src/com/jetbrains/rest/run/RestRunConfiguration.java @@ -21,12 +21,13 @@ import com.intellij.openapi.util.InvalidDataException; import com.intellij.openapi.util.JDOMExternalizerUtil; import com.intellij.openapi.util.WriteExternalException; import com.jetbrains.python.run.AbstractPythonRunConfiguration; +import com.jetbrains.python.run.DebugAwareConfiguration; import org.jdom.Element; /** * User : catherine */ -public abstract class RestRunConfiguration extends AbstractPythonRunConfiguration { +public abstract class RestRunConfiguration extends AbstractPythonRunConfiguration implements DebugAwareConfiguration { private String myInputFile = ""; private String myOutputFile = ""; private String myParams = ""; @@ -109,4 +110,9 @@ public abstract class RestRunConfiguration extends AbstractPythonRunConfiguratio public boolean canRunWithCoverage() { return false; } + + @Override + public final boolean canRunUnderDebug() { + return false; // Rest configuration can't be run under debug + } } diff --git a/python/src/com/jetbrains/python/debugger/PyDebugRunner.java b/python/src/com/jetbrains/python/debugger/PyDebugRunner.java index 728936052ced..23923357cd57 100644 --- a/python/src/com/jetbrains/python/debugger/PyDebugRunner.java +++ b/python/src/com/jetbrains/python/debugger/PyDebugRunner.java @@ -44,6 +44,7 @@ import com.jetbrains.python.console.PythonDebugLanguageConsoleView; import com.jetbrains.python.console.pydev.ConsoleCommunicationListener; import com.jetbrains.python.run.AbstractPythonRunConfiguration; import com.jetbrains.python.run.CommandLinePatcher; +import com.jetbrains.python.run.DebugAwareConfiguration; import com.jetbrains.python.run.PythonCommandLineState; import com.jetbrains.python.sdk.flavors.PythonSdkFlavor; import org.jetbrains.annotations.NotNull; @@ -76,21 +77,29 @@ public class PyDebugRunner extends GenericProgramRunner { } @Override - public boolean canRun(@NotNull String executorId, @NotNull RunProfile profile) { - return DefaultDebugExecutor.EXECUTOR_ID.equals(executorId) && - profile instanceof AbstractPythonRunConfiguration && - ((AbstractPythonRunConfiguration)profile).canRunWithCoverage(); + public boolean canRun(@NotNull final String executorId, @NotNull final RunProfile profile) { + if (!DefaultDebugExecutor.EXECUTOR_ID.equals(executorId)) { + // If not debug at all + return false; + } + if (profile instanceof DebugAwareConfiguration) { + // if configuration knows whether debug is allowed + return ((DebugAwareConfiguration)profile).canRunUnderDebug(); + } + return true; } - protected XDebugSession createSession(@NotNull RunProfileState state, @NotNull final ExecutionEnvironment environment) throws ExecutionException { + protected XDebugSession createSession(@NotNull RunProfileState state, @NotNull final ExecutionEnvironment environment) + throws ExecutionException { FileDocumentManager.getInstance().saveAllDocuments(); final PythonCommandLineState pyState = (PythonCommandLineState)state; final ServerSocket serverSocket = PythonCommandLineState.createServerSocket(); final int serverLocalPort = serverSocket.getLocalPort(); RunProfile profile = environment.getRunProfile(); - final ExecutionResult result = pyState.execute(environment.getExecutor(), createCommandLinePatchers(environment.getProject(), pyState, profile, serverLocalPort)); + final ExecutionResult result = + pyState.execute(environment.getExecutor(), createCommandLinePatchers(environment.getProject(), pyState, profile, serverLocalPort)); return XDebuggerManager.getInstance(environment.getProject()). startSession(environment, new XDebugProcessStarter() { @@ -116,7 +125,8 @@ public class PyDebugRunner extends GenericProgramRunner { } @Override - protected RunContentDescriptor doExecute(@NotNull RunProfileState state, @NotNull final ExecutionEnvironment environment) throws ExecutionException { + protected RunContentDescriptor doExecute(@NotNull RunProfileState state, @NotNull final ExecutionEnvironment environment) + throws ExecutionException { XDebugSession session = createSession(state, environment); initSession(session, state, environment.getExecutor()); return session.getRunContentDescriptor(); @@ -206,10 +216,11 @@ public class PyDebugRunner extends GenericProgramRunner { parametersList.getParamsGroup(PythonCommandLineState.GROUP_EXE_OPTIONS)); ParamsGroup exeParamsOld = parametersList.removeParamsGroup(exeParamsIndex); isModule = false; - for (String param: exeParamsOld.getParameters()) { + for (String param : exeParamsOld.getParameters()) { if (!param.equals("-m")) { newExeParams.addParameter(param); - } else { + } + else { isModule = true; } } diff --git a/python/src/com/jetbrains/python/run/DebugAwareConfiguration.java b/python/src/com/jetbrains/python/run/DebugAwareConfiguration.java new file mode 100644 index 000000000000..d242e73ca895 --- /dev/null +++ b/python/src/com/jetbrains/python/run/DebugAwareConfiguration.java @@ -0,0 +1,29 @@ +/* + * Copyright 2000-2015 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.jetbrains.python.run; + +import com.intellij.execution.configurations.RunConfiguration; + +/** + * Configuration that knows if it supports run under debug or not + * @author Ilya.Kazakevich + */ +public interface DebugAwareConfiguration extends RunConfiguration { + /** + * @return true if this configuration may run under debug + */ + boolean canRunUnderDebug(); +} diff --git a/python/testSrc/com/jetbrains/env/ConfigurationBasedProcessRunner.java b/python/testSrc/com/jetbrains/env/ConfigurationBasedProcessRunner.java index f8c19ec27c06..15e5a24be636 100644 --- a/python/testSrc/com/jetbrains/env/ConfigurationBasedProcessRunner.java +++ b/python/testSrc/com/jetbrains/env/ConfigurationBasedProcessRunner.java @@ -39,6 +39,9 @@ import org.junit.Assert; import javax.swing.*; import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; /** @@ -47,7 +50,9 @@ import java.io.IOException; *
* This class allows configuration to rerun (using {@link #shouldRunAgain()}, * you need to implement {@link #getEnvironmentToRerun(RunContentDescriptor)}, accept last run descriptor and return - * {@link ExecutionEnvironment} to rerun (probably obtained from descriptor) + * {@link ExecutionEnvironment} to rerun (probably obtained from descriptor). + * + * It also has {@link #getAvailableRunnersForLastRun()} with list of strings that represents runner ids available for last run. * * @param