Search in sources :

Example 6 with GeneralCommandLine

use of com.intellij.execution.configurations.GeneralCommandLine in project jscs-plugin by idok.

the class JscsRunner method lint.

public static LintResult lint(@NotNull JscsSettings settings) {
    LintResult result = new LintResult();
    try {
        GeneralCommandLine commandLine = createCommandLineLint(settings);
        ProcessOutput out = execute(commandLine, TIME_OUT);
        //        if (out.getExitCode() == 0) {
        //        } else {
        result.errorOutput = out.getStderr();
        try {
            result.jscsLint = JscsLint.read(out.getStdout());
        } catch (Exception e) {
        //result.errorOutput = out.getStdout();
        }
    //        }
    } catch (Exception e) {
        e.printStackTrace();
        result.errorOutput = e.toString();
    }
    return result;
}
Also used : LintResult(com.jscs.cli.data.LintResult) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) ExecutionException(com.intellij.execution.ExecutionException)

Example 7 with GeneralCommandLine

use of com.intellij.execution.configurations.GeneralCommandLine in project freeline by alibaba.

the class FreelineUtil method build.

public static void build(Project project) {
    GeneralCommandLine commandLine = new GeneralCommandLine();
    commandLine.setWorkDirectory(project.getBasePath());
    commandLine.setExePath("python");
    commandLine.addParameter("freeline.py");
    // debug
    commandLine.addParameter("-d");
    // commands process
    try {
        processCommandline(project, commandLine);
    } catch (ExecutionException e) {
        e.printStackTrace();
    }
}
Also used : GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) ExecutionException(com.intellij.execution.ExecutionException)

Example 8 with GeneralCommandLine

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

the class GoExecutor method execute.

public boolean execute() {
    Logger.getInstance(getClass()).assertTrue(!ApplicationManager.getApplication().isDispatchThread(), "It's bad idea to run external tool on EDT");
    Logger.getInstance(getClass()).assertTrue(myProcessHandler == null, "Process has already run with this executor instance");
    Ref<Boolean> result = Ref.create(false);
    GeneralCommandLine commandLine = null;
    try {
        commandLine = createCommandLine();
        GeneralCommandLine finalCommandLine = commandLine;
        myProcessHandler = new KillableColoredProcessHandler(finalCommandLine, true) {

            @Override
            public void startNotify() {
                if (myShowGoEnvVariables) {
                    GoRunUtil.printGoEnvVariables(finalCommandLine, this);
                }
                super.startNotify();
            }
        };
        GoHistoryProcessListener historyProcessListener = new GoHistoryProcessListener();
        myProcessHandler.addProcessListener(historyProcessListener);
        for (ProcessListener listener : myProcessListeners) {
            myProcessHandler.addProcessListener(listener);
        }
        CapturingProcessAdapter processAdapter = new CapturingProcessAdapter(myProcessOutput) {

            @Override
            public void processTerminated(@NotNull ProcessEvent event) {
                super.processTerminated(event);
                boolean success = event.getExitCode() == 0 && myProcessOutput.getStderr().isEmpty();
                boolean nothingToShow = myProcessOutput.getStdout().isEmpty() && myProcessOutput.getStderr().isEmpty();
                boolean cancelledByUser = (event.getExitCode() == -1 || event.getExitCode() == 2) && nothingToShow;
                result.set(success);
                if (success) {
                    if (myShowNotificationsOnSuccess) {
                        showNotification("Finished successfully", NotificationType.INFORMATION);
                    }
                } else if (cancelledByUser) {
                    if (myShowNotificationsOnError) {
                        showNotification("Interrupted", NotificationType.WARNING);
                    }
                } else if (myShowOutputOnError) {
                    ApplicationManager.getApplication().invokeLater(() -> showOutput(myProcessHandler, historyProcessListener));
                }
            }
        };
        myProcessHandler.addProcessListener(processAdapter);
        myProcessHandler.startNotify();
        ExecutionModes.SameThreadMode sameThreadMode = new ExecutionModes.SameThreadMode(getPresentableName());
        ExecutionHelper.executeExternalProcess(myProject, myProcessHandler, sameThreadMode, commandLine);
        LOGGER.debug("Finished `" + getPresentableName() + "` with result: " + result.get());
        return result.get();
    } catch (ExecutionException e) {
        if (myShowOutputOnError) {
            ExecutionHelper.showErrors(myProject, Collections.singletonList(e), getPresentableName(), null);
        }
        if (myShowNotificationsOnError) {
            showNotification(StringUtil.notNullize(e.getMessage(), "Unknown error, see logs for details"), NotificationType.ERROR);
        }
        String commandLineInfo = commandLine != null ? commandLine.getCommandLineString() : "not constructed";
        LOGGER.debug("Finished `" + getPresentableName() + "` with an exception. Commandline: " + commandLineInfo, e);
        return false;
    }
}
Also used : NotNull(org.jetbrains.annotations.NotNull) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) ExecutionModes(com.intellij.execution.ExecutionModes) ExecutionException(com.intellij.execution.ExecutionException)

