public static void linkExternalProject(final @NotNull ProjectSystemId externalSystemId,
                                         final @NotNull ExternalProjectSettings projectSettings,
                                         final @NotNull Project project,
                                         final @Nullable Consumer<? super Boolean> importResultCallback,
                                         boolean isPreviewMode,
                                         final @NotNull ProgressExecutionMode progressExecutionMode) {
    var systemSettings = ExternalSystemApiUtil.getSettings(project, externalSystemId);
    var existingSettings = systemSettings.getLinkedProjectSettings(projectSettings.getExternalProjectPath());
    if (existingSettings != null) {
      return;
    }

    //noinspection unchecked
    systemSettings.linkProject(projectSettings);
    var callback = new ExternalProjectRefreshCallback() {
      @Override
      public void onSuccess(final @Nullable DataNode<ProjectData> externalProject) {
        if (externalProject == null) {
          if (importResultCallback != null) {
            importResultCallback.consume(false);
          }
          return;
        }
        ProjectDataManager.getInstance().importData(externalProject, project);
        if (importResultCallback != null) {
          importResultCallback.consume(true);
        }
      }

      @Override
      public void onFailure(@NotNull String errorMessage, @Nullable String errorDetails) {
        if (importResultCallback != null) {
          importResultCallback.consume(false);
        }
      }
    };

    var importSpecBuilder = new ImportSpecBuilder(project, externalSystemId).callback(callback).use(progressExecutionMode);
    if (isPreviewMode) importSpecBuilder.usePreviewMode();
    refreshProject(projectSettings.getExternalProjectPath(), importSpecBuilder);
  }
public static void linkExternalProject(final @NotNull ProjectSystemId externalSystemId,
                                         final @NotNull ExternalProjectSettings projectSettings,
                                         final @NotNull Project project,
                                         final @Nullable Consumer<? super Boolean> importResultCallback,
                                         boolean isPreviewMode,
                                         final @NotNull ProgressExecutionMode progressExecutionMode)