@Override
  public void decorate(Resource resource, DecoratorContext context) {
    if (ResourceUtils.isPersistable(resource) && !ResourceUtils.isUnitTestFile(resource)) {
      Long developmentCost = getDevelopmentCost(context);
      context.saveMeasure(
          new Measure(CoreMetrics.DEVELOPMENT_COST, Long.toString(developmentCost)));

      long debt = getMeasureValue(context, CoreMetrics.TECHNICAL_DEBT);
      double density = computeDensity(debt, developmentCost);
      context.saveMeasure(CoreMetrics.SQALE_DEBT_RATIO, 100.0 * density);

      SqaleRatingGrid ratingGrid = new SqaleRatingGrid(sqaleRatingSettings.getRatingGrid());
      context.saveMeasure(createRatingMeasure(ratingGrid.getRatingForDensity(density)));
    }
  }
 @Override
 public void decorate(Resource resource, DecoratorContext context) {
   if (!ResourceUtils.isPersistable(resource)) {
     return;
   }
   File path = null;
   if (ResourceUtils.isProject(resource)) {
     path = fs.baseDir();
   } else if (resource.getPath() != null) {
     path = new File(fs.baseDir(), resource.getPath());
   }
   ResourceNode resourceNode = new ResourceNode(resource, path, fs.sourceCharset());
   RESOURCE_BY_KEY.put(resource.getEffectiveKey(), resourceNode);
   for (DecoratorContext childContext : context.getChildren()) {
     Resource child = childContext.getResource();
     ResourceNode childNode = RESOURCE_BY_KEY.get(child.getEffectiveKey());
     if (childNode != null) {
       resourceNode.addChild(childNode);
     }
   }
 }
Exemple #3
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;
  }