private CompletionStage importWorkspaceAsync()

in plugin/src/com/microsoft/alm/plugin/idea/tfvc/core/TfvcIntegrationEnabler.java [237:313]


    private CompletionStage<Boolean> importWorkspaceAsync(
            @Nullable Project project,
            @NotNull ProgressIndicator indicator,
            @NotNull Path workspacePath) {
        Application application = ApplicationManager.getApplication();

        final double totalSteps = 5.0;
        indicator.setIndeterminate(false);
        indicator.setFraction(0.0 / totalSteps);

        ourLogger.info("Checking if workspace under path \"" + workspacePath + "\" is already imported");
        TfsDetailedWorkspaceInfo existingWorkspace = TfvcWorkspaceLocator.getPartialWorkspace(
                project,
                workspacePath,
                false);
        if (existingWorkspace != null) {
            ourLogger.info("Workspace under path \"" + workspacePath + "\" is already imported, exiting");
            return CompletableFuture.completedFuture(true);
        }

        ourLogger.info("No known workspace detected under path \"" + workspacePath + "\"");
        indicator.setFraction(1.0 / totalSteps);

        Path visualStudioClientPath = VisualStudioTfvcClient.getOrDetectPath(PropertyService.getInstance());
        if (visualStudioClientPath == null) {
            if (SystemInfo.isWindows)
                application.invokeLater(() -> showNoVsClientDialog(project));

            return CompletableFuture.completedFuture(false);
        }

        ourLogger.info("Determining workspace information from client \"" + visualStudioClientPath + "\" for path \"" + workspacePath + "\"");
        return VisualStudioTfvcCommands.getPartialWorkspaceAsync(visualStudioClientPath, workspacePath)
                .thenCompose(vsWorkspace -> {
                    if (vsWorkspace == null) {
                        ourLogger.info("No workspace information, exiting");
                        application.invokeLater(() -> showNoWorkspaceDetectedDialog(project));
                        return CompletableFuture.completedFuture(false);
                    }

                    if (indicator.isCanceled()) {
                        ourLogger.info("Operation canceled, exiting");
                        return CompletableFuture.completedFuture(false);
                    }

                    indicator.setFraction(2.0 / totalSteps);

                    URI collectionUri = vsWorkspace.getServerUri();
                    ourLogger.info("Gathering authentication info for URL: " + collectionUri);
                    return getAuthenticationInfoAsync(collectionUri).thenApply(authenticationInfo -> {
                        if (authenticationInfo == null) {
                            ourLogger.info("authenticationInfo == null, exiting");
                            return false;
                        }

                        if (indicator.isCanceled()) {
                            ourLogger.info("Operation canceled, exiting");
                            return false;
                        }

                        indicator.setFraction(3.0 / totalSteps);

                        ourLogger.info("Refreshing workspaces for server: " + collectionUri);
                        CommandUtils.refreshWorkspacesForServer(authenticationInfo, collectionUri.toString());
                        indicator.setFraction(4.0 / totalSteps);

                        ourLogger.info("Checking if workspace was successfully imported from path: \"" + workspacePath + "\"");
                        TfsDetailedWorkspaceInfo workspaceInfo = TfvcWorkspaceLocator.getPartialWorkspace(
                                project,
                                workspacePath,
                                false);
                        indicator.setFraction(5.0 / totalSteps);

                        return workspaceInfo != null;
                    });
                });
    }