@RequiresBackgroundThread
  private static boolean waitForProcessExecution(
    @NotNull Project project,
    @NotNull ExecutionEnvironment environment,
    @NotNull ThrowableRunnable<ExecutionException> runnable
  ) {
    try (var disposable = new AutoCloseableDisposable()) {
      var targetDone = new Semaphore();
      var result = new Ref<>(false);

      var executorId = environment.getExecutor().getId();
      project.getMessageBus().connect(disposable).subscribe(ExecutionManager.EXECUTION_TOPIC, new ExecutionListener() {
        @Override
        public void processStartScheduled(@NotNull String executorIdLocal, @NotNull ExecutionEnvironment environmentLocal) {
          if (executorId.equals(executorIdLocal) && environment.equals(environmentLocal)) {
            targetDone.down();
          }
        }

        @Override
        public void processNotStarted(@NotNull String executorIdLocal, @NotNull ExecutionEnvironment environmentLocal) {
          if (executorId.equals(executorIdLocal) && environment.equals(environmentLocal)) {
            targetDone.up();
          }
        }

        @Override
        public void processTerminated(
          @NotNull String executorIdLocal,
          @NotNull ExecutionEnvironment environmentLocal,
          @NotNull ProcessHandler handler,
          int exitCode
        ) {
          if (executorId.equals(executorIdLocal) && environment.equals(environmentLocal)) {
            result.set(exitCode == 0);
            targetDone.up();
          }
        }
      });
      try {
        ApplicationManager.getApplication().invokeAndWait(() -> {
          try {
            runnable.run();
          }
          catch (ExecutionException e) {
            targetDone.up();
            LOG.error(e);
          }
        }, ModalityState.defaultModalityState());
      }
      catch (Exception e) {
        targetDone.up();
        LOG.error(e);
      }
      targetDone.waitFor();
      return result.get();
    }
  }
@RequiresBackgroundThread
  private static boolean waitForProcessExecution(
    @NotNull Project project,
    @NotNull ExecutionEnvironment environment,
    @NotNull ThrowableRunnable<ExecutionException> runnable
  )