@NotNull
  private static Future<ProcessHandler> runBuildImpl(final AntBuildFileBase buildFile,
                                                     List<@NlsSafe String> targets,
                                                     @Nullable final AntBuildMessageView buildMessageViewToReuse,
                                                     final DataContext dataContext,
                                                     List<BuildFileProperty> additionalProperties,
                                                     @NotNull final AntBuildListener antBuildListener, final boolean waitFor) {
    final Project project = buildFile.getProject();
    CompletableFuture<ProcessHandler> future = new CompletableFuture<>();

    MessageView.getInstance(project).runWhenInitialized(() -> {
      final TargetEnvironmentRequest request;
      final SimpleJavaParameters javaParameters;
      final AntBuildListenerWrapper listenerWrapper = new AntBuildListenerWrapper(buildFile, antBuildListener);
      try {
        FileDocumentManager.getInstance().saveAllDocuments();
        final AntCommandLineBuilder builder = new AntCommandLineBuilder();

        builder.setBuildFile(buildFile.getAllOptions(), VfsUtilCore.virtualToIoFile(buildFile.getVirtualFile()));
        builder.calculateProperties(dataContext, project, additionalProperties);
        builder.addTargets(targets);

        builder.getCommandLine().setCharset(EncodingProjectManager.getInstance(project).getDefaultCharset());

        javaParameters = builder.getCommandLine();

        WslTargetEnvironmentConfiguration wslConfiguration = JavaCommandLineState.checkCreateWslConfiguration(javaParameters.getJdk());
        if (wslConfiguration != null) {
          request = new WslTargetEnvironmentRequest(wslConfiguration);
        }
        else {
          request = new LocalTargetEnvironmentRequest();
        }

        final AntBuildMessageView messageView = prepareMessageView(buildMessageViewToReuse, buildFile, targets, additionalProperties);
        project.getMessageBus().syncPublisher(AntExecutionListener.TOPIC).beforeExecution(new AntBeforeExecutionEvent(buildFile, messageView));

        new Task.Backgroundable(project, AntBundle.message("ant.build.progress.dialog.title"), true) {

          @Override
          public void onCancel() {
            listenerWrapper.buildFinished(AntBuildListener.ABORTED, 0);
          }

          @Override
          public void run(@NotNull final ProgressIndicator indicator) {
            try {
              TargetedCommandLineBuilder builder = javaParameters.toCommandLine(request);
              TargetEnvironment environment = request.prepareEnvironment(TargetProgressIndicator.EMPTY);
              TargetedCommandLine commandLine = builder.build();

              messageView.setBuildCommandLine(commandLine.getCommandPresentation(environment));

              ProcessHandler handler = runBuild(indicator, messageView, buildFile, listenerWrapper, commandLine, environment);
              future.complete(handler);
              if (waitFor && handler != null) {
                handler.waitFor();
              }
            }
            catch (Throwable e) {
              LOG.error(e);
              listenerWrapper.buildFinished(AntBuildListener.FAILED_TO_RUN, 0);
            }
          }
        }.queue();

      }
      catch (RunCanceledException e) {
        e.showMessage(project, AntBundle.message("run.ant.error.dialog.title"));
        listenerWrapper.buildFinished(AntBuildListener.FAILED_TO_RUN, 0);
        future.complete(null);
      }
      catch (CantRunException e) {
        ExecutionErrorDialog.show(e, AntBundle.message("cant.run.ant.error.dialog.title"), project);
        listenerWrapper.buildFinished(AntBuildListener.FAILED_TO_RUN, 0);
        future.complete(null);
      }
      catch (Macro.ExecutionCancelledException e) {
        listenerWrapper.buildFinished(AntBuildListener.ABORTED, 0);
        future.complete(null);
      }
      catch (Throwable e) {
        listenerWrapper.buildFinished(AntBuildListener.FAILED_TO_RUN, 0);
        LOG.error(e);
        future.complete(null);
      }

    });

    return future;
  }
@NotNull
  private static Future<ProcessHandler> runBuildImpl(final AntBuildFileBase buildFile,
                                                     List<@NlsSafe String> targets,
                                                     @Nullable final AntBuildMessageView buildMessageViewToReuse,
                                                     final DataContext dataContext,
                                                     List<BuildFileProperty> additionalProperties,
                                                     @NotNull final AntBuildListener antBuildListener, final boolean waitFor)