Example 9 with GeneralCommandLine

use of com.intellij.execution.configurations.GeneralCommandLine in project intellij-elixir by KronicDeth.

the class MixBuilder method runMix.

private static void runMix(@NotNull String elixirPath, @NotNull String mixPath, @Nullable String contentRootPath, boolean addDebugInfo, @NotNull CompileContext context) throws ProjectBuildException {
    GeneralCommandLine commandLine = new GeneralCommandLine();
    commandLine.withWorkDirectory(contentRootPath);
    commandLine.setExePath(elixirPath);
    commandLine.addParameter(mixPath);
    commandLine.addParameter("compile");
    if (!addDebugInfo) {
        commandLine.addParameter("--no-debug-info");
    }
    Process process;
    try {
        process = commandLine.createProcess();
    } catch (ExecutionException e) {
        throw new ProjectBuildException("Failed to run mix.", e);
    }
    BaseOSProcessHandler handler = new BaseOSProcessHandler(process, commandLine.getCommandLineString(), Charset.defaultCharset());
    ProcessAdapter adapter = new ElixirCompilerProcessAdapter(context, NAME, commandLine.getWorkDirectory().getPath());
    handler.addProcessListener(adapter);
    handler.startNotify();
    handler.waitFor();
}
Also used : ProjectBuildException(org.jetbrains.jps.incremental.ProjectBuildException) ProcessAdapter(com.intellij.execution.process.ProcessAdapter) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) ExecutionException(com.intellij.execution.ExecutionException) BaseOSProcessHandler(com.intellij.execution.process.BaseOSProcessHandler)

Example 10 with GeneralCommandLine

use of com.intellij.execution.configurations.GeneralCommandLine in project intellij-elixir by KronicDeth.

the class ExtProcessUtil method execAndGetFirstLine.

@NotNull
public static ExtProcessOutput execAndGetFirstLine(long timeout, @NotNull String... command) {
    try {
        final Process cmdRunner = new GeneralCommandLine(command).createProcess();
        ExecutorService singleTreadExecutor = Executors.newSingleThreadExecutor();
        try {
            Future<ExtProcessOutput> cmdRunnerFuture = singleTreadExecutor.submit(new Callable<ExtProcessOutput>() {

                @Override
                public ExtProcessOutput call() throws Exception {
                    cmdRunner.waitFor();
                    String stdOut = readLine(cmdRunner.getInputStream());
                    String stdErr = readLine(cmdRunner.getErrorStream());
                    return new ExtProcessOutput(stdOut, stdErr);
                }
            });
            try {
                return cmdRunnerFuture.get(timeout, TimeUnit.MILLISECONDS);
            } catch (Exception e) {
            // Suppress
            }
            cmdRunnerFuture.cancel(true);
        } finally {
            singleTreadExecutor.shutdown();
        }
    } catch (ExecutionException e) {
    // Suppress
    }
    return new ExtProcessOutput("", "");
}
Also used : GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) ExecutionException(com.intellij.execution.ExecutionException) ExecutionException(com.intellij.execution.ExecutionException) IOException(java.io.IOException) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)136 ExecutionException (com.intellij.execution.ExecutionException)42 File (java.io.File)35 NotNull (org.jetbrains.annotations.NotNull)35 ProcessOutput (com.intellij.execution.process.ProcessOutput)20 VirtualFile (com.intellij.openapi.vfs.VirtualFile)19 CapturingProcessHandler (com.intellij.execution.process.CapturingProcessHandler)10 Project (com.intellij.openapi.project.Project)10 Key (com.intellij.openapi.util.Key)10 IOException (java.io.IOException)10 Nullable (org.jetbrains.annotations.Nullable)10 OSProcessHandler (com.intellij.execution.process.OSProcessHandler)9 ProcessHandler (com.intellij.execution.process.ProcessHandler)7 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)7 Sdk (com.intellij.openapi.projectRoots.Sdk)7 PsiFile (com.intellij.psi.PsiFile)7 Test (org.junit.Test)6 CapturingAnsiEscapesAwareProcessHandler (com.intellij.execution.process.CapturingAnsiEscapesAwareProcessHandler)5 ArrayList (java.util.ArrayList)5 RunResult (org.jetbrains.kotlin.android.tests.run.RunResult)5