]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-11664 Remove metric 'directories'
authorDuarte Meneses <duarte.meneses@sonarsource.com>
Wed, 6 Mar 2019 21:20:30 +0000 (15:20 -0600)
committerSonarTech <sonartech@sonarsource.com>
Fri, 15 Mar 2019 19:20:55 +0000 (20:20 +0100)
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/SizeMeasuresStep.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportSizeMeasuresStepTest.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsSizeMeasuresStepTest.java
sonar-plugin-api/src/main/java/org/sonar/api/measures/CoreMetrics.java

index 54dca2c7237c8015e5217b9b8157a0221b197a14..1cb39d9ef99ee0f4f5f32b7dc7c509e8b2d170e7 100644 (file)
@@ -37,7 +37,6 @@ import org.sonar.ce.task.projectanalysis.metric.MetricRepository;
 import org.sonar.ce.task.step.ComputationStep;
 
 import static org.sonar.api.measures.CoreMetrics.CLASSES_KEY;
-import static org.sonar.api.measures.CoreMetrics.DIRECTORIES_KEY;
 import static org.sonar.api.measures.CoreMetrics.FILES_KEY;
 import static org.sonar.api.measures.CoreMetrics.FUNCTIONS_KEY;
 import static org.sonar.api.measures.CoreMetrics.GENERATED_LINES_KEY;
