CR-IC-4108

This commit is contained in:
Vladimir Krivosheev
2014-01-27 13:21:03 +01:00
parent eb65f3ec30
commit 798bcad01c
@@ -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<Settings extends RunnerSettings>
return;
}
RunManager.getInstance(project).refreshUsagesList(env.getRunProfile());
prepare(project, env, state, new RunProfileStarterConsumer() {
final AsyncResult<RunProfileStarter> 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<Settings extends RunnerSettings>
* @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<RunProfileStarter> 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<Settings extends RunnerSettings>
@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());
}