Search in sources :

Example 61 with ProcessOutput

use of com.intellij.execution.process.ProcessOutput in project intellij-plugins by JetBrains.

the class TsLintExternalAnnotator method createGlobalErrorMessage.

@Nullable
private static JSLinterAnnotationResult<TsLintState> createGlobalErrorMessage(@NotNull TsLinterInput collectedInfo, @Nullable VirtualFile config, @Nullable String error) {
    if (!StringUtil.isEmptyOrSpaces(error)) {
        final ProcessOutput output = new ProcessOutput();
        output.appendStderr(error);
        final IntentionAction detailsAction = JSLinterUtil.createDetailsAction(collectedInfo.getProject(), collectedInfo.getVirtualFile(), null, output, null);
        final JSLinterFileLevelAnnotation annotation = new JSLinterFileLevelAnnotation(error, detailsAction);
        return JSLinterAnnotationResult.create(collectedInfo, annotation, config);
    }
    return null;
}
Also used : ProcessOutput(com.intellij.execution.process.ProcessOutput) IntentionAction(com.intellij.codeInsight.intention.IntentionAction) Nullable(org.jetbrains.annotations.Nullable)

Example 62 with ProcessOutput

use of com.intellij.execution.process.ProcessOutput in project flutter-intellij by flutter.

the class FlutterSettingsConfigurable method updateVersionText.

private void updateVersionText() {
    final FlutterSdk sdk = FlutterSdk.forPath(getSdkPathText());
    if (sdk == null) {
        myVersionLabel.setText("");
        return;
    }
    final ModalityState modalityState = ModalityState.current();
    sdk.flutterVersion().start((ProcessOutput output) -> {
        final String stdout = output.getStdout();
        final String htmlText = "<html>" + StringUtil.replace(StringUtil.escapeXml(stdout.trim()), "\n", "<br/>") + "</html>";
        ApplicationManager.getApplication().invokeLater(() -> updateVersionTextIfCurrent(sdk, htmlText), modalityState);
    }, null);
}
Also used : ProcessOutput(com.intellij.execution.process.ProcessOutput) ModalityState(com.intellij.openapi.application.ModalityState)

Example 63 with ProcessOutput

use of com.intellij.execution.process.ProcessOutput in project teamcity-powershell by JetBrains.

the class DetectionRunner method runProcess.

private static ProcessOutput runProcess(@NotNull final GeneralCommandLine cl) throws ExecutionException {
    final CapturingProcessHandler handler = new CapturingProcessHandler(cl.createProcess(), Charset.forName("UTF-8"));
    final ProcessOutput result = handler.runProcess(20000);
    if (result.isTimeout()) {
        throw new ExecutionException("Process execution of [" + cl.getCommandLineString() + "] has timed out");
    }
    final String errorOutput = result.getStderr();
    if (!StringUtil.isEmptyOrSpaces(errorOutput)) {
        throw new ExecutionException(errorOutput);
    }
    return result;
}
Also used : ProcessOutput(com.intellij.execution.process.ProcessOutput) ExecutionException(com.intellij.execution.ExecutionException) CapturingProcessHandler(com.intellij.execution.process.CapturingProcessHandler)

Example 64 with ProcessOutput

use of com.intellij.execution.process.ProcessOutput in project Perl5-IDEA by Camelcade.

the class PerlFormatWithPerlTidyAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent event) {
    if (isEnabled(event)) {
        final PsiFile file = PerlActionUtil.getPsiFileFromEvent(event);
        if (file == null) {
            return;
        }
        final Project project = file.getProject();
        final Document document = file.getViewProvider().getDocument();
        if (document == null) {
            return;
        }
        final VirtualFile virtualFile = file.getVirtualFile();
        if (virtualFile == null) {
            return;
        }
        FileDocumentManager.getInstance().saveDocument(document);
        new Task.Backgroundable(project, PerlBundle.message("perl.tidy.formatting"), false) {

            @Override
            public void run(@NotNull ProgressIndicator indicator) {
                try {
                    GeneralCommandLine perlTidyCommandLine = getPerlTidyCommandLine(project);
                    final Process process = perlTidyCommandLine.createProcess();
                    final OutputStream outputStream = process.getOutputStream();
                    ApplicationManager.getApplication().executeOnPooledThread(() -> {
                        try {
                            final byte[] sourceBytes = virtualFile.contentsToByteArray();
                            outputStream.write(sourceBytes);
                            outputStream.close();
                        } catch (IOException e) {
                            Notifications.Bus.notify(new Notification(PERL_TIDY_GROUP, PerlBundle.message("perl.action.perl.tidy.formatting.error.title"), e.getMessage(), NotificationType.ERROR));
                        }
                    });
                    final CapturingProcessHandler processHandler = new CapturingProcessHandler(process, virtualFile.getCharset(), perlTidyCommandLine.getCommandLineString());
                    ProcessOutput processOutput = processHandler.runProcess();
                    final List<String> stdoutLines = processOutput.getStdoutLines(false);
                    List<String> stderrLines = processOutput.getStderrLines();
                    if (stderrLines.isEmpty()) {
                        WriteCommandAction.runWriteCommandAction(project, () -> {
                            document.setText(StringUtil.join(stdoutLines, "\n"));
                            PsiDocumentManager.getInstance(project).commitDocument(document);
                        });
                    } else {
                        Notifications.Bus.notify(new Notification(PERL_TIDY_GROUP, PerlBundle.message("perl.action.perl.tidy.formatting.error.title"), StringUtil.join(stderrLines, "<br>"), NotificationType.ERROR));
                    }
                } catch (ExecutionException e) {
                    Notifications.Bus.notify(new Notification(PERL_TIDY_GROUP, PerlBundle.message("perl.action.perl.tidy.running.error.title"), PerlBundle.message("perl.action.perl.tidy.running.error.message", e.getMessage().replaceAll("\\n", "<br/>")), NotificationType.ERROR).addAction(new DumbAwareAction(PerlBundle.message("perl.configure")) {

                        @Override
                        public void actionPerformed(AnActionEvent e) {
                            Notification.get(e).expire();
                            Perl5SettingsConfigurable.open(file);
                        }
                    }));
                }
            }
        }.queue();
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Task(com.intellij.openapi.progress.Task) OutputStream(java.io.OutputStream) IOException(java.io.IOException) Document(com.intellij.openapi.editor.Document) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) Notification(com.intellij.notification.Notification) Project(com.intellij.openapi.project.Project) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) ProcessOutput(com.intellij.execution.process.ProcessOutput) PsiFile(com.intellij.psi.PsiFile) List(java.util.List) ExecutionException(com.intellij.execution.ExecutionException) CapturingProcessHandler(com.intellij.execution.process.CapturingProcessHandler)

