Package org.sonar.api.measures

Examples of org.sonar.api.measures.Measure


  private void savePublicApiDensity(DecoratorContext context) {
    if (context.getMeasure(CoreMetrics.PUBLIC_DOCUMENTED_API_DENSITY) != null) {
      return;
    }

    Measure publicApi = context.getMeasure(CoreMetrics.PUBLIC_API);
    Measure publicUndocApi = context.getMeasure(CoreMetrics.PUBLIC_UNDOCUMENTED_API);

    if (MeasureUtils.hasValue(publicApi) && MeasureUtils.hasValue(publicUndocApi) && publicApi.getValue() > 0) {
      double documentedAPI = publicApi.getValue() - publicUndocApi.getValue();
      Double value = 100.0 * (documentedAPI / publicApi.getValue());
      context.saveMeasure(new Measure(CoreMetrics.PUBLIC_DOCUMENTED_API_DENSITY, value));
    }
  }
View Full Code Here


  private Measure copy(ManualMeasure manualMeasure) {
    Metric metric = metricFinder.findById(manualMeasure.getMetricId());
    if (metric == null) {
      throw new IllegalStateException("Unable to find manual metric with id: " + manualMeasure.getMetricId());
    }
    Measure measure = new Measure(metric);
    measure.setValue(manualMeasure.getValue(), 5);
    measure.setData(manualMeasure.getTextValue());
    measure.setDescription(manualMeasure.getDescription());
    return measure;
  }
View Full Code Here

  @Test
  public void shouldAcceptEverythingWithEmptyFilters() {
    filters = new MeasurementFilters();
    Resource resource = mock(Resource.class);
    Measure measure = mock(Measure.class);
    assertThat(filters.accept(resource, measure)).isTrue();
  }
View Full Code Here

  }

  @Test
  public void shouldAcceptIfAllFiltersAccept() {
    Resource resource = mock(Resource.class);
    Measure measure = mock(Measure.class);
    MeasurementFilter filter1 = mock(MeasurementFilter.class);
    when(filter1.accept(resource, measure)).thenReturn(true);
    MeasurementFilter filter2 = mock(MeasurementFilter.class);
    when(filter2.accept(resource, measure)).thenReturn(true);
View Full Code Here

  }

  @Test
  public void shouldNnotAcceptIfOneFilterDoesntAccept() {
    Resource resource = mock(Resource.class);
    Measure measure = mock(Measure.class);
    MeasurementFilter filter1 = mock(MeasurementFilter.class);
    when(filter1.accept(resource, measure)).thenReturn(false);
    MeasurementFilter filter2 = mock(MeasurementFilter.class);

    filters = new MeasurementFilters(Arrays.array(filter1, filter2));
View Full Code Here

    return true;
  }

  @Override
  public void decorate(Resource resource, DecoratorContext context) {
    Measure nbDuplicatedLines = context.getMeasure(CoreMetrics.DUPLICATED_LINES);
    if (nbDuplicatedLines == null) {
      return;
    }

    Double divisor = getNbLinesFromLocOrNcloc(context);
    if (divisor != null && divisor > 0.0) {
      context.saveMeasure(CoreMetrics.DUPLICATED_LINES_DENSITY, calculate(nbDuplicatedLines.getValue(), divisor));
    }
  }
View Full Code Here

      context.saveMeasure(CoreMetrics.DUPLICATED_LINES_DENSITY, calculate(nbDuplicatedLines.getValue(), divisor));
    }
  }

  private Double getNbLinesFromLocOrNcloc(DecoratorContext context) {
    Measure nbLoc = context.getMeasure(CoreMetrics.LINES);
    if (nbLoc != null) {
      // TODO test this branch
      return nbLoc.getValue();
    }
    Measure nbNcloc = context.getMeasure(CoreMetrics.NCLOC);
    if (nbNcloc != null) {
      Measure nbComments = context.getMeasure(CoreMetrics.COMMENT_LINES);
      Double nbLines = nbNcloc.getValue();
      return nbComments != null ? nbLines + nbComments.getValue() : nbLines;
    }
    return null;
  }
View Full Code Here

    return index.getMeasures(resource, filter);
  }

  @Override
  public Measure saveMeasure(Resource resource, Metric metric, Double value) {
    return saveMeasure(resource, new Measure(metric, value));
  }
View Full Code Here

    for (Object[] object : objects) {
      MeasureModel model = (MeasureModel) object[0];
      Integer characteristicId = model.getCharacteristicId();
      Characteristic characteristic = techDebtModel.characteristicById(characteristicId);
      Measure measure = toMeasure(model, metricById.get(model.getMetricId()), characteristic);
      measure.setDate((Date) object[1]);
      result.add(measure);
    }
    return result;
  }
View Full Code Here

    return result;
  }

  static Measure toMeasure(MeasureModel model, Metric metric, @Nullable Characteristic characteristic) {
    // NOTE: measures on rule are not supported
    Measure measure = new Measure(metric);
    measure.setDescription(model.getDescription());
    measure.setValue(model.getValue());
    measure.setData(model.getData(metric));
    measure.setAlertStatus(model.getAlertStatus());
    measure.setAlertText(model.getAlertText());
    measure.setTendency(model.getTendency());
    measure.setVariation1(model.getVariationValue1());
    measure.setVariation2(model.getVariationValue2());
    measure.setVariation3(model.getVariationValue3());
    measure.setVariation4(model.getVariationValue4());
    measure.setVariation5(model.getVariationValue5());
    measure.setUrl(model.getUrl());
    measure.setCharacteristic(characteristic);
    measure.setPersonId(model.getPersonId());
    return measure;
  }
View Full Code Here

TOP

Related Classes of org.sonar.api.measures.Measure

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.