]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6859 deprecate debt size metric property
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Tue, 22 Sep 2015 17:24:48 +0000 (19:24 +0200)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Fri, 25 Sep 2015 13:03:00 +0000 (15:03 +0200)
and also drop the associated language specific size metric properties

server/sonar-server/src/main/java/org/sonar/server/computation/sqale/SqaleMeasuresVisitor.java
server/sonar-server/src/main/java/org/sonar/server/computation/sqale/SqaleRatingSettings.java
server/sonar-server/src/test/java/org/sonar/server/computation/sqale/ReportSqaleMeasuresVisitorTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/sqale/SqaleRatingSettingsTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/sqale/ViewsSqaleMeasuresVisitorTest.java
sonar-core/src/main/java/org/sonar/core/config/DebtProperties.java
sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java

index 2e1171d0148e1dcb9cc0386ccc7535068935c30b..7ebcf4ea813ebf476c0f6b8489dcb3dbcc92f5f4 100644 (file)
@@ -38,10 +38,10 @@ import static org.sonar.server.computation.measure.Measure.newMeasureBuilder;
 public class SqaleMeasuresVisitor extends PathAwareVisitorAdapter<SqaleMeasuresVisitor.DevelopmentCostCounter> {
   private static final Logger LOG = Loggers.get(SqaleMeasuresVisitor.class);
 
-  private final MetricRepository metricRepository;
   private final MeasureRepository measureRepository;
   private final SqaleRatingSettings sqaleRatingSettings;
 
+  private final Metric nclocMetric;
   private final Metric developmentCostMetric;
   private final Metric technicalDebtMetric;
   private final Metric debtRatioMetric;
@@ -49,14 +49,14 @@ public class SqaleMeasuresVisitor extends PathAwareVisitorAdapter<SqaleMeasuresV
 
   public SqaleMeasuresVisitor(MetricRepository metricRepository, MeasureRepository measureRepository, SqaleRatingSettings sqaleRatingSettings) {
     super(CrawlerDepthLimit.LEAVES, POST_ORDER, DevelopmentCostCounterFactory.INSTANCE);
-    this.metricRepository = metricRepository;
     this.measureRepository = measureRepository;
     this.sqaleRatingSettings = sqaleRatingSettings;
 
-    this.developmentCostMetric = this.metricRepository.getByKey(CoreMetrics.DEVELOPMENT_COST_KEY);
-    this.technicalDebtMetric = this.metricRepository.getByKey(CoreMetrics.TECHNICAL_DEBT_KEY);
-    this.debtRatioMetric = this.metricRepository.getByKey(CoreMetrics.SQALE_DEBT_RATIO_KEY);
-    this.sqaleRatingMetric = this.metricRepository.getByKey(CoreMetrics.SQALE_RATING_KEY);
+    this.nclocMetric = metricRepository.getByKey(CoreMetrics.NCLOC_KEY);
+    this.developmentCostMetric = metricRepository.getByKey(CoreMetrics.DEVELOPMENT_COST_KEY);
+    this.technicalDebtMetric = metricRepository.getByKey(CoreMetrics.TECHNICAL_DEBT_KEY);
+    this.debtRatioMetric = metricRepository.getByKey(CoreMetrics.SQALE_DEBT_RATIO_KEY);
+    this.sqaleRatingMetric = metricRepository.getByKey(CoreMetrics.SQALE_RATING_KEY);
   }
 
   @Override
@@ -147,10 +147,8 @@ public class SqaleMeasuresVisitor extends PathAwareVisitorAdapter<SqaleMeasuresV
   }
 
   private long computeDevelopmentCost(Component file) {
-    String languageKey = file.getFileAttributes().getLanguageKey();
-    String sizeMetricKey = sqaleRatingSettings.getSizeMetricKey(languageKey);
-    Metric sizeMetric = metricRepository.getByKey(sizeMetricKey);
-    return getLongValue(measureRepository.getRawMeasure(file, sizeMetric)) * sqaleRatingSettings.getDevCost(languageKey);
+    long ncloc = getLongValue(measureRepository.getRawMeasure(file, this.nclocMetric));
+    return ncloc * sqaleRatingSettings.getDevCost(file.getFileAttributes().getLanguageKey());
   }
 
   private static long getLongValue(Optional<Measure> measure) {
index 53add370c6848ba4fb5f4cda5427ee16148ec96b..90e48436cd12873b70eab4625d95b0359a15a5f1 100644 (file)
@@ -35,7 +35,6 @@ import static org.sonar.api.CoreProperties.LANGUAGE_SPECIFIC_PARAMETERS_MAN_DAYS
 import static org.sonar.api.CoreProperties.LANGUAGE_SPECIFIC_PARAMETERS_SIZE_METRIC_KEY;
 import static org.sonar.api.CoreProperties.RATING_GRID;
 import static org.sonar.api.CoreProperties.RATING_GRID_DEF_VALUES;
-import static org.sonar.api.CoreProperties.SIZE_METRIC;
 
 public class SqaleRatingSettings {
 
@@ -96,18 +95,6 @@ public class SqaleRatingSettings {
     }
   }
 
-  public String getSizeMetricKey(@Nullable String languageKey) {
-    if (languageKey == null) {
-      return settings.getString(SIZE_METRIC);
-    }
-
-    LanguageSpecificConfiguration languageSpecificConfig = getSpecificParametersForLanguage(languageKey);
-    if (languageSpecificConfig != null && languageSpecificConfig.getMetricKey() != null) {
-      return languageSpecificConfig.getMetricKey();
-    }
-    return settings.getString(SIZE_METRIC);
-  }
-
   @CheckForNull
   private LanguageSpecificConfiguration getSpecificParametersForLanguage(String languageKey) {
     return languageSpecificConfigurationByLanguageKey.get(languageKey);
index 63287ea15fecb41a7986198152aed83ecc6ebf84..b06cbc2f62117fa18387273190565941aff99b28 100644 (file)
@@ -32,14 +32,13 @@ import org.sonar.server.computation.component.ReportComponent;
 import org.sonar.server.computation.component.VisitorsCrawler;
 import org.sonar.server.computation.measure.Measure;
 import org.sonar.server.computation.measure.MeasureRepositoryRule;
-import org.sonar.server.computation.metric.Metric;
-import org.sonar.server.computation.metric.MetricImpl;
 import org.sonar.server.computation.metric.MetricRepositoryRule;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 import static org.sonar.api.measures.CoreMetrics.DEVELOPMENT_COST_KEY;
+import static org.sonar.api.measures.CoreMetrics.NCLOC_KEY;
 import static org.sonar.api.measures.CoreMetrics.SQALE_DEBT_RATIO_KEY;
 import static org.sonar.api.measures.CoreMetrics.SQALE_RATING_KEY;
 import static org.sonar.api.measures.CoreMetrics.TECHNICAL_DEBT_KEY;
@@ -56,10 +55,6 @@ import static org.sonar.server.computation.sqale.SqaleRatingGrid.SqaleRating.C;
 
 public class ReportSqaleMeasuresVisitorTest {
 
-  private static final String METRIC_KEY_1 = "mKey1";
-  private static final String METRIC_KEY_2 = "mKey2";
-  private static final Metric METRIC_1 = new MetricImpl(1, METRIC_KEY_1, "metric1", Metric.MetricType.FLOAT);
-  private static final Metric METRIC_2 = new MetricImpl(2, METRIC_KEY_2, "metric2", Metric.MetricType.WORK_DUR);
   private static final String LANGUAGE_KEY_1 = "lKey1";
   private static final String LANGUAGE_KEY_2 = "lKey2";
   private static final double[] RATING_GRID = new double[] {34, 50, 362, 900, 36258};
@@ -70,8 +65,7 @@ public class ReportSqaleMeasuresVisitorTest {
   public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule();
   @Rule
   public MetricRepositoryRule metricRepository = new MetricRepositoryRule()
-    .add(METRIC_1)
-    .add(METRIC_2)
+    .add(CoreMetrics.NCLOC)
     .add(CoreMetrics.DEVELOPMENT_COST)
     .add(CoreMetrics.TECHNICAL_DEBT)
     .add(CoreMetrics.SQALE_DEBT_RATIO)
@@ -87,8 +81,6 @@ public class ReportSqaleMeasuresVisitorTest {
   public void setUp() {
     // assumes SQALE rating configuration is consistent
     when(sqaleRatingSettings.getRatingGrid()).thenReturn(RATING_GRID);
-    when(sqaleRatingSettings.getSizeMetricKey(LANGUAGE_KEY_1)).thenReturn(METRIC_KEY_1);
-    when(sqaleRatingSettings.getSizeMetricKey(LANGUAGE_KEY_2)).thenReturn(METRIC_KEY_2);
     when(sqaleRatingSettings.getDevCost(LANGUAGE_KEY_1)).thenReturn(DEV_COST_LANGUAGE_1);
     when(sqaleRatingSettings.getDevCost(LANGUAGE_KEY_2)).thenReturn(DEV_COST_LANGUAGE_2);
   }
@@ -113,26 +105,25 @@ public class ReportSqaleMeasuresVisitorTest {
 
   @Test
   public void verify_computation_of_measures_for_file_depending_upon_language_1() {
-    verify_computation_of_measure_for_file(33000l, DEV_COST_LANGUAGE_1, METRIC_KEY_1, LANGUAGE_KEY_1, C);
+    verify_computation_of_measure_for_file(33000l, DEV_COST_LANGUAGE_1, LANGUAGE_KEY_1, C);
   }
 
   @Test
   public void verify_computation_of_measures_for_file_depending_upon_language_2() {
-    verify_computation_of_measure_for_file(4200l, DEV_COST_LANGUAGE_2, METRIC_KEY_2, LANGUAGE_KEY_2, A);
+    verify_computation_of_measure_for_file(4200l, DEV_COST_LANGUAGE_2, LANGUAGE_KEY_2, A);
   }
 
   /**
    * Verify the computation of measures values depending upon which language is associated to the file by
    * processing a tree of a single Component of type FILE.
    */
-  private void verify_computation_of_measure_for_file(long debt, long languageCost, String metricKey, String languageKey,
-    SqaleRatingGrid.SqaleRating expectedRating) {
+  private void verify_computation_of_measure_for_file(long debt, long languageCost, String languageKey, SqaleRatingGrid.SqaleRating expectedRating) {
     long measureValue = 10;
 
     int componentRef = 1;
     ReportComponent fileComponent = createFileComponent(languageKey, componentRef);
     treeRootHolder.setRoot(fileComponent);
-    addRawMeasure(metricKey, componentRef, measureValue);
+    addRawMeasure(NCLOC_KEY, componentRef, measureValue);
     addRawMeasure(TECHNICAL_DEBT_KEY, componentRef, debt);
 
     underTest.visit(fileComponent);
@@ -172,12 +163,12 @@ public class ReportSqaleMeasuresVisitorTest {
 
     long measureValue1111 = 10;
     long debt1111 = 66000l;
-    addRawMeasure(METRIC_KEY_1, 1111, measureValue1111);
+    addRawMeasure(NCLOC_KEY, 1111, measureValue1111);
     addRawMeasure(TECHNICAL_DEBT_KEY, 1111, debt1111);
 
     long measureValue1112 = 10;
     long debt1112 = 4200l;
-    addRawMeasure(METRIC_KEY_2, 1112, measureValue1112);
+    addRawMeasure(NCLOC_KEY, 1112, measureValue1112);
     addRawMeasure(TECHNICAL_DEBT_KEY, 1112, debt1112);
 
     long debt111 = 96325l;
@@ -185,7 +176,7 @@ public class ReportSqaleMeasuresVisitorTest {
 
     long measureValue1121 = 30;
     long debt1121 = 25200l;
-    addRawMeasure(METRIC_KEY_2, 1121, measureValue1121);
+    addRawMeasure(NCLOC_KEY, 1121, measureValue1121);
     addRawMeasure(TECHNICAL_DEBT_KEY, 1121, debt1121);
 
     long debt112 = 99633l;
@@ -193,7 +184,7 @@ public class ReportSqaleMeasuresVisitorTest {
 
     long measureValue1211 = 20;
     long debt1211 = 33000l;
-    addRawMeasure(METRIC_KEY_1, 1211, measureValue1211);
+    addRawMeasure(NCLOC_KEY, 1211, measureValue1211);
     addRawMeasure(TECHNICAL_DEBT_KEY, 1211, debt1211);
 
     long debt121 = 7524l;
index a48753620fb2142489bd67595f09c2be44dcfb5e..f9432c02694762c564c5cb0a261aaf4b97bfbc3b 100644 (file)
@@ -62,14 +62,6 @@ public class SqaleRatingSettingsTest {
     assertThat(configurationLoader.getDevCost("defaultLanguage")).isEqualTo(50L);
   }
 
-  @Test
-  public void load_size_metric_for_language() {
-    settings.setProperty(CoreProperties.SIZE_METRIC, "complexity");
-    SqaleRatingSettings configurationLoader = new SqaleRatingSettings(settings);
-
-    assertThat(configurationLoader.getSizeMetricKey("defaultLanguage")).isEqualTo("complexity");
-  }
-
   @Test
   public void load_overridden_values_for_language() {
 
@@ -86,8 +78,6 @@ public class SqaleRatingSettingsTest {
 
     SqaleRatingSettings configurationLoader = new SqaleRatingSettings(settings);
 
-    assertThat(configurationLoader.getSizeMetricKey(aLanguage)).isEqualTo(CoreMetrics.NCLOC_KEY);
-    assertThat(configurationLoader.getSizeMetricKey(anotherLanguage)).isEqualTo(CoreMetrics.COMPLEXITY_KEY);
     assertThat(configurationLoader.getDevCost(aLanguage)).isEqualTo(30L);
     assertThat(configurationLoader.getDevCost(anotherLanguage)).isEqualTo(40L);
   }
@@ -106,7 +96,6 @@ public class SqaleRatingSettingsTest {
   public void use_generic_value_when_specific_setting_is_missing() {
     String aLanguage = "aLanguage";
 
-    settings.setProperty(CoreProperties.SIZE_METRIC, "complexity");
     settings.setProperty(CoreProperties.DEVELOPMENT_COST, "30");
     settings.setProperty(CoreProperties.LANGUAGE_SPECIFIC_PARAMETERS, "0");
     settings.setProperty(CoreProperties.LANGUAGE_SPECIFIC_PARAMETERS + "." + "0" + "." + CoreProperties.LANGUAGE_SPECIFIC_PARAMETERS_LANGUAGE_KEY, aLanguage);
@@ -114,7 +103,6 @@ public class SqaleRatingSettingsTest {
 
     SqaleRatingSettings configurationLoader = new SqaleRatingSettings(settings);
 
-    assertThat(configurationLoader.getSizeMetricKey(aLanguage)).isEqualTo(CoreMetrics.COMPLEXITY_KEY);
     assertThat(configurationLoader.getDevCost(aLanguage)).isEqualTo(40L);
   }
 }
index 51c717e2d44e6648a0350d90a14d48ca73c9521a..cdb5ed97f590361b4c3b958f955b183af9b3b365 100644 (file)
@@ -84,6 +84,7 @@ public class ViewsSqaleMeasuresVisitorTest {
       .build());
   @Rule
   public MetricRepositoryRule metricRepository = new MetricRepositoryRule()
+    .add(CoreMetrics.NCLOC)
     .add(CoreMetrics.DEVELOPMENT_COST)
     .add(CoreMetrics.TECHNICAL_DEBT)
     .add(CoreMetrics.SQALE_DEBT_RATIO)
index 2899477be3e867af6fcaaf60a6d80ae968cace08..18ea09998b3eb8375d54da820a632851795a70e3 100644 (file)
@@ -26,7 +26,6 @@ import org.sonar.api.CoreProperties;
 import org.sonar.api.PropertyType;
 import org.sonar.api.config.PropertyDefinition;
 import org.sonar.api.config.PropertyFieldDefinition;
-import org.sonar.api.measures.CoreMetrics;
 
 class DebtProperties {
 
@@ -44,16 +43,6 @@ class DebtProperties {
         .deprecatedKey("sqale.hoursInDay")
         .build(),
 
-      PropertyDefinition.builder(CoreProperties.SIZE_METRIC)
-        .defaultValue("" + CoreMetrics.NCLOC_KEY)
-        .name("Size metric")
-        .description("Metric used to estimate artifact's development cost.")
-        .type(PropertyType.METRIC)
-        .options("key:^(ncloc|complexity)$")
-        .category(CoreProperties.CATEGORY_TECHNICAL_DEBT)
-        .deprecatedKey("sizeMetric")
-        .build(),
-
       PropertyDefinition.builder(CoreProperties.DEVELOPMENT_COST)
         .defaultValue("" + CoreProperties.DEVELOPMENT_COST_DEF_VALUE)
         .name("Development cost")
@@ -90,12 +79,6 @@ class DebtProperties {
             .name("Development cost")
             .description("If left blank, the generic value defined in this section will be used.")
             .type(PropertyType.FLOAT)
-            .build(),
-          PropertyFieldDefinition.build(CoreProperties.LANGUAGE_SPECIFIC_PARAMETERS_SIZE_METRIC_KEY)
-            .name("Size metric")
-            .description("If left blank, the generic value defined in this section will be used.")
-            .type(PropertyType.METRIC)
-            .options("key:^(ncloc|complexity)$")
             .build()
         )
         .build()
index a7ecf44637c0a3f72bd468a261fb56e62c1afd61..67d32e50c0cb3f7969d266473c80f07ac84b041d 100644 (file)
@@ -499,7 +499,9 @@ public interface CoreProperties {
 
   /**
    * @since 4.5
+   * @deprecated no used anymore since 5.2
    */
+  @Deprecated
   String SIZE_METRIC = "sonar.technicalDebt.sizeMetric";
 
   /**