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);
}
}
use of com.intellij.execution.configurations.GeneralCommandLine in project intellij-community by JetBrains.
the class PySdkUtil method getProcessOutput.
public static ProcessOutput getProcessOutput(@NotNull GeneralCommandLine cmd, @Nullable String homePath, @Nullable @NonNls Map<String, String> extraEnv, int timeout, @Nullable byte[] stdin, boolean needEOFMarker) {
if (homePath == null || !new File(homePath).exists()) {
return new ProcessOutput();
}
final Map<String, String> systemEnv = System.getenv();
final Map<String, String> expandedCmdEnv = mergeEnvVariables(systemEnv, cmd.getEnvironment());
final Map<String, String> env = extraEnv != null ? mergeEnvVariables(expandedCmdEnv, extraEnv) : expandedCmdEnv;
PythonEnvUtil.resetHomePathChanges(homePath, env);
try {
final GeneralCommandLine commandLine = cmd.withWorkDirectory(homePath).withEnvironment(env);
final CapturingProcessHandler processHandler = new CapturingProcessHandler(commandLine);
if (stdin != null) {
final OutputStream processInput = processHandler.getProcessInput();
assert processInput != null;
processInput.write(stdin);
if (SystemInfo.isWindows && needEOFMarker) {
processInput.write(SUBSTITUTE);
processInput.flush();
} else {
processInput.close();
}
}
return processHandler.runProcess(timeout);
} catch (ExecutionException | IOException e) {
return getOutputForException(e);
}
}
use of com.intellij.execution.configurations.GeneralCommandLine in project intellij-community by JetBrains.
the class JUnit4IntegrationTest method ignoredTestMethod.
@Test
public void ignoredTestMethod() throws Throwable {
EdtTestUtil.runInEdtAndWait(() -> {
PsiClass psiClass = findClass(getModule1(), CLASS_NAME);
assertNotNull(psiClass);
PsiMethod testMethod = psiClass.findMethodsByName(METHOD_NAME, false)[0];
JUnitConfiguration configuration = createConfiguration(testMethod);
Executor executor = DefaultRunExecutor.getRunExecutorInstance();
RunnerAndConfigurationSettingsImpl settings = new RunnerAndConfigurationSettingsImpl(RunManagerImpl.getInstanceImpl(getProject()), configuration, false);
ExecutionEnvironment environment = new ExecutionEnvironment(executor, ProgramRunnerUtil.getRunner(DefaultRunExecutor.EXECUTOR_ID, settings), settings, getProject());
TestObject state = configuration.getState(executor, environment);
JavaParameters parameters = state.getJavaParameters();
parameters.setUseDynamicClasspath(getProject());
GeneralCommandLine commandLine = parameters.toCommandLine();
StringBuffer buf = new StringBuffer();
StringBuffer err = new StringBuffer();
OSProcessHandler process = new OSProcessHandler(commandLine);
process.addProcessListener(new ProcessAdapter() {
@Override
public void onTextAvailable(ProcessEvent event, Key outputType) {
String text = event.getText();
try {
if (outputType == ProcessOutputTypes.STDOUT && !text.isEmpty() && ServiceMessage.parse(text.trim()) == null) {
buf.append(text);
}
if (outputType == ProcessOutputTypes.STDERR) {
err.append(text);
}
} catch (ParseException e) {
e.printStackTrace();
}
}
});
process.startNotify();
process.waitFor();
process.destroyProcess();
String testOutput = buf.toString();
assertEmpty(err.toString());
switch(myJUnitVersion) {
//shouldn't work for old versions
case "4.4":
//shouldn't work for old versions
case "4.5":
break;
default:
assertTrue(testOutput, testOutput.contains("Test1"));
}
});
}
use of com.intellij.execution.configurations.GeneralCommandLine in project intellij-community by JetBrains.
the class GenerateBinaryStubsFix method generateSkeletonsForList.
private boolean generateSkeletonsForList(@NotNull final PySkeletonRefresher refresher, ProgressIndicator indicator, @Nullable final String currentBinaryFilesPath) throws InvalidSdkException {
final PySkeletonGenerator generator = new PySkeletonGenerator(refresher.getSkeletonsPath(), mySdk, currentBinaryFilesPath);
indicator.setIndeterminate(false);
final String homePath = mySdk.getHomePath();
if (homePath == null)
return false;
GeneralCommandLine cmd = PythonHelper.EXTRA_SYSPATH.newCommandLine(homePath, Lists.newArrayList(myQualifiedName));
final ProcessOutput runResult = PySdkUtil.getProcessOutput(cmd, new File(homePath).getParent(), PythonSdkType.getVirtualEnvExtraEnv(homePath), 5000);
if (runResult.getExitCode() == 0 && !runResult.isTimeout()) {
final String extraPath = runResult.getStdout();
final PySkeletonGenerator.ListBinariesResult binaries = generator.listBinaries(mySdk, extraPath);
final List<String> names = Lists.newArrayList(binaries.modules.keySet());
Collections.sort(names);
final int size = names.size();
for (int i = 0; i != size; ++i) {
final String name = names.get(i);
indicator.setFraction((double) i / size);
if (needBinaryList(name)) {
indicator.setText2(name);
final PySkeletonRefresher.PyBinaryItem item = binaries.modules.get(name);
final String modulePath = item != null ? item.getPath() : "";
//noinspection unchecked
refresher.generateSkeleton(name, modulePath, new ArrayList<>(), Consumer.EMPTY_CONSUMER);
}
}
}
return true;
}
Aggregations