コード例 #1
0
  @Override
  public Measure calculate(FormulaData data, FormulaContext context) {

    Double criticalCount = MeasureUtils.getValue(data.getMeasure(FortifyMetrics.CFPO), null);
    Double highCount = MeasureUtils.getValue(data.getMeasure(FortifyMetrics.HFPO), null);
    Double mediumCount = MeasureUtils.getValue(data.getMeasure(FortifyMetrics.MFPO), null);
    Double lowCount = MeasureUtils.getValue(data.getMeasure(FortifyMetrics.LFPO), null);

    if (criticalCount != null && highCount != null && mediumCount != null && lowCount != null) {
      Double securityRatingLevel;
      if (criticalCount > 0) {
        securityRatingLevel = SecurityRatingFormula.BLOCKER_SECURITY_RATING_LEVEL;
      } else if (highCount > 0) {
        securityRatingLevel = SecurityRatingFormula.CRITICAL_SECURITY_RATING_LEVEL;
      } else if (mediumCount > 0) {
        securityRatingLevel = SecurityRatingFormula.MAJOR_SECURITY_RATING_LEVEL;
      } else if (lowCount > 0) {
        securityRatingLevel = SecurityRatingFormula.MINOR_SECURITY_RATING_LEVEL;
      } else {
        securityRatingLevel = SecurityRatingFormula.DEFAULT_SECURITY_RATING_LEVEL;
      }

      return new Measure(context.getTargetMetric(), securityRatingLevel);
    }
    return null;
  }
コード例 #2
0
  /**
   * @param context the context
   * @return the valid lines of the component, i.e. the real number of lines
   */
  protected double getValidLines(DecoratorContext context) {
    double duplicatedLines =
        MeasureUtils.getValue(context.getMeasure(CoreMetrics.DUPLICATED_LINES), 0.0);
    double totalLines = MeasureUtils.getValue(context.getMeasure(CoreMetrics.NCLOC), 0.0);
    double validLines = totalLines - duplicatedLines;

    return validLines > 0 ? validLines : 1.0;
  }
コード例 #3
0
 @Override
 protected Double countCoveredElements(DecoratorContext context) {
   double uncoveredLines =
       MeasureUtils.getValue(context.getMeasure(JaCoCoItMetrics.IT_UNCOVERED_LINES), 0.0);
   double lines =
       MeasureUtils.getValue(context.getMeasure(JaCoCoItMetrics.IT_LINES_TO_COVER), 0.0);
   return lines - uncoveredLines;
 }
コード例 #4
0
 /** {@inheritDoc} */
 public void decorate(Resource resource, DecoratorContext context) {
   if (!shouldDecorateResource(resource, context)) {
     return;
   }
   Double functions = MeasureUtils.getValue(context.getMeasure(CoreMetrics.FUNCTIONS), null);
   Double complexity = MeasureUtils.getValue(context.getMeasure(CoreMetrics.COMPLEXITY), null);
   if (complexity != null && functions != null && functions > 0.0) {
     context.saveMeasure(CoreMetrics.FUNCTION_COMPLEXITY, complexity / functions);
   }
 }
コード例 #5
0
  private void computeViolationsPerRules(DecoratorContext context) {
    Map<RulePriority, Multiset<Rule>> rulesPerSeverity = Maps.newHashMap();
    for (Violation violation : context.getViolations()) {
      Multiset<Rule> rulesBag = initRules(rulesPerSeverity, violation.getSeverity());
      rulesBag.add(violation.getRule());
    }

    for (RulePriority severity : RulePriority.values()) {
      Metric metric = SeverityUtils.severityToViolationMetric(severity);

      Collection<Measure> children = context.getChildrenMeasures(MeasuresFilters.rules(metric));
      for (Measure child : children) {
        RuleMeasure childRuleMeasure = (RuleMeasure) child;
        Rule rule = childRuleMeasure.getRule();
        if (rule != null && MeasureUtils.hasValue(childRuleMeasure)) {
          Multiset<Rule> rulesBag = initRules(rulesPerSeverity, severity);
          rulesBag.add(rule, childRuleMeasure.getIntValue());
        }
      }

      Multiset<Rule> rulesBag = rulesPerSeverity.get(severity);
      if (rulesBag != null) {
        for (Multiset.Entry<Rule> entry : rulesBag.entrySet()) {
          RuleMeasure measure =
              RuleMeasure.createForRule(metric, entry.getElement(), (double) entry.getCount());
          measure.setSeverity(severity);
          context.saveMeasure(measure);
        }
      }
    }
  }
