Search in sources :

Example 31 with OSProcessHandler

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

the class FlutterDoctorAction method runWorkspaceFlutterDoctorScript.

private void runWorkspaceFlutterDoctorScript(@NotNull Project project, @NotNull String workDir, @NotNull String doctorScript) {
    final GeneralCommandLine cmdLine = new GeneralCommandLine().withWorkDirectory(workDir);
    cmdLine.setCharset(CharsetToolkit.UTF8_CHARSET);
    cmdLine.setExePath(FileUtil.toSystemDependentName(doctorScript));
    final OSProcessHandler handler;
    try {
        handler = new OSProcessHandler(cmdLine);
        FlutterConsoles.displayProcessLater(handler, project, null, handler::startNotify);
    } catch (ExecutionException e) {
        LOG.error(e);
    }
}
Also used : OSProcessHandler(com.intellij.execution.process.OSProcessHandler) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) ExecutionException(com.intellij.execution.ExecutionException)

Example 32 with OSProcessHandler

use of com.intellij.execution.process.OSProcessHandler in project google-cloud-intellij by GoogleCloudPlatform.

the class CloudSdkStartupPolicy method createStartupScriptHelper.

@Nullable
@Override
public ScriptHelper createStartupScriptHelper(final ProgramRunner programRunner) {
    return new ScriptHelper() {

        @Nullable
        @Override
        public ExecutableObject getDefaultScript(final CommonModel commonModel) {
            return new ExecutableObject() {

                @Override
                public String getDisplayString() {
                    return GctBundle.getString("appengine.run.startupscript.name");
                }

                @Override
                public OSProcessHandler createProcessHandler(String workingDirectory, Map<String, String> configuredEnvironment) throws ExecutionException {
                    try {
                        CloudSdkServiceManager.getInstance().blockUntilSdkReady(commonModel.getProject(), GctBundle.getString("appengine.run.startupscript"), new CloudSdkStatusHandler() {

                            @Override
                            public void log(String s) {
                                logger.info("Cloud SDK precondition check reported: " + s);
                            }

                            @Override
                            public void onError(String s) {
                                logger.warn("Cloud SDK precondition check reported error: " + s);
                            }

                            @Override
                            public void onUserCancel() {
                            }

                            @Override
                            public String getErrorMessage(SdkStatus sdkStatus) {
                                switch(sdkStatus) {
                                    case INVALID:
                                    case NOT_AVAILABLE:
                                        return GctBundle.message("appengine.run.server.sdk.misconfigured.message");
                                    default:
                                        return "";
                                }
                            }
                        });
                    } catch (InterruptedException e) {
                        // should not happen, but would be an error.
                        throw new ExecutionException(GctBundle.message("appengine.run.server.sdk.misconfigured.message"));
                    }
                    // wait complete, check the final status here manually.
                    SdkStatus sdkStatus = CloudSdkService.getInstance().getStatus();
                    switch(sdkStatus) {
                        case INVALID:
                        case NOT_AVAILABLE:
                            throw new ExecutionException(GctBundle.message("appengine.run.server.sdk.misconfigured.message"));
                        case INSTALLING:
                            // cannot continue still installing.
                            throw new ExecutionException(GctBundle.message("appengine.run.server.sdk.installing.message"));
                        case READY:
                            // continue to start local dev server process.
                            break;
                    }
                    Sdk javaSdk = ProjectRootManager.getInstance(commonModel.getProject()).getProjectSdk();
                    if (javaSdk == null || javaSdk.getHomePath() == null) {
                        throw new ExecutionException(GctBundle.message("appengine.run.server.nosdk"));
                    }
                    AppEngineServerModel runConfiguration;
                    try {
                        // Getting the clone so the debug flags aren't added
                        // to the persisted settings.
                        runConfiguration = (AppEngineServerModel) commonModel.getServerModel().clone();
                    } catch (CloneNotSupportedException ee) {
                        throw new ExecutionException(ee);
                    }
                    Map<String, String> environment = Maps.newHashMap(configuredEnvironment);
                    // IntelliJ appends the JVM flags to the environment
                    // variables, keyed by an empty
                    // string; so we need extract them here.
                    String jvmFlags = environment.get(JVM_FLAGS_ENVIRONMENT_KEY);
                    if (jvmFlags != null) {
                        runConfiguration.appendJvmFlags(Arrays.asList(jvmFlags.trim().split(" ")));
                    }
                    // We don't want to pass the jvm flags to the dev server environment
                    environment.remove(JVM_FLAGS_ENVIRONMENT_KEY);
                    runConfiguration.setEnvironment(environment);
                    AppEngineStandardRunTask runTask = new AppEngineStandardRunTask(runConfiguration, javaSdk, programRunner.getRunnerId());
                    AppEngineExecutor executor = new AppEngineExecutor(runTask);
                    executor.run();
                    Process devappserverProcess = executor.getProcess();
                    startupProcessHandler = new OSProcessHandler(devappserverProcess, GctBundle.getString("appengine.run.startupscript"));
                    return startupProcessHandler;
                }
            };
        }
    };
}
Also used : ExecutableObject(com.intellij.javaee.run.localRun.ExecutableObject) AppEngineServerModel(com.google.cloud.tools.intellij.appengine.server.instance.AppEngineServerModel) AppEngineStandardRunTask(com.google.cloud.tools.intellij.appengine.cloud.executor.AppEngineStandardRunTask) AppEngineExecutor(com.google.cloud.tools.intellij.appengine.cloud.executor.AppEngineExecutor) CommonModel(com.intellij.javaee.run.configuration.CommonModel) OSProcessHandler(com.intellij.execution.process.OSProcessHandler) CloudSdkStatusHandler(com.google.cloud.tools.intellij.appengine.sdk.CloudSdkServiceManager.CloudSdkStatusHandler) Sdk(com.intellij.openapi.projectRoots.Sdk) ScriptHelper(com.intellij.javaee.run.localRun.ScriptHelper) ExecutionException(com.intellij.execution.ExecutionException) Map(java.util.Map) SdkStatus(com.google.cloud.tools.intellij.appengine.sdk.CloudSdkService.SdkStatus) Nullable(org.jetbrains.annotations.Nullable)

