public IS2ProjectValidationStatus validate(IUrlLocation location, IProgressMonitor monitor) {
    if (!accept(location)) {
      throw new IllegalArgumentException(
          "ScmAccessValidator.validate() was called for a location that is not an SCM location.");
    }

    IScmLocation scmLocation = (IScmLocation) location;
    String scmUrl = scmLocation.getUrl();
    IAuthData authData = AuthFacade.getAuthService().select(scmUrl);
    IStatus status = validateAuthData(authData);
    if (status.isOK()) {
      IScmAccessData scmData = new ScmAccessData(scmUrl, scmLocation.getBranch(), "HEAD", authData);

      IScmAccessValidator validator = getValidator(scmData);
      log.debug("Validating SCM access to {} with {}", scmData.getRepositoryUrl(), validator);

      if (validator == null) {
        status =
            new Status(
                IStatus.ERROR,
                S2ProjectValidationPlugin.PLUGIN_ID,
                "SCM provider is not available for " + scmData.getRepositoryUrl());
        monitor.worked(1);
      } else {
        SubMonitor subprogress = SubMonitor.convert(monitor, 1);
        status = validator.validate(scmData, subprogress);
        subprogress.done();
      }
    } else {
      monitor.worked(1);
    }

    if (status != null && status.getException() != null) {
      log.debug(
          "Validated SCM access to " + scmUrl + " with result " + status, status.getException());
    } else {
      log.debug("Validated SCM access to {} with result {}", scmUrl, status);
    }

    return wrapStatus(status, scmLocation);
  }
  /** Returns OK, WARN or ERROR. */
  public IS2ProjectValidationStatus validate(
      IS2Project s2Project, String securityRealmIdFilter, IProgressMonitor monitor) {
    log.debug("Validating SCM access for project {}", s2Project.getName());

    List<IS2Module> modules = s2Project.getModules();

    SubMonitor progress =
        SubMonitor.convert(monitor, "Validating source repository access", modules.size());

    ArrayList<IStatus> results = new ArrayList<IStatus>();

    for (final IS2Module module : modules) {
      if (progress.isCanceled()) {
        throw new OperationCanceledException();
      }

      progress.subTask(module.getName());

      IResourceLocation scmLocation = module.getScmLocation();
      if (scmLocation == null) {
        results.add(
            new Status(
                IStatus.ERROR,
                S2ProjectValidationPlugin.PLUGIN_ID,
                "SCM location is not specified"));
        monitor.worked(1);
        continue;
      }

      String scmUrl = scmLocation.getUrl();
      String realmIdForUrl = null;
      IAuthRealm realmForUrl = AuthFacade.getAuthRegistry().getRealmForURI(scmUrl);
      if (realmForUrl != null) {
        realmIdForUrl = realmForUrl.getId();
      }
      if (securityRealmIdFilter != null
          && !securityRealmIdFilter.equals(realmIdForUrl)
          && !urlsEquals(securityRealmIdFilter, scmUrl)) {
        // This location does not match the specified securityRealmId
        monitor.worked(1);
        continue;
      }
      log.debug("Validating SCM access for module {} at {}", module.getName(), scmUrl);

      IStatus status = validate(scmLocation, progress);
      results.add(status);
    }

    progress.subTask("");
    progress.done();

    if (results.isEmpty()) {
      return null;
    }

    return new S2ProjectValidationMultiStatus(
        this,
        -1,
        results.toArray(new IStatus[results.size()]),
        null /* message */,
        null /* exception */);
  }