public static void refreshProject(final @NotNull String externalProjectPath, final @NotNull ImportSpec importSpec) {
    var project = importSpec.getProject();
    var externalSystemId = importSpec.getExternalSystemId();
    var isPreviewMode = importSpec.isPreviewMode();

    TransactionGuard.getInstance().assertWriteSafeContext(ModalityState.defaultModalityState());
    ApplicationManager.getApplication().invokeAndWait(FileDocumentManager.getInstance()::saveAllDocuments);

    if (!isPreviewMode && !TrustedProjects.isTrusted(project)) {
      if (LOG.isDebugEnabled()) {
        LOG.debug("Skip " + externalSystemId + " load, because project is not trusted", new Throwable());
      }
      return;
    }
    if (LOG.isDebugEnabled()) {
      LOG.debug("Stated " + externalSystemId + " load", new Throwable());
    }

    AbstractExternalSystemLocalSettings<?> localSettings = ExternalSystemApiUtil.getLocalSettings(project, externalSystemId);
    var projectSyncTypeStorage = localSettings.getProjectSyncType();
    var previousSyncType = projectSyncTypeStorage.get(externalProjectPath);
    var syncType = isPreviewMode ? PREVIEW : (previousSyncType == PREVIEW ? IMPORT : RE_IMPORT);
    projectSyncTypeStorage.put(externalProjectPath, syncType);

    var resolveProjectTask = new ExternalSystemResolveProjectTask(project, externalProjectPath, importSpec);

    var taskId = resolveProjectTask.getId();
    var projectName = resolveProjectTask.getProjectName();
    var externalSystemName = externalSystemId.getReadableName();
    var progressExecutionMode = importSpec.getProgressExecutionMode();
    var title = progressExecutionMode == ProgressExecutionMode.MODAL_SYNC
                   ? ExternalSystemBundle.message("progress.import.text", projectName, externalSystemName)
                   : ExternalSystemBundle.message("progress.refresh.text", projectName, externalSystemName);
    if (progressExecutionMode == ProgressExecutionMode.NO_PROGRESS_SYNC ||
        progressExecutionMode == ProgressExecutionMode.NO_PROGRESS_ASYNC) {
      throw new ExternalSystemException("Please, use progress for the project import!");
    }
    ExternalSystemTaskUnderProgress.executeTaskUnderProgress(project, title, progressExecutionMode, new ExternalSystemTaskUnderProgress() {

      @Override
      public @NotNull ExternalSystemTaskId getId() {
        return taskId;
      }

      @Override
      public void execute(@NotNull ProgressIndicator indicator) {
        var activity = ExternalSystemStatUtilKt.importActivityStarted(project, externalSystemId, null);
        try {
          ExternalSystemTelemetryUtil.runWithSpan(externalSystemId, "ExternalSystemSyncProjectTask",
                                                  (ignore) -> executeSync(externalProjectPath, importSpec, resolveProjectTask, indicator));
        }
        finally {
          activity.finished();
        }
      }
    });
  }
public static void refreshProject(final @NotNull String externalProjectPath, final @NotNull ImportSpec importSpec)