Search in sources :

Example 1 with GeneralCommandLine

use of com.intellij.execution.configurations.GeneralCommandLine in project buck by facebook.

the class BuckWSServerPortUtils method getPort.

public static int getPort(String runInPath) throws NumberFormatException, IOException, ExecutionException {
    BuckSettingsProvider.State state = BuckSettingsProvider.getInstance().getState();
    if (state == null) {
        throw new RuntimeException("Cannot load ideabuck settings.");
    }
    String exec = state.buckExecutable;
    if (Strings.isNullOrEmpty(exec)) {
        throw new RuntimeException("Buck executable is not defined in settings.");
    }
    GeneralCommandLine commandLine = new GeneralCommandLine();
    commandLine.setExePath(exec);
    commandLine.withWorkDirectory(runInPath);
    commandLine.addParameter("server");
    commandLine.addParameter("status");
    commandLine.addParameter("--http-port");
    commandLine.setRedirectErrorStream(true);
    Process p = commandLine.createProcess();
    BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
    int port = CONNECTION_FAILED_PORT;
    String line;
    while ((line = reader.readLine()) != null) {
        if (line.startsWith(SEARCH_FOR)) {
            port = Integer.parseInt(line.substring(SEARCH_FOR.length()));
            if (port == CONNECTION_FAILED_PORT) {
                // if the buck server is off, and it gives us -1, throw this exception
                String error = "Your buck server may be turned off, since the Buck daemon is on port " + port + ".\nTry adding to your '.buckconfig.local' or '.buckconfig' file," + " if you don't have it already set:\n" + "[httpserver]\n" + "    port = 0\n" + "After that, restart IntelliJ or reopen your project.\n";
                throw new RuntimeException(error);
            }
        }
    }
    return port;
}
Also used : InputStreamReader(java.io.InputStreamReader) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) BufferedReader(java.io.BufferedReader)

Example 2 with GeneralCommandLine

use of com.intellij.execution.configurations.GeneralCommandLine in project intellij-community by JetBrains.

the class GroovyConsole method createProcessHandler.

private static ProcessHandler createProcessHandler(Module module) {
    try {
        final JavaParameters javaParameters = createJavaParameters(module);
        final GeneralCommandLine commandLine = javaParameters.toCommandLine();
        return new OSProcessHandler(commandLine) {

            @Override
            public boolean isSilentlyDestroyOnClose() {
                return true;
            }
        };
    } catch (ExecutionException e) {
        LOG.warn(e);
        return null;
    }
}
Also used : GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) JavaParameters(com.intellij.execution.configurations.JavaParameters) ExecutionException(com.intellij.execution.ExecutionException)

Example 3 with GeneralCommandLine

use of com.intellij.execution.configurations.GeneralCommandLine in project intellij-community by JetBrains.

the class SshTunnelRuntimeModule method buildTunnelCommandLine.

@NotNull
private GeneralCommandLine buildTunnelCommandLine(@NotNull String sshPath) {
    GeneralCommandLine result = new GeneralCommandLine(sshPath);
    boolean isPuttyLinkClient = StringUtil.endsWithIgnoreCase(FileUtil.getNameWithoutExtension(sshPath), "plink");
    SvnConfigurationState state = getState();
    // quiet mode
    if (!isPuttyLinkClient) {
        result.addParameter("-q");
    }
    result.addParameters(isPuttyLinkClient ? "-P" : "-p", String.valueOf(state.sshPort));
    if (!StringUtil.isEmpty(state.sshUserName)) {
        result.addParameters("-l", state.sshUserName);
    }
    if (SvnConfiguration.SshConnectionType.PRIVATE_KEY.equals(state.sshConnectionType) && !StringUtil.isEmpty(state.sshPrivateKeyPath)) {
        result.addParameters("-i", FileUtil.toSystemIndependentName(state.sshPrivateKeyPath));
    }
    return result;
}
Also used : GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) SvnConfigurationState(org.jetbrains.idea.svn.SvnConfigurationState) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with GeneralCommandLine

use of com.intellij.execution.configurations.GeneralCommandLine in project intellij-community by JetBrains.

the class PydevConsoleRunnerImpl method doCreateConsoleCmdLine.

@NotNull
protected GeneralCommandLine doCreateConsoleCmdLine(Sdk sdk, Map<String, String> environmentVariables, String workingDir, int[] ports, PythonHelper helper) {
    GeneralCommandLine cmd = PythonCommandLineState.createPythonCommandLine(myProject, new PythonConsoleRunParams(myConsoleSettings, workingDir, sdk, environmentVariables), false, PtyCommandLine.isEnabled() && !SystemInfo.isWindows);
    cmd.withWorkDirectory(myWorkingDir);
    ParamsGroup group = cmd.getParametersList().getParamsGroup(PythonCommandLineState.GROUP_SCRIPT);
    helper.addToGroup(group, cmd);
    for (int port : ports) {
        group.addParameter(String.valueOf(port));
    }
    return cmd;
}
Also used : ParamsGroup(com.intellij.execution.configurations.ParamsGroup) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with GeneralCommandLine

use of com.intellij.execution.configurations.GeneralCommandLine 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

GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)180 ExecutionException (com.intellij.execution.ExecutionException)70 NotNull (org.jetbrains.annotations.NotNull)47 File (java.io.File)41 VirtualFile (com.intellij.openapi.vfs.VirtualFile)31 OSProcessHandler (com.intellij.execution.process.OSProcessHandler)25 ProcessOutput (com.intellij.execution.process.ProcessOutput)25 Key (com.intellij.openapi.util.Key)18 Nullable (org.jetbrains.annotations.Nullable)16 ProcessEvent (com.intellij.execution.process.ProcessEvent)15 Project (com.intellij.openapi.project.Project)15 IOException (java.io.IOException)15 ProcessAdapter (com.intellij.execution.process.ProcessAdapter)14 CapturingProcessHandler (com.intellij.execution.process.CapturingProcessHandler)13 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)12 Sdk (com.intellij.openapi.projectRoots.Sdk)9 PsiFile (com.intellij.psi.PsiFile)9 ArrayList (java.util.ArrayList)9 Module (com.intellij.openapi.module.Module)8 ProcessHandler (com.intellij.execution.process.ProcessHandler)7