Пример #1
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 = getBucket(resource);
    if (bucket == null) {
      LOG.warn("Resource is not indexed. Ignoring violation {}", violation);
      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());
    moduleIssues.initAndAddViolation(violation);
  }
Пример #2
0
 public void moveRight() {
   if (lives > 0) {
     bucket = bucket.moveRight();
     if (bucket.getLocation().getX() > WIDTH + Bucket.WIDTH / 2)
       bucket = bucket.moveTo(-Bucket.WIDTH / 2, (int) bucket.getLocation().getY());
   }
 }
Пример #3
0
 @Override
 public void setSource(Resource reference, String source) {
   Bucket bucket = checkIndexed(reference);
   if (bucket != null && !bucket.isExcluded()) {
     persistence.setSource(reference, source);
   }
 }
Пример #4
0
  /** {@inheritDoc} */
  @Override
  public List<Violation> getViolations(ViolationQuery violationQuery) {
    Resource resource = violationQuery.getResource();
    if (resource == null) {
      throw new IllegalArgumentException(
          "A resource must be set on the ViolationQuery in order to search for violations.");
    }

    if (!Scopes.isHigherThanOrEquals(resource, Scopes.FILE)) {
      return Collections.emptyList();
    }

    Bucket bucket = buckets.get(resource);
    if (bucket == null) {
      return Collections.emptyList();
    }

    List<Violation> violations = deprecatedViolations.get(bucket.getResource().getEffectiveKey());
    if (violationQuery.getSwitchMode() == ViolationQuery.SwitchMode.BOTH) {
      return violations;
    }

    List<Violation> filteredViolations = Lists.newArrayList();
    for (Violation violation : violations) {
      if (isFiltered(violation, violationQuery.getSwitchMode())) {
        filteredViolations.add(violation);
      }
    }
    return filteredViolations;
  }
Пример #5
0
 @Override
 public Resource getParent(Resource resource) {
   Bucket bucket = getBucket(resource);
   if (bucket != null && bucket.getParent() != null) {
     return bucket.getParent().getResource();
   }
   return null;
 }
Пример #6
0
 @Override
 public <R extends Resource> R getResource(R reference) {
   Bucket bucket = buckets.get(reference);
   if (bucket != null) {
     return (R) bucket.getResource();
   }
   return null;
 }
Пример #7
0
 @Override
 public <M> M getMeasures(Resource resource, MeasuresFilter<M> filter) {
   Bucket bucket = buckets.get(resource);
   if (bucket != null) {
     // TODO the data measures which are not kept in memory are not reloaded yet. Use getMeasure().
     return bucket.getMeasures(filter);
   }
   return null;
 }
Пример #8
0
 @Override
 @CheckForNull
 public <R extends Resource> R getResource(@Nullable R reference) {
   Bucket bucket = getBucket(reference);
   if (bucket != null) {
     return (R) bucket.getResource();
   }
   return null;
 }
Пример #9
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;
 }
Пример #10
0
 @Override
 public List<Resource> getChildren(Resource resource) {
   List<Resource> children = Lists.newLinkedList();
   Bucket bucket = getBucket(resource);
   if (bucket != null) {
     for (Bucket childBucket : bucket.getChildren()) {
       children.add(childBucket.getResource());
     }
   }
   return children;
 }
Пример #11
0
 @Override
 public Measure getMeasure(Resource resource, Metric metric) {
   Bucket bucket = buckets.get(resource);
   if (bucket != null) {
     Measure measure = bucket.getMeasures(MeasuresFilters.metric(metric));
     if (measure != null) {
       return persistence.reloadMeasure(measure);
     }
   }
   return null;
 }
Пример #12
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;
 }
Пример #13
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;
  }
Пример #14
0
 private boolean checkExclusion(Resource resource, Bucket parent) {
   boolean excluded =
       (parent != null && parent.isExcluded())
           || (resourceFilters != null && resourceFilters.isExcluded(resource));
   resource.setExcluded(excluded);
   return excluded;
 }
Пример #15
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;
  }
Пример #16
0
  public void draw(Graphics g) {
    g.setColor(Color.BLACK);
    g.drawString("Points: " + points, 10, 20);
    g.drawString("Lives: " + lives, 10, 30);
    if (lives <= 0) {
      g.setColor(Color.RED);
      g.drawString("You Lose", WIDTH / 2 - 20, HEIGHT / 2);
    }
    for (int i = 0; i < balls.size(); i++) balls.get(i).draw(g);

    bucket.draw(g);
  }
