public Collection findWorkspaces()

in src/org/jetbrains/tfsIntegration/core/tfs/Workstation.java [258:298]


  public Collection<WorkspaceInfo> findWorkspaces(final @NotNull FilePath localPath,
                                                  boolean considerChildMappings,
                                                  Object projectOrComponent) throws TfsException {
    checkDuplicateMappings();
    final Collection<WorkspaceInfo> resultCached = findWorkspacesCached(localPath, considerChildMappings);
    if (!resultCached.isEmpty()) {
      // given path is mapped according to cached mapping info -> reload and check with server info
      for (WorkspaceInfo workspace : resultCached) {
        if (!workspace.hasMapping(localPath, considerChildMappings, projectOrComponent)) {
          throw new WorkspaceHasNoMappingException(workspace);
        }
      }
      return resultCached;
    }
    else {
      // TODO: exclude servers that are unavailable during current application run
      // not found in cached info, but workspaces may be out of date -> try to search all the workspaces reloaded
      Collection<WorkspaceInfo> result = new ArrayList<>();
      Collection<ServerInfo> serversToSkip = new ArrayList<>();
      for (WorkspaceInfo workspace : getAllWorkspacesForCurrentOwnerAndComputer(true)) {
        if (serversToSkip.contains(workspace.getServer())) {
          // if server is somehow unavailable, don't try every workspace on it
          continue;
        }
        try {
          if (workspace.hasMapping(localPath, considerChildMappings, projectOrComponent)) {
            result.add(workspace);
            if (!considerChildMappings) {
              // optmimization: same local path can't be mapped in different workspaces, so don't process other workspaces
              return result;
            }
          }
        }
        catch (TfsException e) {
          // if some server failed, try next one, otherwise user will get strange error messages
          serversToSkip.add(workspace.getServer());
        }
      }
      return result;
    }
  }