Search in sources :

Example 31 with ProcessHandler

use of com.intellij.execution.process.ProcessHandler in project android by JetBrains.

the class AndroidProgramRunner method doExecute.

@Override
protected RunContentDescriptor doExecute(@NotNull final RunProfileState state, @NotNull final ExecutionEnvironment env) throws ExecutionException {
    boolean showRunContent = env.getRunProfile() instanceof AndroidTestRunConfiguration;
    RunnerAndConfigurationSettings runnerAndConfigurationSettings = env.getRunnerAndConfigurationSettings();
    if (runnerAndConfigurationSettings != null) {
        runnerAndConfigurationSettings.setActivateToolWindowBeforeRun(showRunContent);
    }
    RunContentDescriptor descriptor = super.doExecute(state, env);
    if (descriptor != null) {
        ProcessHandler processHandler = descriptor.getProcessHandler();
        assert processHandler != null;
        RunProfile runProfile = env.getRunProfile();
        int uniqueId = runProfile instanceof RunConfigurationBase ? ((RunConfigurationBase) runProfile).getUniqueID() : -1;
        AndroidSessionInfo sessionInfo = new AndroidSessionInfo(processHandler, descriptor, uniqueId, env.getExecutor().getId(), InstantRunUtils.isInstantRunEnabled(env));
        processHandler.putUserData(AndroidSessionInfo.KEY, sessionInfo);
    }
    return descriptor;
}
Also used : RunConfigurationBase(com.intellij.execution.configurations.RunConfigurationBase) RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) AndroidTestRunConfiguration(com.android.tools.idea.testartifacts.instrumented.AndroidTestRunConfiguration) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) ProcessHandler(com.intellij.execution.process.ProcessHandler) RunProfile(com.intellij.execution.configurations.RunProfile)

Example 32 with ProcessHandler

use of com.intellij.execution.process.ProcessHandler in project android by JetBrains.

the class AndroidTestRunConfiguration method getConsoleProvider.

@NotNull
@Override
protected ConsoleProvider getConsoleProvider() {
    return new ConsoleProvider() {

        @NotNull
        @Override
        public ConsoleView createAndAttach(@NotNull Disposable parent, @NotNull ProcessHandler handler, @NotNull Executor executor) throws ExecutionException {
            AndroidTestConsoleProperties properties = new AndroidTestConsoleProperties(AndroidTestRunConfiguration.this, executor);
            ConsoleView consoleView = SMTestRunnerConnectionUtil.createAndAttachConsole("Android", handler, properties);
            Disposer.register(parent, consoleView);
            return consoleView;
        }
    };
}
Also used : Disposable(com.intellij.openapi.Disposable) ConsoleView(com.intellij.execution.ui.ConsoleView) ProcessHandler(com.intellij.execution.process.ProcessHandler) NotNull(org.jetbrains.annotations.NotNull) NotNull(org.jetbrains.annotations.NotNull)

Example 33 with ProcessHandler

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

the class ExternalSystemUtil method runTask.

