Beispiel #1
0
  boolean registerDependency(Dependency dependency) {
    Bucket fromBucket = doIndex(dependency.getFrom());
    Bucket toBucket = doIndex(dependency.getTo());

    if (fromBucket != null
        && !fromBucket.isExcluded()
        && toBucket != null
        && !toBucket.isExcluded()) {
      dependencies.add(dependency);
      registerOutgoingDependency(dependency);
      registerIncomingDependency(dependency);
      return true;
    }
    return false;
  }
Beispiel #2
0
 private boolean checkExclusion(Resource resource, Bucket parent) {
   boolean excluded =
       (parent != null && parent.isExcluded())
           || (resourceFilters != null && resourceFilters.isExcluded(resource));
   resource.setExcluded(excluded);
   return excluded;
 }
Beispiel #3
0
 @Override
 public void setSource(Resource reference, String source) {
   Bucket bucket = checkIndexed(reference);
   if (bucket != null && !bucket.isExcluded()) {
     persistence.setSource(reference, source);
   }
 }
Beispiel #4
0
  @Override
  public void addViolation(Violation violation, boolean force) {
    Resource resource = violation.getResource();
    if (resource == null) {
      violation.setResource(currentProject);
    } else if (!Scopes.isHigherThanOrEquals(resource, Scopes.FILE)) {
      throw new IllegalArgumentException(
          "Violations are only supported on files, directories and project");
    }

    Rule rule = violation.getRule();
    if (rule == null) {
      LOG.warn("Rule is null. Ignoring violation {}", violation);
      return;
    }

    Bucket bucket = checkIndexed(resource);
    if (bucket == null || bucket.isExcluded()) {
      return;
    }

    // keep a limitation (bug?) of deprecated violations api : severity is always
    // set by sonar. The severity set by plugins is overridden.
    // This is not the case with issue api.
    violation.setSeverity(null);

    violation.setResource(bucket.getResource());
    scanIssues.initAndAddViolation(violation);
  }
Beispiel #5
0
 private Bucket getBucket(Resource resource, boolean acceptExcluded) {
   Bucket bucket = null;
   if (resource != null) {
     bucket = buckets.get(resource);
     if (!acceptExcluded && bucket != null && bucket.isExcluded()) {
       bucket = null;
     }
   }
   return bucket;
 }
Beispiel #6
0
 public List<Resource> getChildren(Resource resource, boolean acceptExcluded) {
   List<Resource> children = Lists.newLinkedList();
   Bucket bucket = getBucket(resource, acceptExcluded);
   if (bucket != null) {
     for (Bucket childBucket : bucket.getChildren()) {
       if (acceptExcluded || !childBucket.isExcluded()) {
         children.add(childBucket.getResource());
       }
     }
   }
   return children;
 }
Beispiel #7
0
  /** the measure is updated if it's already registered. */
  @Override
  public Measure addMeasure(Resource resource, Measure measure) {
    Bucket bucket = checkIndexed(resource);
    if (bucket != null && !bucket.isExcluded()) {
      Metric metric = metricFinder.findByKey(measure.getMetricKey());
      if (metric == null) {
        throw new SonarException("Unknown metric: " + measure.getMetricKey());
      }
      measure.setMetric(metric);
      bucket.addMeasure(measure);

      if (measure.getPersistenceMode().useDatabase()) {
        persistence.saveMeasure(resource, measure);
      }
    }
    return measure;
  }
Beispiel #8
0
 @Override
 public boolean isExcluded(Resource reference) {
   Bucket bucket = getBucket(reference, true);
   return bucket != null && bucket.isExcluded();
 }
Beispiel #9
0
 @Override
 public boolean index(Resource resource, Resource parentReference) {
   Bucket bucket = doIndex(resource, parentReference);
   return bucket != null && !bucket.isExcluded();
 }