*/
package com.jetbrains.python.console;
-import com.intellij.execution.process.ProcessHandler;
import com.intellij.execution.ui.ConsoleViewContentType;
import com.intellij.execution.ui.ExecutionConsole;
-import com.intellij.openapi.util.text.StringUtil;
+import com.intellij.remote.RemoteProcessHandlerBase;
import com.intellij.util.ui.UIUtil;
import com.intellij.xdebugger.XDebugSession;
import com.jetbrains.python.debugger.PyDebugProcess;
import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
import java.net.ServerSocket;
*/
public class PyConsoleDebugProcess extends PyDebugProcess {
private final int myLocalPort;
+ private final PyConsoleDebugProcessHandler myConsoleDebugProcessHandler;
public PyConsoleDebugProcess(@NotNull XDebugSession session,
@NotNull final ServerSocket serverSocket,
@NotNull final ExecutionConsole executionConsole,
- @Nullable final ProcessHandler processHandler) {
- super(session, serverSocket, executionConsole, processHandler, false);
+ @NotNull final PyConsoleDebugProcessHandler consoleDebugProcessHandler) {
+ super(session, serverSocket, executionConsole, consoleDebugProcessHandler, false);
myLocalPort = serverSocket.getLocalPort();
+ myConsoleDebugProcessHandler = consoleDebugProcessHandler;
}
@Override
}
public void connect(PydevConsoleCommunication consoleCommunication) throws Exception {
- consoleCommunication.connectToDebugger(myLocalPort);
+ int portToConnect;
+ if (myConsoleDebugProcessHandler.getConsoleProcessHandler() instanceof RemoteProcessHandlerBase) {
+ portToConnect = getRemoteTunneledPort(myLocalPort,
+ ((RemoteProcessHandlerBase)myConsoleDebugProcessHandler.getConsoleProcessHandler()));
+ } else {
+ portToConnect = myLocalPort;
+ }
+ consoleCommunication.connectToDebugger(portToConnect);
}
public void waitForNextConnection() {
import com.intellij.execution.process.*;
import com.intellij.openapi.util.Key;
+import com.jetbrains.python.debugger.PositionConverterProvider;
+import com.jetbrains.python.debugger.PyDebugProcess;
+import com.jetbrains.python.debugger.PyLocalPositionConverter;
+import com.jetbrains.python.debugger.PyPositionConverter;
+import org.jetbrains.annotations.Nullable;
import java.io.OutputStream;
/**
* @author traff
*/
-public class PyConsoleDebugProcessHandler extends ProcessHandler {
- private PydevConsoleCommunication myConsoleCommunication;
+public class PyConsoleDebugProcessHandler extends ProcessHandler implements PositionConverterProvider {
+ private final PyConsoleProcessHandler myConsoleProcessHandler;
- public PyConsoleDebugProcessHandler(final PyConsoleProcessHandler processHandler, PydevConsoleCommunication communication) {
- myConsoleCommunication = communication;
+ public PyConsoleDebugProcessHandler(final PyConsoleProcessHandler processHandler) {
+ myConsoleProcessHandler = processHandler;
processHandler.addProcessListener(new ProcessListener() {
@Override
public void startNotified(ProcessEvent event) {
public OutputStream getProcessInput() {
return null;
}
+
+ public PyConsoleProcessHandler getConsoleProcessHandler() {
+ return myConsoleProcessHandler;
+ }
+
+ @Nullable
+ @Override
+ public PyPositionConverter createPositionConverter(PyDebugProcess debugProcess) {
+ if (myConsoleProcessHandler instanceof PositionConverterProvider) {
+ return ((PositionConverterProvider)myConsoleProcessHandler).createPositionConverter(debugProcess);
+ }
+ else {
+ return new PyLocalPositionConverter();
+ }
+ }
}
import com.jetbrains.python.console.parsing.PythonConsoleData;
import com.jetbrains.python.console.pydev.ConsoleCommunication;
import com.jetbrains.python.debugger.PyDebugRunner;
-import com.jetbrains.python.debugger.PyLocalPositionConverter;
import com.jetbrains.python.debugger.PySourcePosition;
import com.jetbrains.python.remote.PyRemoteSdkAdditionalDataBase;
import com.jetbrains.python.remote.PyRemoteSdkCredentials;
import com.jetbrains.python.run.PythonCommandLineState;
import com.jetbrains.python.run.PythonTracebackFilter;
import com.jetbrains.python.sdk.PySdkUtil;
-import com.jetbrains.python.sdk.PythonSdkType;
import com.jetbrains.python.sdk.flavors.PythonSdkFlavor;
import icons.PythonIcons;
import org.apache.xmlrpc.XmlRpcException;
remoteProcess.addRemoteTunnel(remotePorts.second, "localhost", myPorts[1]);
- myPydevConsoleCommunication = new PydevConsoleCommunication(getProject(), myPorts[0], remoteProcess, myPorts[1]);
+ myPydevConsoleCommunication = new PydevRemoteConsoleCommunication(getProject(), myPorts[0], remoteProcess, myPorts[1]);
return remoteProcess;
}
catch (Exception e) {
@Override
protected PyConsoleProcessHandler createProcessHandler(final Process process) {
- myProcessHandler = new PyConsoleProcessHandler(process, getConsoleView(), myPydevConsoleCommunication, myCommandLine,
- CharsetToolkit.UTF8_CHARSET);
+ if (PySdkUtil.isRemote(mySdk)) {
+ PythonRemoteInterpreterManager manager = PythonRemoteInterpreterManager.getInstance();
+ if (manager != null) {
+ PyRemoteSdkAdditionalDataBase data = (PyRemoteSdkAdditionalDataBase)mySdk.getSdkAdditionalData();
+ assert data != null;
+ try {
+ myProcessHandler =
+ manager.createConsoleProcessHandler(process, data.getRemoteSdkCredentials(), getConsoleView(), myPydevConsoleCommunication,
+ myCommandLine, CharsetToolkit.UTF8_CHARSET,
+ manager.setupMappings(getProject(), data, null));
+ }
+ catch (InterruptedException e) {
+ LOG.error("Error getting remote credentials");
+ }
+ }
+ else {
+ LOG.error("Can't create remote console process handler");
+ }
+ }
+ else {
+ myProcessHandler = new PyConsoleProcessHandler(process, getConsoleView(), myPydevConsoleCommunication, myCommandLine,
+ CharsetToolkit.UTF8_CHARSET);
+ }
return myProcessHandler;
}
public void update(AnActionEvent e) {
if (mySession != null) {
e.getPresentation().setEnabled(false);
- } else {
+ }
+ else {
e.getPresentation().setEnabled(true);
}
}
public XDebugProcess start(@NotNull final XDebugSession session) {
PythonDebugLanguageConsoleView debugConsoleView = new PythonDebugLanguageConsoleView(getProject(), mySdk);
- PyConsoleDebugProcessHandler consoleDebugProcessHandler = new PyConsoleDebugProcessHandler(myProcessHandler, myPydevConsoleCommunication);
+ PyConsoleDebugProcessHandler consoleDebugProcessHandler =
+ new PyConsoleDebugProcessHandler(myProcessHandler);
PyConsoleDebugProcess consoleDebugProcess =
new PyConsoleDebugProcess(session, serverSocket, debugConsoleView,
consoleDebugProcessHandler);
- PythonDebugConsoleCommunication communication = PyDebugRunner.initDebugConsoleView(getProject(), consoleDebugProcess, debugConsoleView, consoleDebugProcessHandler);
+ PythonDebugConsoleCommunication communication =
+ PyDebugRunner.initDebugConsoleView(getProject(), consoleDebugProcess, debugConsoleView, consoleDebugProcessHandler);
myPydevConsoleCommunication.setDebugCommunication(communication);
debugConsoleView.attachToProcess(consoleDebugProcessHandler);
- consoleDebugProcess.setPositionConverter(new PyLocalPositionConverter());
-
consoleDebugProcess.waitForNextConnection();
try {
--- /dev/null
+/*
+ * Copyright 2000-2014 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.console;
+
+import com.intellij.openapi.project.Project;
+
+/**
+ * @author traff
+ */
+public class PydevRemoteConsoleCommunication extends PydevConsoleCommunication {
+ /**
+ * Initializes the xml-rpc communication.
+ *
+ * @param project
+ * @param port the port where the communication should happen.
+ * @param process this is the process that was spawned (server for the XML-RPC)
+ * @param clientPort
+ * @throws MalformedURLException
+ */
+ public PydevRemoteConsoleCommunication(Project project, int port, Process process, int clientPort)
+ throws Exception {
+ super(project, port, process, clientPort);
+ }
+}
--- /dev/null
+/*
+ * Copyright 2000-2014 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.debugger;
+
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * @author traff
+ */
+public interface PositionConverterProvider {
+ @Nullable
+ PyPositionConverter createPositionConverter(PyDebugProcess debugProcess);
+}
import com.intellij.xdebugger.stepping.XSmartStepIntoHandler;
import com.jetbrains.python.console.pydev.PydevCompletionVariant;
import com.jetbrains.python.debugger.pydev.*;
-import com.jetbrains.python.remote.RemoteDebuggableProcessHandler;
import com.jetbrains.python.run.PythonProcessHandler;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
if (myProcessHandler != null) {
myProcessHandler.addProcessListener(this);
}
- if (processHandler instanceof RemoteDebuggableProcessHandler) {
- myPositionConverter = ((RemoteDebuggableProcessHandler)processHandler).createPositionConverter(this);
+ if (processHandler instanceof PositionConverterProvider) {
+ myPositionConverter = ((PositionConverterProvider)processHandler).createPositionConverter(this);
}
else {
myPositionConverter = new PyLocalPositionConverter();
@Override
public int handleDebugPort(int localPort) throws IOException {
if (myProcessHandler instanceof RemoteProcessHandlerBase) {
- RemoteProcessHandlerBase remoteProcessHandler = (RemoteProcessHandlerBase)myProcessHandler;
- try {
- Pair<String, Integer> remoteSocket = remoteProcessHandler.obtainRemoteSocket();
- remoteProcessHandler.addRemoteForwarding(remoteSocket.getSecond(), localPort);
- return remoteSocket.getSecond();
- }
- catch (Exception e) {
- throw new IOException(e);
- }
+ return getRemoteTunneledPort(localPort, (RemoteProcessHandlerBase)myProcessHandler);
}
else {
return localPort;
}
}
+ protected static int getRemoteTunneledPort(int localPort, @NotNull RemoteProcessHandlerBase handler) throws IOException {
+ try {
+ Pair<String, Integer> remoteSocket = handler.obtainRemoteSocket();
+ handler.addRemoteForwarding(remoteSocket.getSecond(), localPort);
+ return remoteSocket.getSecond();
+ }
+ catch (Exception e) {
+ throw new IOException(e);
+ }
+ }
+
@Override
public void recordSignature(PySignature signature) {
PySignatureCacheManager.getInstance(getSession().getProject()).recordSignature(myPositionConverter.convertSignature(signature));
import com.intellij.util.NullableConsumer;
import com.intellij.util.PathMappingSettings;
import com.jetbrains.python.PythonHelpersLocator;
+import com.jetbrains.python.console.PyConsoleProcessHandler;
+import com.jetbrains.python.console.PydevConsoleCommunication;
+import com.jetbrains.python.console.PythonConsoleView;
import com.jetbrains.python.sdk.skeletons.PySkeletonGenerator;
import org.jdom.Element;
import org.jetbrains.annotations.NotNull;
import java.awt.*;
import java.io.IOException;
+import java.nio.charset.Charset;
import java.util.Collection;
import java.util.List;
public abstract ProcessOutput runRemoteProcess(@Nullable Project project,
RemoteSdkCredentials data,
- @NotNull PathMappingSettings mappings,
+ @NotNull PathMappingSettings mappings,
String[] command,
@Nullable String workingDir,
boolean askForSudo)
public abstract RemoteSshProcess createRemoteProcess(@Nullable Project project,
@NotNull PyRemoteSdkCredentials data,
@NotNull PathMappingSettings mappings,
- @NotNull GeneralCommandLine commandLine, boolean allocatePty)
+ @NotNull GeneralCommandLine commandLine, boolean allocatePty)
throws RemoteSdkException;
public abstract boolean editSdk(@NotNull Project project, @NotNull SdkModificator sdkModificator, Collection<Sdk> existingSdks);
public abstract boolean testConnection(RemoteCredentials credentials);
+ public abstract PyConsoleProcessHandler createConsoleProcessHandler(Process process,
+ PyRemoteSdkCredentials data,
+ PythonConsoleView view,
+ PydevConsoleCommunication consoleCommunication,
+ String commandLine, Charset charset, PathMappingSettings settings);
+
public static class PyRemoteInterpreterExecutionException extends ExecutionException {
public PyRemoteInterpreterExecutionException() {
package com.jetbrains.python.remote;
import com.intellij.remote.RemoteProcessHandlerBase;
-import com.jetbrains.python.debugger.PyDebugProcess;
-import com.jetbrains.python.debugger.PyPositionConverter;
+import com.jetbrains.python.debugger.PositionConverterProvider;
/**
* @author yole
*/
-public interface RemoteDebuggableProcessHandler extends RemoteProcessHandlerBase {
- PyPositionConverter createPositionConverter(PyDebugProcess debugProcess);
+public interface RemoteDebuggableProcessHandler extends RemoteProcessHandlerBase, PositionConverterProvider{
}