use of com.intellij.execution.process.KillableColoredProcessHandler in project intellij-community by JetBrains.
the class TestNGRunnableState method startProcess.
@NotNull
@Override
protected OSProcessHandler startProcess() throws ExecutionException {
final OSProcessHandler processHandler = new KillableColoredProcessHandler(createCommandLine());
ProcessTerminatedListener.attach(processHandler);
createSearchingForTestsTask().attachTaskToProcess(processHandler);
return processHandler;
}
use of com.intellij.execution.process.KillableColoredProcessHandler in project intellij-community by JetBrains.
the class TestObject method createHandler.
@NotNull
protected OSProcessHandler createHandler(Executor executor) throws ExecutionException {
appendForkInfo(executor);
final String repeatMode = getConfiguration().getRepeatMode();
if (!RepeatCount.ONCE.equals(repeatMode)) {
final int repeatCount = getConfiguration().getRepeatCount();
final String countString = RepeatCount.N.equals(repeatMode) && repeatCount > 0 ? RepeatCount.getCountString(repeatCount) : repeatMode;
getJavaParameters().getProgramParametersList().add(countString);
}
final OSProcessHandler processHandler = new KillableColoredProcessHandler(createCommandLine());
ProcessTerminatedListener.attach(processHandler);
final SearchForTestsTask searchForTestsTask = createSearchingForTestsTask();
if (searchForTestsTask != null) {
searchForTestsTask.attachTaskToProcess(processHandler);
}
return processHandler;
}
use of com.intellij.execution.process.KillableColoredProcessHandler in project intellij-community by JetBrains.
the class IpnbConnectionManager method startIpythonServer.
public boolean startIpythonServer(@NotNull final String initUrl, @NotNull final IpnbFileEditor fileEditor) {
final Module module = ProjectFileIndex.SERVICE.getInstance(myProject).getModuleForFile(fileEditor.getVirtualFile());
if (module == null)
return false;
final Sdk sdk = PythonSdkType.findPythonSdk(module);
if (sdk == null) {
showWarning(fileEditor, "Please check Python Interpreter in Settings->Python Interpreter", null);
return false;
}
final List<PyPackage> packages = PyPackageManager.getInstance(sdk).getPackages();
final PyPackage ipythonPackage = packages != null ? PyPackageUtil.findPackage(packages, "ipython") : null;
final PyPackage jupyterPackage = packages != null ? PyPackageUtil.findPackage(packages, "jupyter") : null;
if (ipythonPackage == null && jupyterPackage == null) {
showWarning(fileEditor, "Add Jupyter to the interpreter of the current project.", null);
return false;
}
String url = showDialogUrl(initUrl);
if (url == null)
return false;
final IpnbSettings ipnbSettings = IpnbSettings.getInstance(myProject);
ipnbSettings.setURL(url);
final Pair<String, String> hostPort = getHostPortFromUrl(url);
if (hostPort == null) {
showWarning(fileEditor, "Please, check Jupyter Notebook URL in <a href=\"\">Settings->Tools->Jupyter Notebook</a>", new IpnbSettingsAdapter());
return false;
}
final String homePath = sdk.getHomePath();
if (homePath == null) {
showWarning(fileEditor, "Python Sdk is invalid, please check Python Interpreter in Settings->Python Interpreter", null);
return false;
}
Map<String, String> env = null;
final ArrayList<String> parameters = Lists.newArrayList(homePath);
String ipython = findJupyterRunner(homePath);
if (ipython == null) {
ipython = findIPythonRunner(homePath);
if (ipython == null) {
ipython = PythonHelper.LOAD_ENTRY_POINT.asParamString();
env = ImmutableMap.of("PYCHARM_EP_DIST", "ipython", "PYCHARM_EP_NAME", "ipython");
}
parameters.add(ipython);
parameters.add("notebook");
} else {
parameters.add(ipython);
}
parameters.add("--no-browser");
if (hostPort.getFirst() != null) {
parameters.add("--ip");
parameters.add(hostPort.getFirst());
}
if (hostPort.getSecond() != null) {
parameters.add("--port");
parameters.add(hostPort.getSecond());
}
final String arguments = ipnbSettings.getArguments();
if (!StringUtil.isEmptyOrSpaces(arguments)) {
parameters.addAll(StringUtil.split(arguments, " "));
}
final String directory = ipnbSettings.getWorkingDirectory();
final String baseDir = !StringUtil.isEmptyOrSpaces(directory) ? directory : ModuleRootManager.getInstance(module).getContentRoots()[0].getCanonicalPath();
final GeneralCommandLine commandLine = new GeneralCommandLine(parameters).withWorkDirectory(baseDir);
if (env != null) {
commandLine.withEnvironment(env);
}
try {
final boolean[] serverStarted = { false };
final KillableColoredProcessHandler processHandler = new KillableColoredProcessHandler(commandLine) {
@Override
protected void doDestroyProcess() {
super.doDestroyProcess();
myKernels.clear();
myToken = null;
UnixProcessManager.sendSigIntToProcessTree(getProcess());
}
@Override
public void coloredTextAvailable(@NotNull @NonNls String text, @NotNull Key attributes) {
super.coloredTextAvailable(text, attributes);
if (text.toLowerCase().contains("active kernels")) {
serverStarted[0] = true;
}
final String token = "?token=";
if (text.toLowerCase().contains(token)) {
myToken = text.substring(text.indexOf(token) + token.length()).trim();
}
}
@Override
public boolean isSilentlyDestroyOnClose() {
return true;
}
};
processHandler.setShouldDestroyProcessRecursively(true);
GuiUtils.invokeLaterIfNeeded(() -> new RunContentExecutor(myProject, processHandler).withTitle("Jupyter Notebook").withStop(() -> {
myKernels.clear();
processHandler.destroyProcess();
UnixProcessManager.sendSigIntToProcessTree(processHandler.getProcess());
}, () -> !processHandler.isProcessTerminated()).withRerun(() -> startIpythonServer(url, fileEditor)).withHelpId("reference.manage.py").withFilter(new UrlFilter()).run(), ModalityState.defaultModalityState());
int countAttempt = 0;
while (!serverStarted[0] && countAttempt < MAX_ATTEMPTS) {
countAttempt += 1;
TimeoutUtil.sleep(1000);
}
return true;
} catch (ExecutionException e) {
return false;
}
}
use of com.intellij.execution.process.KillableColoredProcessHandler in project intellij-plugins by JetBrains.
the class JstdRunProfileState method createOSProcessHandler.
@NotNull
private KillableColoredProcessHandler createOSProcessHandler(@NotNull String serverUrl) throws ExecutionException {
Map<TestRunner.ParameterKey, String> params = createParameterMap(serverUrl);
GeneralCommandLine commandLine = createCommandLine(params);
KillableColoredProcessHandler processHandler = new KillableColoredProcessHandler(commandLine, true);
ProcessTerminatedListener.attach(processHandler);
return processHandler;
}
use of com.intellij.execution.process.KillableColoredProcessHandler in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoRunningState method startProcess.
@NotNull
@Override
protected ProcessHandler startProcess() throws ExecutionException {
GoExecutor executor = patchExecutor(createCommonExecutor());
GeneralCommandLine commandLine = executor.withParameterString(myConfiguration.getParams()).createCommandLine();
KillableColoredProcessHandler handler = new KillableColoredProcessHandler(commandLine, true);
ProcessTerminatedListener.attach(handler);
return handler;
}
Aggregations