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;
}
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;
}
};
}
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();
}
}
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);
}
}
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);
}
}
Aggregations