From 798bcad01c5d31345a53cef758bb54fac572a444 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Mon, 27 Jan 2014 13:21:03 +0100 Subject: [PATCH] CR-IC-4108 --- .../runners/AsyncGenericProgramRunner.java | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/platform/lang-api/src/com/intellij/execution/runners/AsyncGenericProgramRunner.java b/platform/lang-api/src/com/intellij/execution/runners/AsyncGenericProgramRunner.java index 6751d355347e..feb611f718c9 100644 --- a/platform/lang-api/src/com/intellij/execution/runners/AsyncGenericProgramRunner.java +++ b/platform/lang-api/src/com/intellij/execution/runners/AsyncGenericProgramRunner.java @@ -20,6 +20,7 @@ import com.intellij.execution.configurations.*; import com.intellij.execution.ui.RunContentDescriptor; import com.intellij.openapi.options.SettingsEditor; import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.AsyncResult; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -63,10 +64,11 @@ public abstract class AsyncGenericProgramRunner return; } RunManager.getInstance(project).refreshUsagesList(env.getRunProfile()); - prepare(project, env, state, new RunProfileStarterConsumer() { + final AsyncResult result = prepare(project, env, state); + result.doWhenProcessed(new Runnable() { @Override - public void consume(@NotNull RunProfileStarter starter) { - startRunProfile(project, env, state, callback, starter); + public void run() { + startRunProfile(project, env, state, callback, result.getResult()); } }); } @@ -79,22 +81,18 @@ public abstract class AsyncGenericProgramRunner * @param project Project instance * @param env ExecutionEnvironment instance * @param state RunProfileState instance - * @param consumer RunProfileStarterConsumer instance; if no further actual execution is needed, then {@code consumer.consume} method shouldn't be called. + * @return RunProfileStarter async result */ - protected abstract void prepare(@NotNull Project project, - @NotNull ExecutionEnvironment env, - @NotNull RunProfileState state, - @NotNull RunProfileStarterConsumer consumer) throws ExecutionException; - - public interface RunProfileStarterConsumer { - void consume(@NotNull RunProfileStarter provider); - } + @NotNull + protected abstract AsyncResult prepare(@NotNull Project project, + @NotNull ExecutionEnvironment env, + @NotNull RunProfileState state) throws ExecutionException; private static void startRunProfile(@NotNull Project project, @NotNull ExecutionEnvironment environment, @NotNull RunProfileState state, @Nullable final Callback callback, - @NotNull final RunProfileStarter starter) { + @Nullable final RunProfileStarter starter) { ExecutionManager.getInstance(project).startRunProfile(new RunProfileStarter() { @Override public RunContentDescriptor execute(@NotNull Project project, @@ -102,7 +100,7 @@ public abstract class AsyncGenericProgramRunner @NotNull RunProfileState state, @Nullable RunContentDescriptor contentToReuse, @NotNull ExecutionEnvironment env) throws ExecutionException { - RunContentDescriptor descriptor = starter.execute(project, executor, state, contentToReuse, env); + RunContentDescriptor descriptor = starter == null ? null : starter.execute(project, executor, state, contentToReuse, env); if (descriptor != null) { descriptor.setExecutionId(env.getExecutionId()); }