Search in sources :

Example 1 with RunContentExecutor

use of com.intellij.execution.RunContentExecutor in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoExecutor method showOutput.

private void showOutput(@NotNull OSProcessHandler originalHandler, @NotNull GoHistoryProcessListener historyProcessListener) {
    if (myShowOutputOnError) {
        BaseOSProcessHandler outputHandler = new KillableColoredProcessHandler(originalHandler.getProcess(), null);
        RunContentExecutor runContentExecutor = new RunContentExecutor(myProject, outputHandler).withTitle(getPresentableName()).withActivateToolWindow(myShowOutputOnError).withFilter(new GoConsoleFilter(myProject, myModule, myWorkDirectory != null ? VfsUtilCore.pathToUrl(myWorkDirectory) : null));
        Disposer.register(myProject, runContentExecutor);
        runContentExecutor.run();
        historyProcessListener.apply(outputHandler);
    }
    if (myShowNotificationsOnError) {
        showNotification("Failed to run", NotificationType.ERROR);
    }
}
Also used : GoConsoleFilter(com.goide.runconfig.GoConsoleFilter) RunContentExecutor(com.intellij.execution.RunContentExecutor)

Example 2 with RunContentExecutor

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

the class StudyRunAction method executeFile.

private void executeFile(@NotNull final Project project, @NotNull final VirtualFile openedFile, @NotNull final String filePath) {
    GeneralCommandLine cmd = new GeneralCommandLine();
    cmd.withWorkDirectory(openedFile.getParent().getCanonicalPath());
    TaskFile selectedTaskFile = StudyUtils.getTaskFile(project, openedFile);
    assert selectedTaskFile != null;
    final Task currentTask = selectedTaskFile.getTask();
    final Sdk sdk = StudyUtils.findSdk(currentTask, project);
    if (sdk == null) {
        StudyUtils.showNoSdkNotification(currentTask, project);
        return;
    }
    String sdkHomePath = sdk.getHomePath();
    if (sdkHomePath != null) {
        cmd.setExePath(sdkHomePath);
        StudyUtils.setCommandLineParameters(cmd, project, filePath, sdkHomePath, currentTask);
        try {
            myHandler = new OSProcessHandler(cmd);
        } catch (ExecutionException e) {
            LOG.error(e);
            return;
        }
        for (ProcessListener processListener : myProcessListeners) {
            myHandler.addProcessListener(processListener);
        }
        final RunContentExecutor executor = StudyUtils.getExecutor(project, currentTask, myHandler);
        if (executor != null) {
            Disposer.register(project, executor);
            executor.run();
        }
        EduUtils.synchronize();
    }
}
Also used : TaskFile(com.jetbrains.edu.learning.courseFormat.TaskFile) Task(com.jetbrains.edu.learning.courseFormat.Task) OSProcessHandler(com.intellij.execution.process.OSProcessHandler) ProcessListener(com.intellij.execution.process.ProcessListener) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) RunContentExecutor(com.intellij.execution.RunContentExecutor) Sdk(com.intellij.openapi.projectRoots.Sdk) ExecutionException(com.intellij.execution.ExecutionException)

Example 3 with RunContentExecutor

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