Пример #17
0
  @Test
  public void countGroupByRange()
      throws IOException, SqlParseException, SQLFeatureNotSupportedException {
    Aggregations result =
        query(
            String.format(
                "SELECT COUNT(age) FROM %s/account GROUP BY range(age, 20,25,30,35,40) ",
                TEST_INDEX));
    org.elasticsearch.search.aggregations.bucket.range.Range ageRanges =
        result.get("range(age,20,25,30,35,40)");
    assertThat(ageRanges.getBuckets().size(), equalTo(4));

    long[] expectedResults = new long[] {225L, 226L, 259L, 245L};
    int index = 0;
    for (Bucket bucket : ageRanges.getBuckets()) {
      assertThat(
          ((ValueCount) bucket.getAggregations().get("COUNT(age)")).getValue(),
          equalTo(expectedResults[index]));
      index++;
    }
  }
Пример #18
0
 public void testBallCatch() {
   for (int i = 0; i < balls.size(); i++) {
     if (bucket.contains(balls.get(i))) {
       if (balls.get(i).isGood()) points++;
       else lives--;
       balls.remove(i);
       i--;
     } else if (balls.get(i).getLocation().getY() >= HEIGHT + Ball.RADIUS) {
       if (balls.get(i).isGood()) lives--;
       balls.remove(i);
       i--;
     }
   }
 }
Пример #19
0
  private Bucket doIndex(Resource resource, Resource parentReference) {
    Bucket bucket = buckets.get(resource);
    if (bucket != null) {
      return bucket;
    }

    checkLock(resource);

    Resource parent = null;
    if (!ResourceUtils.isLibrary(resource)) {
      // a library has no parent
      parent = (Resource) ObjectUtils.defaultIfNull(parentReference, currentProject);
    }

    Bucket parentBucket = getBucket(parent, true);
    if (parentBucket == null && parent != null) {
      LOG.warn("Resource ignored, parent is not indexed: " + resource);
      return null;
    }

    resource.setEffectiveKey(createUID(currentProject, resource));
    bucket = new Bucket(resource).setParent(parentBucket);
    buckets.put(resource, bucket);

    boolean excluded = checkExclusion(resource, parentBucket);
    if (!excluded) {
      Snapshot snapshot =
          persistence.saveResource(
              currentProject, resource, (parentBucket != null ? parentBucket.getResource() : null));
      if (ResourceUtils.isPersistable(resource)
          && !Qualifiers.LIBRARY.equals(resource.getQualifier())) {
        graph.addComponent(resource, snapshot);
      }
    }

    return bucket;
  }
Пример #20
0
  private Bucket doIndex(Resource resource, @Nullable Resource parentReference) {
    Bucket bucket = getBucket(resource);
    if (bucket != null) {
      return bucket;
    }

    if (StringUtils.isBlank(resource.getKey())) {
      LOG.warn("Unable to index a resource without key " + resource);
      return null;
    }

    Resource parent = null;
    if (!ResourceUtils.isLibrary(resource)) {
      // a library has no parent
      parent = (Resource) ObjectUtils.defaultIfNull(parentReference, currentProject);
    }

    Bucket parentBucket = getBucket(parent);
    if (parentBucket == null && parent != null) {
      LOG.warn("Resource ignored, parent is not indexed: " + resource);
      return null;
    }

    if (ResourceUtils.isProject(resource)
        || /* For technical projects */ ResourceUtils.isRootProject(resource)) {
      resource.setEffectiveKey(resource.getKey());
    } else {
      resource.setEffectiveKey(ComponentKeys.createEffectiveKey(currentProject, resource));
    }
    bucket = new Bucket(resource).setParent(parentBucket);
    addBucket(resource, bucket);

    Resource parentResource = parentBucket != null ? parentBucket.getResource() : null;
    resourceCache.add(resource, parentResource);

    return bucket;
  }
Пример #21
0
 @Override
 public boolean index(Resource resource, Resource parentReference) {
   Bucket bucket = doIndex(resource, parentReference);
   return bucket != null && !bucket.isExcluded();
 }
Пример #22
0
 public static void main(String args[]) {
   Bucket m = new Bucket();
   int[] nums = {100, 4, 200, 1, 3, 2, 198, 197, 199, 201, 202};
   System.out.println(m.longestConsecutive(nums));
 }
Пример #23
0
 @Override
 public boolean isExcluded(Resource reference) {
   Bucket bucket = getBucket(reference, true);
   return bucket != null && bucket.isExcluded();
 }
Пример #24
0
 /** Does nothing if the resource is already registered. */
 @Override
 public Resource addResource(Resource resource) {
   Bucket bucket = doIndex(resource);
   return bucket != null ? bucket.getResource() : null;
 }