示例#1
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;
  }
示例#2
0
 public Dependency getEdge(Resource from, Resource to) {
   Map<Resource, Dependency> map = outgoingDependenciesByResource.get(from);
   if (map != null) {
     return map.get(to);
   }
   return null;
 }
示例#3
0
 @Override
 public <R extends Resource> R getResource(R reference) {
   Bucket bucket = buckets.get(reference);
   if (bucket != null) {
     return (R) bucket.getResource();
   }
   return null;
 }
示例#4
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;
 }
示例#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;
 }
示例#6
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;
 }
示例#7
0
 private Bucket getBucket(@Nullable Resource reference) {
   if (reference == null) {
     return null;
   }
   if (StringUtils.isNotBlank(reference.getKey())) {
     return buckets.get(reference);
   }
   String relativePathFromSourceDir = null;
   boolean isTest = false;
   boolean isDir = false;
   if (reference instanceof File) {
     File referenceFile = (File) reference;
     isTest = Qualifiers.UNIT_TEST_FILE.equals(referenceFile.getQualifier());
     relativePathFromSourceDir = referenceFile.relativePathFromSourceDir();
   } else if (reference instanceof Directory) {
     isDir = true;
     Directory referenceDir = (Directory) reference;
     relativePathFromSourceDir = referenceDir.relativePathFromSourceDir();
     if (Directory.ROOT.equals(relativePathFromSourceDir)) {
       relativePathFromSourceDir = "";
     }
   }
   if (relativePathFromSourceDir != null) {
     // Resolve using deprecated key
     List<java.io.File> dirs;
     if (isTest) {
       dirs = getProject().getFileSystem().getTestDirs();
     } else {
       dirs = getProject().getFileSystem().getSourceDirs();
     }
     for (java.io.File src : dirs) {
       java.io.File abs = new java.io.File(src, relativePathFromSourceDir);
       Bucket b =
           getBucket(
               isDir
                   ? Directory.fromIOFile(abs, getProject())
                   : File.fromIOFile(abs, getProject()));
       if (b != null) {
         return b;
       }
     }
   }
   return null;
 }
示例#8
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;
  }