Future<ProcessHandler> (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 AntBuildMessageView messageView; final TargetEnvironmentRequest request; final SimpleJavaParameters javaParameters; final AntBuildListenerWrapper listenerWrapper = new AntBuildListenerWrapper(buildFile, antBuildListener); final Project project = buildFile.getProject(); try { FileDocumentManager.getInstance().saveAllDocuments(); final AntCommandLineBuilder builder = new AntCommandLineBuilder(); builder.setBuildFile(buildFile.getAllOptions(), VfsUtilCore.virtualToIoFile(buildFile.getVirtualFile())); builder.calculateProperties(dataContext, buildFile.getProject(), additionalProperties); builder.addTargets(targets); builder.getCommandLine().setCharset(EncodingProjectManager.getInstance(buildFile.getProject()).getDefaultCharset()); messageView = prepareMessageView(buildMessageViewToReuse, buildFile, targets, additionalProperties); javaParameters = builder.getCommandLine(); WslTargetEnvironmentConfiguration wslConfiguration = JavaCommandLineState.checkCreateWslConfiguration(javaParameters.getJdk()); if (wslConfiguration != null) { request = new WslTargetEnvironmentRequest(wslConfiguration); } else { request = new LocalTargetEnvironmentRequest(); } project.getMessageBus().syncPublisher(AntExecutionListener.TOPIC).beforeExecution(new AntBeforeExecutionEvent(buildFile, messageView)); } catch (RunCanceledException e) { e.showMessage(project, AntBundle.message("run.ant.error.dialog.title")); listenerWrapper.buildFinished(AntBuildListener.FAILED_TO_RUN, 0); return null; } catch (CantRunException e) { ExecutionErrorDialog.show(e, AntBundle.message("cant.run.ant.error.dialog.title"), project); listenerWrapper.buildFinished(AntBuildListener.FAILED_TO_RUN, 0); return null; } catch (Macro.ExecutionCancelledException e) { listenerWrapper.buildFinished(AntBuildListener.ABORTED, 0); return null; } catch (Throwable e) { listenerWrapper.buildFinished(AntBuildListener.FAILED_TO_RUN, 0); LOG.error(e); return null; } CompletableFuture<ProcessHandler> future = new CompletableFuture<>(); new Task.Backgroundable(buildFile.getProject(), 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(); return future; }