@@ -75,7 +74,6 @@ public class SizeMeasuresStep implements ComputationStep {
   @Override
   public void execute(ComputationStep.Context context) {
     new PathAwareCrawler<>(new FileAndDirectoryMeasureVisitor(
-      metricRepository.getByKey(DIRECTORIES_KEY),
       metricRepository.getByKey(FILES_KEY),
       metricRepository.getByKey(LINES_KEY)))
       .visit(treeRootHolder.getRoot());
@@ -90,13 +88,11 @@ public class SizeMeasuresStep implements ComputationStep {
   }
 
   private class FileAndDirectoryMeasureVisitor extends PathAwareVisitorAdapter<Counter> {
-    private final Metric directoryMetric;
     private final Metric fileMetric;
     private final Metric linesMetric;
 
-    public FileAndDirectoryMeasureVisitor(Metric directoryMetric, Metric fileMetric, Metric linesMetric) {
+    public FileAndDirectoryMeasureVisitor(Metric fileMetric, Metric linesMetric) {
       super(CrawlerDepthLimit.LEAVES, POST_ORDER, COUNTER_STACK_ELEMENT_FACTORY);
-      this.directoryMetric = directoryMetric;
       this.fileMetric = fileMetric;
       this.linesMetric = linesMetric;
     }
@@ -109,25 +105,16 @@ public class SizeMeasuresStep implements ComputationStep {
     @Override
     public void visitDirectory(Component directory, Path<Counter> path) {
       int mainfileCount = path.current().files;
-      path.parent().directories += path.current().directories;
-      if (mainfileCount > 0 || path.current().directories > 0) {
-        path.parent().directories += 1;
-      }
       if (mainfileCount > 0) {
         measureRepository.add(directory, fileMetric, newMeasureBuilder().create(mainfileCount));
         measureRepository.add(directory, linesMetric, newMeasureBuilder().create(path.current().lines));
         path.parent().files += mainfileCount;
         path.parent().lines += path.current().lines;
       }
-      int mainDirectoryCount = path.current().directories;
-      if (mainDirectoryCount > 0) {
-        measureRepository.add(directory, directoryMetric, newMeasureBuilder().create(mainDirectoryCount));
-      }
     }
 
     private void createMeasures(Component directory, Counter counter) {
       if (counter.files > 0) {
-        measureRepository.add(directory, directoryMetric, newMeasureBuilder().create(counter.directories));
         measureRepository.add(directory, fileMetric, newMeasureBuilder().create(counter.files));
         measureRepository.add(directory, linesMetric, newMeasureBuilder().create(counter.lines));
       }
@@ -158,7 +145,6 @@ public class SizeMeasuresStep implements ComputationStep {
 
     @Override
     public void visitProjectView(Component projectView, Path<Counter> path) {
-      path.parent().directories += getIntValue(projectView, this.directoryMetric);
       path.parent().files += getIntValue(projectView, this.fileMetric);
       path.parent().lines += getIntValue(projectView, this.linesMetric);
     }
@@ -172,10 +158,8 @@ public class SizeMeasuresStep implements ComputationStep {
   private static class Counter {
     private int lines = 0;
     private int files = 0;
-    private int directories = 0;
 
     void aggregate(Counter counter) {
-      directories += counter.directories;
       files += counter.files;
       lines += counter.lines;
     }
index 3c528f849cfc6f8f329609b1a280acc5aa25bba1..d57e08f211a3e7a595317294e1c5ddf7c7b174b5 100644 (file)
@@ -36,7 +36,6 @@ import static com.google.common.collect.Iterables.concat;
 import static java.util.Arrays.asList;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.sonar.api.measures.CoreMetrics.CLASSES_KEY;
-import static org.sonar.api.measures.CoreMetrics.DIRECTORIES_KEY;
 import static org.sonar.api.measures.CoreMetrics.FILES_KEY;
 import static org.sonar.api.measures.CoreMetrics.FUNCTIONS_KEY;
 import static org.sonar.api.measures.CoreMetrics.GENERATED_LINES_KEY;
@@ -221,8 +220,7 @@ public class ReportSizeMeasuresStepTest {
     MeasureRepoEntry[] measureRepoEntries = concatIntoArray(
       otherMeasures,
       linesCount == null ? null : entryOf(LINES_KEY, newMeasureBuilder().create(linesCount)),
-      fileCount == null ? null : entryOf(FILES_KEY, newMeasureBuilder().create(fileCount)),
-      directoryCount == null ? null : entryOf(DIRECTORIES_KEY, newMeasureBuilder().create(directoryCount)));
+      fileCount == null ? null : entryOf(FILES_KEY, newMeasureBuilder().create(fileCount)));
     assertThat(toEntries(measureRepository.getAddedRawMeasures(componentRef)))
       .containsOnly(measureRepoEntries);
   }
index 6d776219663ceabfe73dbf22f512520cc7fd6366..5542479975479561d43813b1b7a6435d6f724ed3 100644 (file)
@@ -36,7 +36,6 @@ import static org.assertj.core.api.Assertions.assertThat;
 import static org.sonar.api.measures.CoreMetrics.CLASSES;
 import static org.sonar.api.measures.CoreMetrics.CLASSES_KEY;
 import static org.sonar.api.measures.CoreMetrics.DIRECTORIES;
-import static org.sonar.api.measures.CoreMetrics.DIRECTORIES_KEY;
 import static org.sonar.api.measures.CoreMetrics.FILES;
 import static org.sonar.api.measures.CoreMetrics.FILES_KEY;
 import static org.sonar.api.measures.CoreMetrics.FUNCTIONS;
@@ -118,12 +117,8 @@ public class ViewsSizeMeasuresStepTest {
     .addRawMeasure(PROJECTVIEW_2_REF, FILES_KEY, newMeasureBuilder().create(2))
     .addRawMeasure(PROJECTVIEW_3_REF, FILES_KEY, newMeasureBuilder().create(3))
     // PROJECTVIEW_4_REF has no file metric
-    .addRawMeasure(PROJECTVIEW_5_REF, FILES_KEY, newMeasureBuilder().create(5))
-    .addRawMeasure(PROJECTVIEW_1_REF, DIRECTORIES_KEY, newMeasureBuilder().create(1))
-    .addRawMeasure(PROJECTVIEW_2_REF, DIRECTORIES_KEY, newMeasureBuilder().create(2))
-    // PROJECTVIEW_3_REF has no directory metric
-    .addRawMeasure(PROJECTVIEW_4_REF, DIRECTORIES_KEY, newMeasureBuilder().create(4))
-    .addRawMeasure(PROJECTVIEW_5_REF, DIRECTORIES_KEY, newMeasureBuilder().create(5));
+    .addRawMeasure(PROJECTVIEW_5_REF, FILES_KEY, newMeasureBuilder().create(5));
+  // PROJECTVIEW_3_REF has no directory metric
 
   private SizeMeasuresStep underTest = new SizeMeasuresStep(treeRootHolder, metricRepository, measureRepository);
 
@@ -225,8 +220,7 @@ public class ViewsSizeMeasuresStepTest {
   private static MeasureRepoEntry[] createFileAndDirectoryEntries(@Nullable Integer linesCount, @Nullable Integer fileCount, @Nullable Integer directoryCount) {
     return new MeasureRepoEntry[] {
       linesCount == null ? null : entryOf(LINES_KEY, newMeasureBuilder().create(linesCount)),
-      fileCount == null ? null : entryOf(FILES_KEY, newMeasureBuilder().create(fileCount)),
-      directoryCount == null ? null : entryOf(DIRECTORIES_KEY, newMeasureBuilder().create(directoryCount))
+      fileCount == null ? null : entryOf(FILES_KEY, newMeasureBuilder().create(fileCount))
     };
   }
 
@@ -234,7 +228,7 @@ public class ViewsSizeMeasuresStepTest {
     return from(concat(
       asList(otherMeasures),
       from(asList(measureRepoEntries)).filter(notNull())))
-        .toArray(MeasureRepoEntry.class);
+      .toArray(MeasureRepoEntry.class);
   }
 
   private void verifyNoMeasure(int componentRef) {
index d15be6890ac03c26f37ca693fb117a001840e2d1..a8d6b9c34f6fdc4805bf2b2fd62b613858bbe554 100644 (file)
@@ -166,10 +166,16 @@ public final class CoreMetrics {
     .setDomain(DOMAIN_SIZE)
     .create();
 
+  /**
+   * @deprecated since 7.7 - no longer computed
+   */
+  @Deprecated
   public static final String DIRECTORIES_KEY = "directories";
+
   /**
-   * Computed by the platform.
+   * @deprecated since 7.7 - no longer computed
    */
+  @Deprecated
   public static final Metric<Integer> DIRECTORIES = new Metric.Builder(DIRECTORIES_KEY, "Directories", Metric.ValueType.INT)
     .setDescription("Directories")
     .setDirection(Metric.DIRECTION_WORST)
@@ -177,6 +183,9 @@ public final class CoreMetrics {
     .setDomain(DOMAIN_SIZE)
     .create();
 
+  /**
+   * Computed by the platform.
+   */
   public static final String FUNCTIONS_KEY = "functions";
   public static final Metric<Integer> FUNCTIONS = new Metric.Builder(FUNCTIONS_KEY, "Functions", Metric.ValueType.INT)
     .setDescription("Functions")