Promise<Object> (@NotNull final PlaybackContext context) { //example: %runConfiguration TILL_TERMINATED My Run Configuration String[] command = extractCommandArgument(PREFIX).split(" ", 2); String mode = command[0]; String configurationNameToRun = command[1]; Timer timer = new Timer(); final ActionCallback actionCallback = new ActionCallbackProfilerStopper(); Project project = context.getProject(); MessageBusConnection connection = project.getMessageBus().connect(); connection.subscribe(ExecutionManager.EXECUTION_TOPIC, new ExecutionListener() { @Override public void processStarting(@NotNull String executorId, @NotNull ExecutionEnvironment env, @NotNull ProcessHandler handler) { timer.start(); myExecutionEnvironment = env; context.message("processStarting: " + env, getLine()); } @Override public void processStarted(@NotNull String executorId, @NotNull ExecutionEnvironment env, @NotNull ProcessHandler handler) { myExecutionEnvironment = env; if (mode.equals(WAIT_FOR_PROCESS_STARTED)) { timer.stop(); long executionTime = timer.getTotalTime(); context.message("processStarted in: " + env + ": " + executionTime, getLine()); actionCallback.setDone(); } } @Override public void processTerminated(@NotNull String executorId, @NotNull ExecutionEnvironment env, @NotNull ProcessHandler handler, int exitCode) { if (mode.equals(WAIT_FOR_PROCESS_TERMINATED)) { timer.stop(); long executionTime = timer.getTotalTime(); context.message("processTerminated in: " + env + ": " + executionTime, getLine()); if (env.equals(myExecutionEnvironment)) { if (exitCode == 0) { actionCallback.setDone(); } else { actionCallback.reject("Run configuration is finished with exitCode: " + exitCode); } connection.disconnect(); } } } }); RunManagerImpl runManager = RunManagerImpl.getInstanceImpl(project); ApplicationManager.getApplication().invokeLater(() -> { if (!mode.contains(WAIT_FOR_PROCESS_STARTED) && !mode.contains(WAIT_FOR_PROCESS_TERMINATED)) { actionCallback.reject("Specified mode is neither TILL_STARTED nor TILL_TERMINATED"); } Executor executor = new DefaultRunExecutor(); ExecutionTarget target = DefaultExecutionTarget.INSTANCE; RunConfiguration configurationToRun = getConfigurationByName(runManager, configurationNameToRun); if (configurationToRun == null) { actionCallback.reject("Specified configuration is not found: " + configurationNameToRun); printAllConfigurationsNames(runManager); } else { RunnerAndConfigurationSettingsImpl runnerAndConfigurationSettings = new RunnerAndConfigurationSettingsImpl(runManager, configurationToRun); ExecutionManager.getInstance(project).restartRunProfile(project, executor, target, runnerAndConfigurationSettings, null); } }); return Promises.toPromise(actionCallback); }