public <T extends TaskRepository> void setRepositories(List<T> repositories) {

    Set<TaskRepository> set = new HashSet<TaskRepository>(myRepositories);
    set.removeAll(repositories);
    myBadRepositories.removeAll(set); // remove all changed reps
    myIssueCache.clear();

    myRepositories.clear();
    myRepositories.addAll(repositories);

    reps:
    for (T repository : repositories) {
      if (repository.isShared() && repository.getUrl() != null) {
        List<TaskProjectConfiguration.SharedServer> servers = getProjectConfiguration().servers;
        TaskRepositoryType type = repository.getRepositoryType();
        for (TaskProjectConfiguration.SharedServer server : servers) {
          if (repository.getUrl().equals(server.url) && type.getName().equals(server.type)) {
            continue reps;
          }
        }
        TaskProjectConfiguration.SharedServer server = new TaskProjectConfiguration.SharedServer();
        server.type = type.getName();
        server.url = repository.getUrl();
        servers.add(server);
      }
    }
  }
  public static Set<WorkingCopyFormat> getUpgradeFormats(
      @NotNull WCInfo info, @NotNull List<WorkingCopyFormat> supportedFormats) {
    Set<WorkingCopyFormat> canUpgradeTo = EnumSet.noneOf(WorkingCopyFormat.class);

    for (WorkingCopyFormat format : supportedFormats) {
      if (format.isOrGreater(info.getFormat())) {
        canUpgradeTo.add(format);
      }
    }
    canUpgradeTo.add(info.getFormat());

    return canUpgradeTo;
  }
 @Nullable
 private List<Task> getIssuesFromRepositories(
     @Nullable String request,
     int max,
     long since,
     boolean forceRequest,
     @NotNull final ProgressIndicator cancelled) {
   List<Task> issues = null;
   for (final TaskRepository repository : getAllRepositories()) {
     if (!repository.isConfigured() || (!forceRequest && myBadRepositories.contains(repository))) {
       continue;
     }
     try {
       Task[] tasks = repository.getIssues(request, max, since, cancelled);
       myBadRepositories.remove(repository);
       if (issues == null) issues = new ArrayList<Task>(tasks.length);
       if (!repository.isSupported(TaskRepository.NATIVE_SEARCH) && request != null) {
         List<Task> filteredTasks =
             TaskSearchSupport.filterTasks(request, ContainerUtil.list(tasks));
         ContainerUtil.addAll(issues, filteredTasks);
       } else {
         ContainerUtil.addAll(issues, tasks);
       }
     } catch (ProcessCanceledException ignored) {
       // OK
     } catch (Exception e) {
       String reason = "";
       // Fix to IDEA-111810
       if (e.getClass() == Exception.class) {
         // probably contains some message meaningful to end-user
         reason = e.getMessage();
       }
       //noinspection InstanceofCatchParameter
       if (e instanceof SocketTimeoutException) {
         LOG.warn("Socket timeout from " + repository);
       } else {
         LOG.warn("Cannot connect to " + repository, e);
       }
       myBadRepositories.add(repository);
       if (forceRequest) {
         notifyAboutConnectionFailure(repository, reason);
       }
     }
   }
   return issues;
 }
  @Override
  public boolean testConnection(final TaskRepository repository) {

    TestConnectionTask task =
        new TestConnectionTask("Test connection") {
          public void run(@NotNull ProgressIndicator indicator) {
            indicator.setText("Connecting to " + repository.getUrl() + "...");
            indicator.setFraction(0);
            indicator.setIndeterminate(true);
            try {
              myConnection = repository.createCancellableConnection();
              if (myConnection != null) {
                Future<Exception> future =
                    ApplicationManager.getApplication().executeOnPooledThread(myConnection);
                while (true) {
                  try {
                    myException = future.get(100, TimeUnit.MILLISECONDS);
                    return;
                  } catch (TimeoutException ignore) {
                    try {
                      indicator.checkCanceled();
                    } catch (ProcessCanceledException e) {
                      myException = e;
                      myConnection.cancel();
                      return;
                    }
                  } catch (Exception e) {
                    myException = e;
                    return;
                  }
                }
              } else {
                try {
                  repository.testConnection();
                } catch (Exception e) {
                  LOG.info(e);
                  myException = e;
                }
              }
            } catch (Exception e) {
              myException = e;
            }
          }
        };
    ProgressManager.getInstance().run(task);
    Exception e = task.myException;
    if (e == null) {
      myBadRepositories.remove(repository);
      Messages.showMessageDialog(
          myProject, "Connection is successful", "Connection", Messages.getInformationIcon());
    } else if (!(e instanceof ProcessCanceledException)) {
      String message = e.getMessage();
      if (e instanceof UnknownHostException) {
        message = "Unknown host: " + message;
      }
      if (message == null) {
        LOG.error(e);
        message = "Unknown error";
      }
      Messages.showErrorDialog(myProject, StringUtil.capitalize(message), "Error");
    }
    return e == null;
  }