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;
}
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;
}
}
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;
}
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;
}
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);
}
}
Aggregations