public static void runTask(@NotNull final ExternalSystemTaskExecutionSettings taskSettings, @NotNull final String executorId, @NotNull final Project project, @NotNull final ProjectSystemId externalSystemId, @Nullable final TaskCallback callback, @NotNull final ProgressExecutionMode progressExecutionMode, boolean activateToolWindowBeforeRun) {
    ExecutionEnvironment environment = createExecutionEnvironment(project, externalSystemId, taskSettings, executorId);
    if (environment == null)
        return;
    RunnerAndConfigurationSettings runnerAndConfigurationSettings = environment.getRunnerAndConfigurationSettings();
    assert runnerAndConfigurationSettings != null;
    runnerAndConfigurationSettings.setActivateToolWindowBeforeRun(activateToolWindowBeforeRun);
    final TaskUnderProgress task = new TaskUnderProgress() {

        @Override
        public void execute(@NotNull ProgressIndicator indicator) {
            indicator.setIndeterminate(true);
            final Semaphore targetDone = new Semaphore();
            final Ref<Boolean> result = new Ref<>(false);
            final Disposable disposable = Disposer.newDisposable();
            project.getMessageBus().connect(disposable).subscribe(ExecutionManager.EXECUTION_TOPIC, new ExecutionListener() {

                public void processStartScheduled(@NotNull final String executorIdLocal, @NotNull final ExecutionEnvironment environmentLocal) {
                    if (executorId.equals(executorIdLocal) && environment.equals(environmentLocal)) {
                        targetDone.down();
                    }
                }

                public void processNotStarted(@NotNull final String executorIdLocal, @NotNull final ExecutionEnvironment environmentLocal) {
                    if (executorId.equals(executorIdLocal) && environment.equals(environmentLocal)) {
                        targetDone.up();
                    }
                }

                public void processStarted(@NotNull final String executorIdLocal, @NotNull final ExecutionEnvironment environmentLocal, @NotNull final ProcessHandler handler) {
                    if (executorId.equals(executorIdLocal) && environment.equals(environmentLocal)) {
                        handler.addProcessListener(new ProcessAdapter() {

                            public void processTerminated(ProcessEvent event) {
                                result.set(event.getExitCode() == 0);
                                targetDone.up();
                            }
                        });
                    }
                }
            });
            try {
                ApplicationManager.getApplication().invokeAndWait(() -> {
                    try {
                        environment.getRunner().execute(environment);
                    } catch (ExecutionException e) {
                        targetDone.up();
                        LOG.error(e);
                    }
                }, ModalityState.defaultModalityState());
            } catch (Exception e) {
                LOG.error(e);
                Disposer.dispose(disposable);
                return;
            }
            targetDone.waitFor();
            Disposer.dispose(disposable);
            if (callback != null) {
                if (result.get()) {
                    callback.onSuccess();
                } else {
                    callback.onFailure();
                }
            }
        }
    };
    final String title = AbstractExternalSystemTaskConfigurationType.generateName(project, taskSettings);
    switch(progressExecutionMode) {
        case NO_PROGRESS_SYNC:
            task.execute(new EmptyProgressIndicator());
            break;
        case MODAL_SYNC:
            new Task.Modal(project, title, true) {

                @Override
                public void run(@NotNull ProgressIndicator indicator) {
                    task.execute(indicator);
                }
            }.queue();
            break;
        case NO_PROGRESS_ASYNC:
            ApplicationManager.getApplication().executeOnPooledThread(() -> task.execute(new EmptyProgressIndicator()));
            break;
        case IN_BACKGROUND_ASYNC:
            new Task.Backgroundable(project, title) {

                @Override
                public void run(@NotNull ProgressIndicator indicator) {
                    task.execute(indicator);
                }
            }.queue();
            break;
        case START_IN_FOREGROUND_ASYNC:
            new Task.Backgroundable(project, title, true, PerformInBackgroundOption.DEAF) {

                @Override
                public void run(@NotNull ProgressIndicator indicator) {
                    task.execute(indicator);
                }
            }.queue();
    }
}
Also used : Disposable(com.intellij.openapi.Disposable) ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) Task(com.intellij.openapi.progress.Task) ExternalSystemResolveProjectTask(com.intellij.openapi.externalSystem.service.internal.ExternalSystemResolveProjectTask) ProcessAdapter(com.intellij.execution.process.ProcessAdapter) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) ProcessEvent(com.intellij.execution.process.ProcessEvent) Semaphore(com.intellij.util.concurrency.Semaphore) NotNull(org.jetbrains.annotations.NotNull) ImportCanceledException(com.intellij.openapi.externalSystem.service.ImportCanceledException) IOException(java.io.IOException) Ref(com.intellij.openapi.util.Ref) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) ProcessHandler(com.intellij.execution.process.ProcessHandler)

Example 34 with ProcessHandler

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

the class Tool method execute.

