Promise<Object> (final @NotNull PlaybackContext context) { final ActionCallback actionCallback = new ActionCallbackProfilerStopper(); List<String> arguments = extractCommandList(PREFIX, " "); String mode = arguments.remove(0); Project project = context.getProject(); MessageBusConnection connection = project.getMessageBus().connect(); SpanBuilder span = PerformanceTestSpan.TRACER.spanBuilder(SPAN_NAME).setParent(PerformanceTestSpan.getContext()); Ref<Span> spanRef = new Ref<>(); Ref<Scope> scopeRef = new Ref<>(); connection .subscribe(CompilerTopics.COMPILATION_STATUS, new CompilationStatusListener() { @Override public void compilationFinished(boolean aborted, int errors, int warnings, @NotNull CompileContext compileContext) { if (errors > 0) { CompilerMessage[] errorMessages = compileContext.getMessages(CompilerMessageCategory.ERROR); StringBuilder errorMessage = new StringBuilder("Errors happened during build: " + errors); for (CompilerMessage error : errorMessages) { errorMessage.append("\n").append(error); } context.message(errorMessage.toString(), getLine()); spanRef.get().setAttribute("Errors", errors); } if (warnings > 0) { CompilerMessage[] warningMessages = compileContext.getMessages(CompilerMessageCategory.WARNING); StringBuilder warningMessage = new StringBuilder("Warnings happened during build: " + warnings); for (CompilerMessage warning : warningMessages) { warningMessage.append("\n").append(warning); } context.message(warningMessage.toString(), getLine()); spanRef.get().setAttribute("Warnings", warnings); } connection.disconnect(); } }); ApplicationManager.getApplication().invokeLater(() -> { ProjectTaskManagerImpl.putBuildOriginator(project, this.getClass()); ProjectTaskManager instance = ProjectTaskManager.getInstance(project); Promise<ProjectTaskManager.Result> promise = null; spanRef.set(span.startSpan()); scopeRef.set(spanRef.get().makeCurrent()); switch (mode) { case BUILD -> promise = build(getModules(arguments, project), instance); case REBUILD -> promise = rebuild(getModules(arguments, project), instance); case RECOMPILE_FILES -> promise = recompileFiles(arguments, project); default -> actionCallback.reject("Specified mode is neither BUILD nor REBUILD nor RECOMPILE_FILES"); } if (promise != null) { promise.onSuccess(result -> { spanRef.get().end(); scopeRef.get().close(); boolean failed = hasCompilationErrors(result); if (failed) { String errorMessage = PerformanceTestingBundle.message("command.build.finish.with.compilation.errors"); context.message(errorMessage, getLine()); actionCallback.reject(errorMessage); } else if (result.hasErrors() || result.isAborted() || project.isDisposed()) { String errorMessage; if (result.hasErrors()) { errorMessage = PerformanceTestingBundle.message("command.build.finish.with.errors"); } else if (result.isAborted()) { errorMessage = PerformanceTestingBundle.message("command.build.aborted"); } else { errorMessage = PerformanceTestingBundle.message("command.build.project.disposed"); } context.message(errorMessage, getLine()); actionCallback.reject(errorMessage); } else { context.message(PerformanceTestingBundle.message("command.build.finish"), getLine()); actionCallback.setDone(); } }); } }); return Promises.toPromise(actionCallback); }