コード例 #6
0
 private void computeTotalViolations(DecoratorContext context) {
   if (context.getMeasure(CoreMetrics.VIOLATIONS) == null) {
     Collection<Measure> childrenViolations = context.getChildrenMeasures(CoreMetrics.VIOLATIONS);
     Double sum = MeasureUtils.sum(true, childrenViolations);
     context.saveMeasure(CoreMetrics.VIOLATIONS, sum + context.getViolations().size());
   }
 }
コード例 #7
0
  /** {@inheritDoc} */
  public void decorate(Resource resource, DecoratorContext context) {
    if (!shouldDecorateResource(context)) {
      return;
    }
    Measure dividend = context.getMeasure(getDividendMetric());
    Measure divisor = context.getMeasure(getDivisorMetric());

    if (MeasureUtils.hasValue(dividend)
        && MeasureUtils.hasValue(divisor)
        && divisor.getValue() > 0.0) {
      context.saveMeasure(
          new Measure(
              getQuotientMetric(),
              compute(dividend, divisor, getQuotientMetric().isPercentageType())));
    }
  }
コード例 #8
0
 private int saveValue(DecoratorContext context, Metric metric, String ruleKey) {
   int result;
   result = MeasureUtils.sum(true, context.getChildrenMeasures(metric)).intValue();
   for (Violation violation : context.getViolations()) {
     if (violation.getRule().getKey().equals(ruleKey)) {
       result++;
     }
   }
   context.saveMeasure(metric, (double) result);
   return result;
 }
コード例 #9
0
  @Override
  public void checkResource(
      Resource resource,
      DecoratorContext context,
      RuleKey rule,
      ResourcePerspectives perspectives) {
    double lineCoverage =
        MeasureUtils.getValue(context.getMeasure(CoreMetrics.BRANCH_COVERAGE), 0.0);
    if (context.getMeasure(CoreMetrics.BRANCH_COVERAGE) != null
        && lineCoverage < minimumBranchCoverageRatio) {
      double uncoveredConditions =
          MeasureUtils.getValue(context.getMeasure(CoreMetrics.UNCOVERED_CONDITIONS), 0.0);
      double conditionsToCover =
          MeasureUtils.getValue(context.getMeasure(CoreMetrics.CONDITIONS_TO_COVER), 0.0);
      double conditionsToCoverToReachThreshold =
          Math.ceil(
              (conditionsToCover * minimumBranchCoverageRatio / 100)
                  - (conditionsToCover - uncoveredConditions));

      createIssue(resource, rule, conditionsToCoverToReachThreshold, perspectives);
    }
  }
コード例 #10
0
  private void computeViolationsPerSeverities(DecoratorContext context) {
    Multiset<RulePriority> severitiesBag = HashMultiset.create();
    for (Violation violation : context.getViolations()) {
      severitiesBag.add(violation.getSeverity());
    }

    for (RulePriority severity : RulePriority.values()) {
      Metric metric = SeverityUtils.severityToViolationMetric(severity);
      if (context.getMeasure(metric) == null) {
        Collection<Measure> children = context.getChildrenMeasures(MeasuresFilters.metric(metric));
        int sum = MeasureUtils.sum(true, children).intValue() + severitiesBag.count(severity);
        context.saveMeasure(metric, (double) sum);
      }
    }
  }
コード例 #11
0
 private boolean shouldDecorateResource(Resource resource, DecoratorContext context) {
   return !MeasureUtils.hasValue(context.getMeasure(CoreMetrics.FUNCTION_COMPLEXITY));
 }
コード例 #12
0
 @Override
 protected Double countElements(DecoratorContext context) {
   return MeasureUtils.getValue(context.getMeasure(JaCoCoItMetrics.IT_LINES_TO_COVER), 0.0);
 }
コード例 #13
0
 private int sumChildren(DecoratorContext context, Metric metric) {
   return MeasureUtils.sum(true, context.getChildrenMeasures(metric)).intValue();
 }