use of com.intellij.execution.process.ProcessAdapter in project intellij-community by JetBrains.
the class PyCCCommandLineState method doCreateProcess.
@Override
protected ProcessHandler doCreateProcess(GeneralCommandLine commandLine) throws ExecutionException {
ProcessHandler handler = super.doCreateProcess(commandLine);
handler.addProcessListener(new ProcessAdapter() {
@Override
public void processTerminated(ProcessEvent event) {
ApplicationManager.getApplication().invokeLater(() -> EduUtils.deleteWindowDescriptions(myTask, myTaskDir));
}
});
return handler;
}
use of com.intellij.execution.process.ProcessAdapter in project intellij-community by JetBrains.
the class JavaTestFrameworkRunnableState method execute.
@NotNull
@Override
public ExecutionResult execute(@NotNull Executor executor, @NotNull ProgramRunner runner) throws ExecutionException {
final RunnerSettings runnerSettings = getRunnerSettings();
final SMTRunnerConsoleProperties testConsoleProperties = getConfiguration().createTestConsoleProperties(executor);
testConsoleProperties.setIfUndefined(TestConsoleProperties.HIDE_PASSED_TESTS, false);
final BaseTestsOutputConsoleView consoleView = SMTestRunnerConnectionUtil.createConsole(getFrameworkName(), testConsoleProperties);
final SMTestRunnerResultsForm viewer = ((SMTRunnerConsoleView) consoleView).getResultsViewer();
Disposer.register(getConfiguration().getProject(), consoleView);
final OSProcessHandler handler = createHandler(executor);
consoleView.attachToProcess(handler);
final AbstractTestProxy root = viewer.getRoot();
if (root instanceof TestProxyRoot) {
((TestProxyRoot) root).setHandler(handler);
}
handler.addProcessListener(new ProcessAdapter() {
@Override
public void startNotified(ProcessEvent event) {
if (getConfiguration().isSaveOutputToFile()) {
final File file = OutputFileUtil.getOutputFile(getConfiguration());
root.setOutputFilePath(file != null ? file.getAbsolutePath() : null);
}
}
@Override
public void processTerminated(ProcessEvent event) {
Runnable runnable = () -> {
root.flushOutputFile();
deleteTempFiles();
clear();
};
UIUtil.invokeLaterIfNeeded(runnable);
handler.removeProcessListener(this);
}
});
AbstractRerunFailedTestsAction rerunFailedTestsAction = testConsoleProperties.createRerunFailedTestsAction(consoleView);
LOG.assertTrue(rerunFailedTestsAction != null);
rerunFailedTestsAction.setModelProvider(() -> viewer);
final DefaultExecutionResult result = new DefaultExecutionResult(consoleView, handler);
result.setRestartActions(rerunFailedTestsAction, new ToggleAutoTestAction() {
@Override
public boolean isDelayApplicable() {
return false;
}
@Override
public AbstractAutoTestManager getAutoTestManager(Project project) {
return JavaAutoRunManager.getInstance(project);
}
});
JavaRunConfigurationExtensionManager.getInstance().attachExtensionsToProcess(getConfiguration(), handler, runnerSettings);
return result;
}
use of com.intellij.execution.process.ProcessAdapter 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.ProcessAdapter in project intellij-community by JetBrains.
the class RunContentExecutor method run.
public void run() {
FileDocumentManager.getInstance().saveAllDocuments();
// Use user-provided console if exist. Create new otherwise
ConsoleView view = (myUserProvidedConsole != null ? myUserProvidedConsole : createConsole());
view.attachToProcess(myProcess);
if (myAfterCompletion != null) {
myProcess.addProcessListener(new ProcessAdapter() {
@Override
public void processTerminated(ProcessEvent event) {
ApplicationManager.getApplication().invokeLater(myAfterCompletion);
}
});
}
myProcess.startNotify();
}
use of com.intellij.execution.process.ProcessAdapter in project intellij-community by JetBrains.
the class AppletConfiguration method getState.
@Override
public RunProfileState getState(@NotNull final Executor executor, @NotNull final ExecutionEnvironment env) throws ExecutionException {
return new JavaCommandLineState(env) {
private AppletHtmlFile myHtmlURL = null;
@Override
protected JavaParameters createJavaParameters() throws ExecutionException {
final JavaParameters params = new JavaParameters();
myHtmlURL = getHtmlURL();
if (myHtmlURL != null) {
final int classPathType = myHtmlURL.isHttp() ? JavaParameters.JDK_ONLY : JavaParameters.JDK_AND_CLASSES;
final RunConfigurationModule runConfigurationModule = getConfigurationModule();
JavaParametersUtil.configureModule(runConfigurationModule, params, classPathType, ALTERNATIVE_JRE_PATH_ENABLED ? ALTERNATIVE_JRE_PATH : null);
final String policyFileParameter = getPolicyFileParameter();
if (policyFileParameter != null) {
params.getVMParametersList().add(policyFileParameter);
}
params.getVMParametersList().addParametersString(VM_PARAMETERS);
params.setMainClass("sun.applet.AppletViewer");
params.getProgramParametersList().add(myHtmlURL.getUrl());
}
return params;
}
@Override
@NotNull
protected OSProcessHandler startProcess() throws ExecutionException {
final OSProcessHandler handler = super.startProcess();
final AppletHtmlFile htmlUrl = myHtmlURL;
if (htmlUrl != null) {
handler.addProcessListener(new ProcessAdapter() {
@Override
public void processTerminated(ProcessEvent event) {
htmlUrl.deleteFile();
}
});
}
return handler;
}
};
}
Aggregations