Search in sources :

Example 1 with Tunnelable

use of com.intellij.remote.Tunnelable in project intellij-community by JetBrains.

the class PydevConsoleRunnerImpl method createRemoteConsoleProcess.

private RemoteProcess createRemoteConsoleProcess(PythonRemoteInterpreterManager manager, String[] command, Map<String, String> env, File workDirectory) throws ExecutionException {
    PyRemoteSdkAdditionalDataBase data = (PyRemoteSdkAdditionalDataBase) mySdk.getSdkAdditionalData();
    assert data != null;
    GeneralCommandLine commandLine = new GeneralCommandLine();
    commandLine.setWorkDirectory(workDirectory);
    commandLine.withParameters(command);
    commandLine.getEnvironment().putAll(env);
    commandLine.getParametersList().set(0, PythonRemoteInterpreterManager.toSystemDependent(new File(data.getHelpersPath(), getRunnerFileFromHelpers()).getPath(), PySourcePosition.isWindowsPath(data.getInterpreterPath())));
    commandLine.getParametersList().set(1, "0");
    commandLine.getParametersList().set(2, "0");
    try {
        PyRemotePathMapper pathMapper = PydevConsoleRunner.getPathMapper(myProject, mySdk, myConsoleSettings);
        assert pathMapper != null;
        commandLine.putUserData(PyRemoteProcessStarter.OPEN_FOR_INCOMING_CONNECTION, true);
        // we do not have an option to setup Docker container settings now for Python console so we should bind at least project
        // directory to some path inside the Docker container
        commandLine.putUserData(PythonRemoteInterpreterManager.ADDITIONAL_MAPPINGS, buildDockerPathMappings());
        myRemoteProcessHandlerBase = PyRemoteProcessStarterManagerUtil.getManager(data).startRemoteProcess(myProject, commandLine, manager, data, pathMapper);
        myCommandLine = myRemoteProcessHandlerBase.getCommandLine();
        RemoteProcess remoteProcess = myRemoteProcessHandlerBase.getProcess();
        Couple<Integer> remotePorts = getRemotePortsFromProcess(remoteProcess);
        if (remoteProcess instanceof Tunnelable) {
            Tunnelable tunnelableProcess = (Tunnelable) remoteProcess;
            tunnelableProcess.addLocalTunnel(myPorts[0], remotePorts.first);
            tunnelableProcess.addRemoteTunnel(remotePorts.second, "localhost", myPorts[1]);
            if (LOG.isDebugEnabled()) {
                LOG.debug(String.format("Using tunneled communication for Python console: port %d (=> %d) on IDE side, " + "port %d (=> %d) on pydevconsole.py side", myPorts[1], remotePorts.second, myPorts[0], remotePorts.first));
            }
            myPydevConsoleCommunication = new PydevRemoteConsoleCommunication(myProject, myPorts[0], remoteProcess, myPorts[1]);
        } else {
            if (LOG.isDebugEnabled()) {
                LOG.debug(String.format("Using direct communication for Python console: port %d on IDE side, port %d on pydevconsole.py side", remotePorts.second, remotePorts.first));
            }
            myPydevConsoleCommunication = new PydevRemoteConsoleCommunication(myProject, remotePorts.first, remoteProcess, remotePorts.second);
        }
        return remoteProcess;
    } catch (Exception e) {
        throw new ExecutionException(e.getMessage(), e);
    }
}
Also used : PyRemotePathMapper(com.jetbrains.python.remote.PyRemotePathMapper) Tunnelable(com.intellij.remote.Tunnelable) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) PyRemoteSdkAdditionalDataBase(com.jetbrains.python.remote.PyRemoteSdkAdditionalDataBase) RemoteProcess(com.intellij.remote.RemoteProcess) ExecutionException(com.intellij.execution.ExecutionException) VirtualFile(com.intellij.openapi.vfs.VirtualFile) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) File(java.io.File) PsiFile(com.intellij.psi.PsiFile) XmlRpcException(org.apache.xmlrpc.XmlRpcException) IOException(java.io.IOException) ExecutionException(com.intellij.execution.ExecutionException)

Aggregations

ExecutionException (com.intellij.execution.ExecutionException)1 GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiFile (com.intellij.psi.PsiFile)1 RemoteProcess (com.intellij.remote.RemoteProcess)1 Tunnelable (com.intellij.remote.Tunnelable)1 LightVirtualFile (com.intellij.testFramework.LightVirtualFile)1 PyRemotePathMapper (com.jetbrains.python.remote.PyRemotePathMapper)1 PyRemoteSdkAdditionalDataBase (com.jetbrains.python.remote.PyRemoteSdkAdditionalDataBase)1 File (java.io.File)1 IOException (java.io.IOException)1 XmlRpcException (org.apache.xmlrpc.XmlRpcException)1