Example 33 with OSProcessHandler

use of com.intellij.execution.process.OSProcessHandler in project google-cloud-intellij by GoogleCloudPlatform.

the class AppEngineServerInstance method shutdown.

@Override
public void shutdown() {
    super.shutdown();
    ProcessHandler processHandler = getProcessHandler();
    if (processHandler instanceof OSProcessHandler) {
        // todo[nik] remove later. This fix is necessary only for IDEA 8.x
        ((OSProcessHandler) processHandler).getProcess().destroy();
    }
}
Also used : OSProcessHandler(com.intellij.execution.process.OSProcessHandler) OSProcessHandler(com.intellij.execution.process.OSProcessHandler) ProcessHandler(com.intellij.execution.process.ProcessHandler)

Example 34 with OSProcessHandler

use of com.intellij.execution.process.OSProcessHandler in project intellij-elixir by KronicDeth.

the class Root method mixTask.

/**
 * private methods
 */
private static void mixTask(@NotNull final String workingDirectory, @NotNull final Sdk sdk, @SuppressWarnings("SameParameterValue") @NotNull final String title, @SuppressWarnings("SameParameterValue") @NotNull final String task, @NotNull final String... taskParameters) {
    ProgressManager.getInstance().run(new Task.Modal(null, title, true) {

        @Override
        public void run(@NotNull final ProgressIndicator indicator) {
            indicator.setIndeterminate(true);
            GeneralCommandLine generalCommandLine = Mix.commandLine(emptyMap(), workingDirectory, sdk, emptyList(), emptyList());
            generalCommandLine.addParameter(task);
            generalCommandLine.addParameters(taskParameters);
            try {
                OSProcessHandler handler = new OSProcessHandler(generalCommandLine.createProcess(), generalCommandLine.getPreparedCommandLine(Platform.current()));
                handler.addProcessListener(new ProcessAdapter() {

                    @Override
                    public void onTextAvailable(ProcessEvent event, Key outputType) {
                        String text = event.getText();
                        indicator.setText2(text);
                    }
                });
                ProcessTerminatedListener.attach(handler);
                handler.startNotify();
                handler.waitFor();
                indicator.setText2("Refreshing");
            } catch (ExecutionException e) {
                LOG.warn(e);
            }
        }
    });
}
Also used : Task(com.intellij.openapi.progress.Task) ProcessAdapter(com.intellij.execution.process.ProcessAdapter) ProcessEvent(com.intellij.execution.process.ProcessEvent) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) OSProcessHandler(com.intellij.execution.process.OSProcessHandler) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) ExecutionException(com.intellij.execution.ExecutionException) Key(com.intellij.openapi.util.Key)

Example 35 with OSProcessHandler

use of com.intellij.execution.process.OSProcessHandler in project freeline by alibaba.

the class FreelineUtil method processCommandline.

/* process command line */
private static void processCommandline(final Project project, GeneralCommandLine commandLine) throws ExecutionException {
    final OSProcessHandler processHandler = new OSProcessHandler(commandLine);
    ProcessTerminatedListener.attach(processHandler);
    processHandler.startNotify();
    ApplicationManager.getApplication().invokeLater(new Runnable() {

        @Override
        public void run() {
            processConsole(project, processHandler);
        }
    });
}
Also used : OSProcessHandler(com.intellij.execution.process.OSProcessHandler)

Aggregations

OSProcessHandler (com.intellij.execution.process.OSProcessHandler)55 ExecutionException (com.intellij.execution.ExecutionException)25 GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)24 ProcessEvent (com.intellij.execution.process.ProcessEvent)24 ProcessAdapter (com.intellij.execution.process.ProcessAdapter)23 NotNull (org.jetbrains.annotations.NotNull)18 Key (com.intellij.openapi.util.Key)14 ProcessHandler (com.intellij.execution.process.ProcessHandler)6 Project (com.intellij.openapi.project.Project)6 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6 File (java.io.File)6 Module (com.intellij.openapi.module.Module)5 Sdk (com.intellij.openapi.projectRoots.Sdk)5 IOException (java.io.IOException)5 ProgramRunner (com.intellij.execution.runners.ProgramRunner)4 Nullable (org.jetbrains.annotations.Nullable)4 Executor (com.intellij.execution.Executor)3 RunContentExecutor (com.intellij.execution.RunContentExecutor)3 KillableColoredProcessHandler (com.intellij.execution.process.KillableColoredProcessHandler)3 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)3