Ejemplo n.º 1
0
 public boolean isSupportedType(String type) {
   for (IScmAccessValidator validator : getAllValidators()) {
     if (validator.accept(type)) {
       return true;
     }
   }
   return false;
 }
Ejemplo n.º 2
0
  private IScmAccessValidator getValidator(IScmAccessData data) {
    List<IScmAccessValidator> validators = new ArrayList<IScmAccessValidator>();

    for (IScmAccessValidator validator : getAllValidators()) {
      if (validator.accept(data)) {
        validators.add(validator);
      }
    }

    Collections.sort(
        validators,
        new Comparator<IScmAccessValidator>() {
          public int compare(IScmAccessValidator o1, IScmAccessValidator o2) {
            return o1.getPriority() - o2.getPriority();
          }
        });

    return validators.isEmpty() ? null : validators.get(0);
  }
Ejemplo n.º 3
0
  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);
  }