Example 65 with ProcessOutput

use of com.intellij.execution.process.ProcessOutput in project Perl5-IDEA by Camelcade.

the class PerlCoverageRunner method doLoadCoverageData.

@Nullable
private static ProjectData doLoadCoverageData(@NotNull File sessionDataFile, @NotNull PerlCoverageSuite perlCoverageSuite) {
    Project project = perlCoverageSuite.getProject();
    GeneralCommandLine perlCommandLine = ReadAction.compute(() -> {
        if (project.isDisposed()) {
            return null;
        }
        VirtualFile coverFile = PerlRunUtil.findLibraryScriptWithNotification(project, COVER, COVER_LIB);
        if (coverFile == null) {
            return null;
        }
        String libRoot = PerlPluginUtil.getPluginPerlLibRoot();
        if (libRoot == null) {
            return null;
        }
        GeneralCommandLine commandLine = PerlRunUtil.getPerlCommandLine(project, coverFile, "-I" + FileUtil.toSystemIndependentName(libRoot));
        if (commandLine == null) {
            // fixme should be a notification
            return null;
        }
        commandLine.addParameters("--silent", "--nosummary", "-report", "camelcade", sessionDataFile.getAbsolutePath());
        return commandLine;
    });
    if (perlCommandLine == null) {
        return null;
    }
    try {
        LOG.info("Loading coverage by: " + perlCommandLine.getCommandLineString());
        ProcessOutput output = ExecUtil.execAndGetOutput(perlCommandLine);
        if (output.getExitCode() != 0) {
            String errorMessage = output.getStderr();
            if (StringUtil.isEmpty(errorMessage)) {
                errorMessage = output.getStdout();
            }
            if (!StringUtil.isEmpty(errorMessage)) {
                showError(project, errorMessage);
            }
            return null;
        }
        String stdout = output.getStdout();
        if (StringUtil.isEmpty(stdout)) {
            return null;
        }
        try {
            PerlFileData[] filesData = new Gson().fromJson(stdout, PerlFileData[].class);
            if (filesData != null) {
                return parsePerlFileData(filesData);
            }
        } catch (JsonParseException e) {
            showError(project, e.getMessage());
            LOG.warn("Error parsing JSON", e);
        }
    } catch (ExecutionException e) {
        showError(project, e.getMessage());
        LOG.warn("Error loading coverage", e);
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) ProcessOutput(com.intellij.execution.process.ProcessOutput) Gson(com.google.gson.Gson) JsonParseException(com.google.gson.JsonParseException) ExecutionException(com.intellij.execution.ExecutionException) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

ProcessOutput (com.intellij.execution.process.ProcessOutput)66 ExecutionException (com.intellij.execution.ExecutionException)25 GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)25 VirtualFile (com.intellij.openapi.vfs.VirtualFile)23 File (java.io.File)23 CapturingProcessHandler (com.intellij.execution.process.CapturingProcessHandler)16 Nullable (org.jetbrains.annotations.Nullable)13 NotNull (org.jetbrains.annotations.NotNull)9 ArrayList (java.util.ArrayList)7 Test (org.junit.Test)7 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)5 Project (com.intellij.openapi.project.Project)5 PsiFile (com.intellij.psi.PsiFile)5 IOException (java.io.IOException)5 OutputStream (java.io.OutputStream)4 CapturingAnsiEscapesAwareProcessHandler (com.intellij.execution.process.CapturingAnsiEscapesAwareProcessHandler)3 Notification (com.intellij.notification.Notification)3 Document (com.intellij.openapi.editor.Document)3 Task (com.intellij.openapi.progress.Task)3 Sdk (com.intellij.openapi.projectRoots.Sdk)3