public void execute(AnActionEvent event, DataContext dataContext, long executionId, @Nullable final ProcessListener processListener) {
    final Project project = CommonDataKeys.PROJECT.getData(dataContext);
    if (project == null) {
        return;
    }
    FileDocumentManager.getInstance().saveAllDocuments();
    try {
        if (isUseConsole()) {
            ExecutionEnvironment environment = ExecutionEnvironmentBuilder.create(project, DefaultRunExecutor.getRunExecutorInstance(), new ToolRunProfile(this, dataContext)).build();
            environment.setExecutionId(executionId);
            environment.getRunner().execute(environment, new ProgramRunner.Callback() {

                @Override
                public void processStarted(RunContentDescriptor descriptor) {
                    ProcessHandler processHandler = descriptor.getProcessHandler();
                    if (processHandler != null && processListener != null) {
                        LOG.assertTrue(!processHandler.isStartNotified(), "ProcessHandler is already startNotified, the listener won't be correctly notified");
                        processHandler.addProcessListener(processListener);
                    }
                }
            });
        } else {
            GeneralCommandLine commandLine = createCommandLine(dataContext);
            if (commandLine == null) {
                return;
            }
            OSProcessHandler handler = new OSProcessHandler(commandLine);
            handler.addProcessListener(new ToolProcessAdapter(project, synchronizeAfterExecution(), getName()));
            if (processListener != null) {
                handler.addProcessListener(processListener);
            }
            handler.startNotify();
        }
    } catch (ExecutionException ex) {
        ExecutionErrorDialog.show(ex, ToolsBundle.message("tools.process.start.error"), project);
    }
}
Also used : Project(com.intellij.openapi.project.Project) ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) OSProcessHandler(com.intellij.execution.process.OSProcessHandler) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) OSProcessHandler(com.intellij.execution.process.OSProcessHandler) ProcessHandler(com.intellij.execution.process.ProcessHandler) ProgramRunner(com.intellij.execution.runners.ProgramRunner) ExecutionException(com.intellij.execution.ExecutionException)

Example 35 with ProcessHandler

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

the class ExecutorRegistryImpl method initComponent.

@Override
public void initComponent() {
    ProjectManager.getInstance().addProjectManagerListener(new ProjectManagerAdapter() {

        @Override
        public void projectOpened(final Project project) {
            final MessageBusConnection connect = project.getMessageBus().connect(project);
            connect.subscribe(ExecutionManager.EXECUTION_TOPIC, new ExecutionListener() {

                @Override
                public void processStartScheduled(@NotNull String executorId, @NotNull ExecutionEnvironment environment) {
                    myInProgress.add(createExecutionId(executorId, environment));
                }

                @Override
                public void processNotStarted(@NotNull String executorId, @NotNull ExecutionEnvironment environment) {
                    myInProgress.remove(createExecutionId(executorId, environment));
                }

                @Override
                public void processStarted(@NotNull String executorId, @NotNull ExecutionEnvironment environment, @NotNull ProcessHandler handler) {
                    myInProgress.remove(createExecutionId(executorId, environment));
                }
            });
        }

        @Override
        public void projectClosed(final Project project) {
            // perform cleanup
            synchronized (myInProgress) {
                for (Iterator<Trinity<Project, String, String>> it = myInProgress.iterator(); it.hasNext(); ) {
                    final Trinity<Project, String, String> trinity = it.next();
                    if (project.equals(trinity.first)) {
                        it.remove();
                    }
                }
            }
        }
    });
    final Executor[] executors = Extensions.getExtensions(Executor.EXECUTOR_EXTENSION_NAME);
    for (Executor executor : executors) {
        initExecutor(executor);
    }
}
Also used : MessageBusConnection(com.intellij.util.messages.MessageBusConnection) ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) Trinity(com.intellij.openapi.util.Trinity) NotNull(org.jetbrains.annotations.NotNull) DefaultRunExecutor(com.intellij.execution.executors.DefaultRunExecutor) ProcessHandler(com.intellij.execution.process.ProcessHandler)

Aggregations

ProcessHandler (com.intellij.execution.process.ProcessHandler)100 NotNull (org.jetbrains.annotations.NotNull)31 RunContentDescriptor (com.intellij.execution.ui.RunContentDescriptor)24 ExecutionException (com.intellij.execution.ExecutionException)17 Project (com.intellij.openapi.project.Project)17 ConsoleView (com.intellij.execution.ui.ConsoleView)16 DefaultExecutionResult (com.intellij.execution.DefaultExecutionResult)15 ProcessEvent (com.intellij.execution.process.ProcessEvent)14 ExecutionEnvironment (com.intellij.execution.runners.ExecutionEnvironment)14 ProcessAdapter (com.intellij.execution.process.ProcessAdapter)13 ProgramRunner (com.intellij.execution.runners.ProgramRunner)12 Nullable (org.jetbrains.annotations.Nullable)10 Executor (com.intellij.execution.Executor)9 GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)7 Disposable (com.intellij.openapi.Disposable)7 RunProfile (com.intellij.execution.configurations.RunProfile)6 OSProcessHandler (com.intellij.execution.process.OSProcessHandler)6 SMTRunnerConsoleView (com.intellij.execution.testframework.sm.runner.ui.SMTRunnerConsoleView)6 File (java.io.File)6 DefaultRunExecutor (com.intellij.execution.executors.DefaultRunExecutor)5