the class CompileQrcAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    Project project = e.getData(CommonDataKeys.PROJECT);
    VirtualFile[] vFiles = e.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY);
    assert vFiles != null;
    Module module = e.getData(LangDataKeys.MODULE);
    String path = QtFileType.findQtTool(module, "pyrcc4");
    if (path == null) {
        path = QtFileType.findQtTool(module, "pyside-rcc");
    }
    if (path == null) {
        Messages.showErrorDialog(project, "Could not find pyrcc4 or pyside-rcc for selected Python interpreter", "Compile .qrc file");
        return;
    }
    CompileQrcDialog dialog = new CompileQrcDialog(project, vFiles);
    dialog.show();
    if (dialog.getExitCode() != DialogWrapper.OK_EXIT_CODE) {
        return;
    }
    GeneralCommandLine cmdLine = new GeneralCommandLine(path, "-o", dialog.getOutputPath());
    for (VirtualFile vFile : vFiles) {
        cmdLine.addParameter(vFile.getPath());
    }
    try {
        ProcessHandler process = new OSProcessHandler(cmdLine);
        ProcessTerminatedListener.attach(process);
        new RunContentExecutor(project, process).withTitle("Compile .qrc").run();
    } catch (ExecutionException ex) {
        Messages.showErrorDialog(project, "Error running " + path + ": " + ex.getMessage(), "Compile .qrc file");
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) OSProcessHandler(com.intellij.execution.process.OSProcessHandler) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) OSProcessHandler(com.intellij.execution.process.OSProcessHandler) ProcessHandler(com.intellij.execution.process.ProcessHandler) RunContentExecutor(com.intellij.execution.RunContentExecutor) Module(com.intellij.openapi.module.Module) ExecutionException(com.intellij.execution.ExecutionException)

Example 4 with RunContentExecutor

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

the class SphinxBaseCommand method execute.

public void execute(@NotNull final Module module) {
    final Project project = module.getProject();
    try {
        if (!setWorkDir(module))
            return;
        final ProcessHandler process = createProcess(module);
        new RunContentExecutor(project, process).withFilter(new PythonTracebackFilter(project)).withTitle("reStructuredText").withRerun(() -> execute(module)).withAfterCompletion(getAfterTask(module)).run();
    } catch (ExecutionException e) {
        Messages.showErrorDialog(e.getMessage(), "ReStructuredText Error");
    }
}
Also used : Project(com.intellij.openapi.project.Project) ProcessHandler(com.intellij.execution.process.ProcessHandler) RunContentExecutor(com.intellij.execution.RunContentExecutor) ExecutionException(com.intellij.execution.ExecutionException) PythonTracebackFilter(com.jetbrains.python.run.PythonTracebackFilter)

Example 5 with RunContentExecutor

use of com.intellij.execution.RunContentExecutor 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;
    }
}
Also used : NonNls(org.jetbrains.annotations.NonNls) UrlFilter(com.intellij.execution.filters.UrlFilter) NotNull(org.jetbrains.annotations.NotNull) PyPackage(com.jetbrains.python.packaging.PyPackage) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) RunContentExecutor(com.intellij.execution.RunContentExecutor) Sdk(com.intellij.openapi.projectRoots.Sdk) Module(com.intellij.openapi.module.Module) ExecutionException(com.intellij.execution.ExecutionException) Key(com.intellij.openapi.util.Key) KillableColoredProcessHandler(com.intellij.execution.process.KillableColoredProcessHandler)

Aggregations

RunContentExecutor (com.intellij.execution.RunContentExecutor)7 ExecutionException (com.intellij.execution.ExecutionException)6 ProcessHandler (com.intellij.execution.process.ProcessHandler)4 GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)3 Project (com.intellij.openapi.project.Project)3 OSProcessHandler (com.intellij.execution.process.OSProcessHandler)2 Module (com.intellij.openapi.module.Module)2 Sdk (com.intellij.openapi.projectRoots.Sdk)2 GoConsoleFilter (com.goide.runconfig.GoConsoleFilter)1 UrlFilter (com.intellij.execution.filters.UrlFilter)1 KillableColoredProcessHandler (com.intellij.execution.process.KillableColoredProcessHandler)1 ProcessListener (com.intellij.execution.process.ProcessListener)1 Key (com.intellij.openapi.util.Key)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 Task (com.jetbrains.edu.learning.courseFormat.Task)1 TaskFile (com.jetbrains.edu.learning.courseFormat.TaskFile)1 PyPackage (com.jetbrains.python.packaging.PyPackage)1 PythonTracebackFilter (com.jetbrains.python.run.PythonTracebackFilter)1 NonNls (org.jetbrains.annotations.NonNls)1 NotNull (org.jetbrains.annotations.NotNull)1