Example #1
0
  /**
   * Accept a visitor for all the validators that are enabled for the given project.
   *
   * @param visitor
   * @param project
   * @param valType the type of validation
   * @param operation
   * @param monitor
   */
  public void accept(
      IValidatorVisitor visitor,
      IProject project,
      ValType valType,
      ValOperation operation,
      IProgressMonitor monitor) {

    if (isDisabled(project)) return;

    for (Validator val : getValidators(project)) {
      if (monitor.isCanceled()) return;
      if (!ValidatorProjectManager.get().shouldValidate(val, project, valType)) continue;
      if (operation.isSuspended(val, project)) continue;
      try {
        visitor.visit(val, project, valType, operation, monitor);
      } catch (Exception e) {
        ValidationPlugin.getPlugin().handleException(e);
      }
    }
  }
Example #2
0
  /**
   * Run all the validators that are applicable to this resource.
   *
   * <p>If this is a manual validation both the version 1 and version 2 validators are run. If it is
   * a build validation, then only the version 2 validators are run, because the old framework
   * handles the running of the old validators.
   *
   * @param project project that is being validated
   * @param resource the resource that is being validated
   * @param kind the kind of resource delta. It will be one of the IResourceDelta constants, like
   *     IResourceDelta.CHANGED for example.
   * @param valType The type of validation request.
   * @param buildKind the kind of build that triggered this validation. See
   *     IncrementalProjectBuilder for values.
   * @param operation the operation that this validation is running under
   * @param monitor the monitor to use to report progress
   */
  public void validate(
      IProject project,
      final IResource resource,
      final int kind,
      ValType valType,
      int buildKind,
      ValOperation operation,
      final IProgressMonitor monitor) {

    MarkerManager.getDefault()
        .deleteMarkers(resource, operation.getStarted(), IResource.DEPTH_ZERO);

    IValidatorVisitor visitor =
        new IValidatorVisitor() {

          public void visit(
              Validator validator,
              IProject project,
              ValType vt,
              ValOperation operation,
              IProgressMonitor monitor) {

            Validator.V1 v1 = validator.asV1Validator();
            if (vt == ValType.Build && v1 != null) return;

            SubMonitor subMonitor = SubMonitor.convert(monitor);
            String task =
                NLS.bind(ValMessages.LogValStart, validator.getName(), resource.getName());
            subMonitor.beginTask(task, 1);

            if (project.isOpen())
              validate(validator, operation, resource, kind, subMonitor.newChild(1), null);
          }
        };
    SubMonitor sm = SubMonitor.convert(monitor, getValidators(project).length);
    accept(visitor, project, resource, valType, operation, sm);
  }
Example #3
0
  /**
   * Accept a visitor for all the validators that are enabled for the given project, resource, and
   * validation mode.
   *
   * @param valType the type of validation request
   */
  public void accept(
      IValidatorVisitor visitor,
      IProject project,
      IResource resource,
      ValType valType,
      ValOperation operation,
      IProgressMonitor monitor) {

    if (isDisabled(project)) return;

    Map<String, IValidatorGroupListener[]> groupListeners =
        new HashMap<String, IValidatorGroupListener[]>();

    ValProperty vp = getValProperty(resource, valType, _configNumber.get());
    if (vp != null) {
      BitSet bs = vp.getConfigSet();
      for (Validator val : getValidators(project)) {
        if (!monitor.isCanceled()) {
          if (!bs.get(_idManager.getIndex(val.getId()))) continue;
          if (operation.isSuspended(val, project)) continue;
          Validator.V2 v2 = val.asV2Validator();
          if (v2 != null) {
            notifyGroupListenersStarting(
                resource, operation.getState(), monitor, groupListeners, v2);
          }
          try {
            visitor.visit(val, project, valType, operation, monitor);
          } catch (Exception e) {
            ValidationPlugin.getPlugin().handleException(e);
          }
        }
      }
      notifyGroupFinishing(resource, operation.getState(), monitor, groupListeners);
      return;
    }

    vp = new ValProperty();
    vp.setConfigNumber(_configNumber.get());
    ContentTypeWrapper ctw = new ContentTypeWrapper();
    for (Validator val : getValidators(project)) {
      if (!monitor.isCanceled()) {
        if (!ValidatorProjectManager.get().shouldValidate(val, project, valType)) continue;
        if (Friend.shouldValidate(val, resource, valType, ctw)) {
          vp.getConfigSet().set(_idManager.getIndex(val.getId()));
          // we do the suspend check after figuring out if it needs to be validated, because we save
          // this information for the session.
          if (operation.isSuspended(val, project)) continue;
          Validator.V2 v2 = val.asV2Validator();
          if (v2 != null) {
            notifyGroupListenersStarting(
                resource, operation.getState(), monitor, groupListeners, v2);
          }
          try {
            visitor.visit(val, project, valType, operation, monitor);
          } catch (Exception e) {
            ValidationPlugin.getPlugin().handleException(e);
          }
        }
      }
    }
    notifyGroupFinishing(resource, operation.getState(), monitor, groupListeners);
    putValProperty(vp, resource, valType);
  }
Example #4
0
  /**
   * Validate a single resource with a single validator. This will call the validator whether the
   * validator is enabled or not.
   *
   * <p>Callers of this method should ensure that the shouldValidate was tested before making this
   * call.
   *
   * @param validator the validator
   * @param operation the operation that the validation is running in.
   * @param resource the resource to validate
   * @param kind the kind of resource change. See IResourceDelta.
   * @param monitor
   */
  public void validate(
      Validator validator,
      ValOperation operation,
      IResource resource,
      int kind,
      IProgressMonitor monitor,
      ValidationEvent event) {
    if (operation.isValidated(validator.getId(), resource)) return;
    long time = 0;
    long cpuTime = -1;
    String msg1 = NLS.bind(ValMessages.LogValStart, validator.getName(), resource.getName());
    monitor.subTask(msg1);
    IPerformanceMonitor pm = ValidationFramework.getDefault().getPerformanceMonitor();
    if (pm.isCollecting()) {
      time = System.currentTimeMillis();
      cpuTime = Misc.getCPUTime();
    }

    if (Tracing.matchesExtraDetail(validator.getId())) {
      Tracing.log("ValManager-03: validating ", resource); // $NON-NLS-1$
    }

    if (resource.exists()) {
      ValidationResult vr = validator.validate(resource, kind, operation, monitor, event);

      if (pm.isCollecting()) {
        if (cpuTime != -1) {
          cpuTime = Misc.getCPUTime() - cpuTime;
        }
        int num = 0;
        if (vr != null) num = vr.getNumberOfValidatedResources();
        PerformanceCounters pc =
            new PerformanceCounters(
                validator.getId(),
                validator.getName(),
                resource.getName(),
                num,
                System.currentTimeMillis() - time,
                cpuTime);
        pm.add(pc);
      }
      if (ValidationPlugin.getPlugin().isDebugging() && !pm.isCollecting()) {
        String msg =
            time != 0
                ? NLS.bind(
                    ValMessages.LogValEndTime,
                    new Object[] {
                      validator.getName(),
                      validator.getId(),
                      resource,
                      Misc.getTimeMS(System.currentTimeMillis() - time)
                    })
                : NLS.bind(ValMessages.LogValEnd, validator.getName(), resource);
        Tracing.log("ValManager-01: " + msg); // $NON-NLS-1$
      }
      if (vr != null) {
        operation.mergeResults(vr);
        if (vr.getSuspendValidation() != null)
          operation.suspendValidation(vr.getSuspendValidation(), validator);
      }
    }
  }