void ( @NotNull String externalProjectPath, @NotNull ImportSpec importSpec, @NotNull ExternalSystemResolveProjectTask resolveProjectTask, @NotNull ProgressIndicator indicator ) { var project = importSpec.getProject(); var taskId = resolveProjectTask.getId(); var externalSystemId = taskId.getProjectSystemId(); var callback = importSpec.getCallback(); var isPreviewMode = importSpec.isPreviewMode(); if (project.isDisposed()) return; if (indicator instanceof ProgressIndicatorEx indicatorEx) { indicatorEx.addStateDelegate(new AbstractProgressIndicatorExBase() { @Override public void cancel() { super.cancel(); resolveProjectTask.cancel(); } }); } var processingManager = ExternalSystemProcessingManager.getInstance(); if (processingManager.findTask(ExternalSystemTaskType.RESOLVE_PROJECT, externalSystemId, externalProjectPath) != null) { if (callback != null) { callback.onFailure(taskId, ExternalSystemBundle.message("error.resolve.already.running", externalProjectPath), null); } return; } if (!(callback instanceof MyMultiExternalProjectRefreshCallback)) { ExternalSystemNotificationManager.getInstance(project) .clearNotifications(null, NotificationSource.PROJECT_SYNC, externalSystemId); } if (!isPreviewMode) { var externalSystemTaskActivator = ExternalProjectsManagerImpl.getInstance(project).getTaskActivator(); if (!externalSystemTaskActivator.runTasks(externalProjectPath, ExternalSystemTaskActivator.Phase.BEFORE_SYNC)) { return; } } var projectName = resolveProjectTask.getProjectName(); var processHandler = new ExternalSystemProcessHandler(resolveProjectTask, projectName + " import") { @Override protected void destroyProcessImpl() { resolveProjectTask.cancel(); closeInput(); } }; var consoleManager = getConsoleManagerFor(resolveProjectTask); var consoleView = consoleManager.attachExecutionConsole(project, resolveProjectTask, null, processHandler); Disposer.register(project, Objects.requireNonNullElse(consoleView, processHandler)); var syncViewManager = project.getService(SyncViewManager.class); try (BuildEventDispatcher eventDispatcher = new ExternalSystemEventDispatcher(taskId, syncViewManager, false)) { var finishSyncEventSupplier = new Ref<Supplier<? extends FinishBuildEvent>>(); var taskListener = new ExternalSystemTaskNotificationListenerAdapter() { @Override public void onStart(@NotNull ExternalSystemTaskId id, String workingDir) { if (isPreviewMode) return; var buildDescriptor = createSyncDescriptor( externalProjectPath, importSpec, resolveProjectTask, processHandler, consoleView, consoleManager ); eventDispatcher.onEvent(id, new StartBuildEventImpl(buildDescriptor, BuildBundle.message("build.event.message.syncing"))); } @Override public void onTaskOutput(@NotNull ExternalSystemTaskId id, @NotNull String text, boolean stdOut) { processHandler.notifyTextAvailable(text, stdOut ? ProcessOutputTypes.STDOUT : ProcessOutputTypes.STDERR); eventDispatcher.setStdOut(stdOut); eventDispatcher.append(text); } @Override public void onFailure(@NotNull ExternalSystemTaskId id, @NotNull Exception e) { finishSyncEventSupplier.set(() -> { var eventTime = System.currentTimeMillis(); var eventMessage = BuildBundle.message("build.status.failed"); var externalSystemName = externalSystemId.getReadableName(); var title = ExternalSystemBundle.message("notification.project.refresh.fail.title", externalSystemName, projectName); var dataContext = BuildConsoleUtils.getDataContext(id, syncViewManager); var eventResult = createFailureResult(title, e, externalSystemId, project, externalProjectPath, dataContext); return new FinishBuildEventImpl(id, null, eventTime, eventMessage, eventResult); }); processHandler.notifyProcessTerminated(1); } @Override public void onCancel(@NotNull ExternalSystemTaskId id) { finishSyncEventSupplier.set(() -> { var eventTime = System.currentTimeMillis(); var eventMessage = BuildBundle.message("build.status.cancelled"); var eventResult = new FailureResultImpl(); return new FinishBuildEventImpl(id, null, eventTime, eventMessage, eventResult); }); processHandler.notifyProcessTerminated(1); } @Override public void onSuccess(@NotNull ExternalSystemTaskId id) { finishSyncEventSupplier.set(() -> { var eventTime = System.currentTimeMillis(); var eventMessage = BuildBundle.message("build.status.finished"); var eventResult = new SuccessResultImpl(); return new FinishBuildEventImpl(id, null, eventTime, eventMessage, eventResult); }); processHandler.notifyProcessTerminated(0); } @Override public void onStatusChange(@NotNull ExternalSystemTaskNotificationEvent event) { if (isPreviewMode) return; if (event instanceof ExternalSystemBuildEvent) { var buildEvent = ((ExternalSystemBuildEvent)event).getBuildEvent(); eventDispatcher.onEvent(event.getId(), buildEvent); } else if (event instanceof ExternalSystemTaskExecutionEvent) { var buildEvent = convert(((ExternalSystemTaskExecutionEvent)event)); eventDispatcher.onEvent(event.getId(), buildEvent); } } }; LOG.info("External project [" + externalProjectPath + "] resolution task started"); var startTS = System.currentTimeMillis(); resolveProjectTask.execute(indicator, taskListener); var endTS = System.currentTimeMillis(); LOG.info("External project [" + externalProjectPath + "] resolution task executed in " + (endTS - startTS) + " ms."); handleSyncResult(externalProjectPath, importSpec, resolveProjectTask, eventDispatcher, finishSyncEventSupplier); } }