Example #1
0
  boolean shouldComputeVariation(String variationMode, Resource resource) {
    if (Scopes.FILE.equals(resource.getScope())
        && !Qualifiers.UNIT_TEST_FILE.equals(resource.getQualifier())) {
      return enabledFileVariation
          && StringUtils.equals(variationMode, CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS);
    }

    // measures on files are currently purged, so past measures are not available on files
    return StringUtils.equals(Scopes.PROJECT, resource.getScope())
        || StringUtils.equals(Scopes.DIRECTORY, resource.getScope());
  }
Example #2
0
 public void decorate(Resource resource, DecoratorContext context) {
   if (Scopes.isFile(resource) && !Qualifiers.UNIT_TEST_FILE.equals(resource.getQualifier())) {
     int classes = 0;
     for (DecoratorContext child : context.getChildren()) {
       if (Scopes.isProgramUnit(child.getResource())) {
         classes++;
       }
     }
     context.saveMeasure(new Measure(CoreMetrics.CLASSES, (double) classes));
   }
 }
Example #3
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<String> dirs;
     ProjectDefinition projectDef = projectTree.getProjectDefinition(getProject());
     if (isTest) {
       dirs = projectDef.getTestDirs();
     } else {
       dirs = projectDef.getSourceDirs();
     }
     for (String src : dirs) {
       java.io.File dirOrFile = pathResolver.relativeFile(projectDef.getBaseDir(), src);
       java.io.File abs = new java.io.File(dirOrFile, relativePathFromSourceDir);
       Bucket b =
           getBucket(
               isDir
                   ? Directory.fromIOFile(abs, getProject())
                   : File.fromIOFile(abs, getProject()));
       if (b != null) {
         return b;
       }
     }
   }
   return null;
 }