mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-15975 Interface introduced to prevent configurations from running under debug, hence tests rerun support debug now while rest not
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
@@ -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;
|
||||
* <p/>
|
||||
* This class allows configuration to <strong>rerun</strong> (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).
|
||||
* <p/>
|
||||
* It also has {@link #getAvailableRunnersForLastRun()} with list of strings that represents runner ids available for last run.
|
||||
*
|
||||
* @param <CONF_T> configuration class this runner supports
|
||||
* @author Ilya.Kazakevich
|
||||
@@ -61,6 +66,9 @@ public abstract class ConfigurationBasedProcessRunner<CONF_T extends AbstractPyt
|
||||
@NotNull
|
||||
private final Class<CONF_T> myExpectedConfigurationType;
|
||||
|
||||
@NotNull
|
||||
private final List<String> myAvailableRunnersForLastRun = new ArrayList<String>();
|
||||
|
||||
/**
|
||||
* Environment to be used to run instead of factory. Used to rerun
|
||||
*/
|
||||
@@ -104,6 +112,18 @@ public abstract class ConfigurationBasedProcessRunner<CONF_T extends AbstractPyt
|
||||
}, ModalityState.NON_MODAL);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/// Find all available runners to report them to the test
|
||||
myAvailableRunnersForLastRun.clear();
|
||||
for (final ProgramRunner<?> runner : ProgramRunner.PROGRAM_RUNNER_EP.getExtensions()) {
|
||||
for (final Executor executor : Executor.EXECUTOR_EXTENSION_NAME.getExtensions()) {
|
||||
if (runner.canRun(executor.getId(), executionEnvironment.getRunProfile())) {
|
||||
myAvailableRunnersForLastRun.add(runner.getRunnerId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
executionEnvironment.getRunner().execute(executionEnvironment, new ProgramRunner.Callback() {
|
||||
@Override
|
||||
public void processStarted(final RunContentDescriptor descriptor) {
|
||||
@@ -200,4 +220,13 @@ public abstract class ConfigurationBasedProcessRunner<CONF_T extends AbstractPyt
|
||||
protected ExecutionEnvironment getEnvironmentToRerun(@NotNull final RunContentDescriptor lastRunDescriptor) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list of runner ids which are allowed to run against current environment.
|
||||
* Use it to check if desired runner (like debugger) exists
|
||||
*/
|
||||
@NotNull
|
||||
public final List<String> getAvailableRunnersForLastRun() {
|
||||
return Collections.unmodifiableList(myAvailableRunnersForLastRun);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user