]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7150 directories count doesn't include empty directories
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 2 May 2016 08:28:50 +0000 (10:28 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Tue, 3 May 2016 12:26:32 +0000 (14:26 +0200)
server/sonar-server/src/main/java/org/sonar/server/computation/step/SizeMeasuresStep.java
server/sonar-server/src/test/java/org/sonar/server/computation/step/ReportSizeMeasuresStepTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/step/ViewsSizeMeasuresStepTest.java

index fce9685f812357184631016058ad96221af26165..8fd191a547961f97679720e661238961a4d95caa 100644 (file)
@@ -121,8 +121,8 @@ public class SizeMeasuresStep implements ComputationStep {
     }
 
     private void createMeasures(Component directory, int dirCount, int fileCount) {
-      measureRepository.add(directory, directoryMetric, newMeasureBuilder().create(dirCount));
       if (fileCount > 0) {
+        measureRepository.add(directory, directoryMetric, newMeasureBuilder().create(dirCount));
         measureRepository.add(directory, fileMetric, newMeasureBuilder().create(fileCount));
       }
     }
index d5d0183e0c41bb61d994ca9bff1317e6fedecfe2..d668f2a99dd4eb9e9742a1244c2cb06936b64241 100644 (file)
@@ -65,7 +65,7 @@ public class ReportSizeMeasuresStepTest {
   private static final int FILE_3_REF = 12351;
   private static final int UNIT_TEST_1_REF = 12352;
   private static final int UNIT_TEST_2_REF = 12361;
-  private static final Integer NO_FILE_METRIC = null;
+  private static final Integer NO_METRIC = null;
 
   @Rule
   public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule().setRoot(
@@ -120,7 +120,7 @@ public class ReportSizeMeasuresStepTest {
     verifyNoMeasure(UNIT_TEST_2_REF);
     verifyMeasuresOnOtherComponent(DIRECTORY_1_REF, 2, 1);
     verifyMeasuresOnOtherComponent(DIRECTORY_2_REF, 1, 1);
-    verifyMeasuresOnOtherComponent(DIRECTORY_3_REF, NO_FILE_METRIC, 1);
+    verifyMeasuresOnOtherComponent(DIRECTORY_3_REF, NO_METRIC, NO_METRIC);
     verifyMeasuresOnOtherComponent(SUB_MODULE_REF, 3, 3);
     verifyMeasuresOnOtherComponent(MODULE_REF, 3, 3);
     verifyMeasuresOnOtherComponent(ROOT_REF, 3, 3);
@@ -155,7 +155,7 @@ public class ReportSizeMeasuresStepTest {
       entryOf(metric1Key, newMeasureBuilder().create(7)),
       entryOf(metric2Key, newMeasureBuilder().create(100))
     };
-    verifyMeasuresOnOtherComponent(DIRECTORY_3_REF, NO_FILE_METRIC, 1);
+    verifyMeasuresOnOtherComponent(DIRECTORY_3_REF, NO_METRIC, NO_METRIC);
     verifyMeasuresOnOtherComponent(SUB_MODULE_REF, 3, 3, subModuleAndAboveEntries);
     verifyMeasuresOnOtherComponent(MODULE_REF, 3, 3, subModuleAndAboveEntries);
     verifyMeasuresOnOtherComponent(ROOT_REF, 3, 3, subModuleAndAboveEntries);
@@ -180,7 +180,7 @@ public class ReportSizeMeasuresStepTest {
     verifyNoMeasure(UNIT_TEST_2_REF);
     verifyMeasuresOnOtherComponent(DIRECTORY_1_REF, 2, 1, entryOf(metricKey, newMeasureBuilder().create(16)));
     verifyMeasuresOnOtherComponent(DIRECTORY_2_REF, 1, 1, entryOf(metricKey, newMeasureBuilder().create(3)));
-    verifyMeasuresOnOtherComponent(DIRECTORY_3_REF, NO_FILE_METRIC, 1);
+    verifyMeasuresOnOtherComponent(DIRECTORY_3_REF, NO_METRIC, NO_METRIC);
     verifyMeasuresOnOtherComponent(SUB_MODULE_REF, 3, 3, entryOf(metricKey, newMeasureBuilder().create(19)));
     verifyMeasuresOnOtherComponent(MODULE_REF, 3, 3, entryOf(metricKey, newMeasureBuilder().create(19)));
     verifyMeasuresOnOtherComponent(ROOT_REF, 3, 3, entryOf(metricKey, newMeasureBuilder().create(19)));
@@ -201,10 +201,12 @@ public class ReportSizeMeasuresStepTest {
       .containsOnly(entryOf(FILES_KEY, newMeasureBuilder().create(fileCount)));
   }
 
-  private void verifyMeasuresOnOtherComponent(int componentRef, @Nullable Integer fileCount, int directoryCount, MeasureRepoEntry... otherMeasures) {
+  private void verifyMeasuresOnOtherComponent(int componentRef, @Nullable Integer fileCount, @Nullable Integer directoryCount, MeasureRepoEntry... otherMeasures) {
     MeasureRepoEntry[] measureRepoEntries = concatIntoArray(
       otherMeasures,
-      fileCount == null ? null : entryOf(FILES_KEY, newMeasureBuilder().create(fileCount)), entryOf(DIRECTORIES_KEY, newMeasureBuilder().create(directoryCount)));
+      fileCount == null ? null : entryOf(FILES_KEY, newMeasureBuilder().create(fileCount)),
+      directoryCount == null ? null : entryOf(DIRECTORIES_KEY, newMeasureBuilder().create(directoryCount))
+    );
     assertThat(toEntries(measureRepository.getAddedRawMeasures(componentRef)))
       .containsOnly(measureRepoEntries);
   }
index eb7037eb5b31ff5ebbbf1d1ea41b81e264e46fe0..2e691f4e7b4f52030eb81c6a3620359a26ea52ac 100644 (file)
@@ -62,7 +62,7 @@ public class ViewsSizeMeasuresStepTest {
   private static final int PROJECTVIEW_3_REF = 1241;
   private static final int PROJECTVIEW_4_REF = 1251;
   private static final int PROJECTVIEW_5_REF = 14;
-  private static final Integer NO_FILE_METRIC = null;
+  private static final Integer NO_METRIC = null;
 
   @Rule
   public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule().setRoot(
@@ -124,9 +124,9 @@ public class ViewsSizeMeasuresStepTest {
     verifyNoMeasure(PROJECTVIEW_5_REF);
     verifyMeasures(SUB_SUBVIEW_1_REF, 3, 3);
     verifyMeasures(SUB_SUBVIEW_2_REF, 3, 0);
-    verifyMeasures(SUB_SUBVIEW_3_REF, NO_FILE_METRIC, 4);
+    verifyMeasures(SUB_SUBVIEW_3_REF, NO_METRIC, NO_METRIC);
     verifyMeasures(SUBVIEW_1_REF, 6, 7);
-    verifyMeasures(SUBVIEW_2_REF, NO_FILE_METRIC, 0);
+    verifyMeasures(SUBVIEW_2_REF, NO_METRIC, NO_METRIC);
     verifyMeasures(ROOT_REF, 11, 12);
   }
 
@@ -157,11 +157,11 @@ public class ViewsSizeMeasuresStepTest {
     verifyMeasures(SUB_SUBVIEW_1_REF, 3, 3,
         entryOf(metric1Key, newMeasureBuilder().create(7)), entryOf(metric2Key, newMeasureBuilder().create(10)));
     verifyMeasures(SUB_SUBVIEW_2_REF, 3, 0);
-    verifyMeasures(SUB_SUBVIEW_3_REF, NO_FILE_METRIC, 4,
+    verifyMeasures(SUB_SUBVIEW_3_REF, NO_METRIC, NO_METRIC,
         entryOf(metric2Key, newMeasureBuilder().create(90)));
     verifyMeasures(SUBVIEW_1_REF, 6, 7,
         entryOf(metric1Key, newMeasureBuilder().create(7)), entryOf(metric2Key, newMeasureBuilder().create(100)));
-    verifyMeasures(SUBVIEW_2_REF, NO_FILE_METRIC, 0);
+    verifyMeasures(SUBVIEW_2_REF, NO_METRIC, NO_METRIC);
     verifyMeasures(ROOT_REF, 11, 12,
         entryOf(metric1Key, newMeasureBuilder().create(10)), entryOf(metric2Key, newMeasureBuilder().create(107)));
   }
@@ -186,9 +186,9 @@ public class ViewsSizeMeasuresStepTest {
     verifyNoMeasure(PROJECTVIEW_5_REF);
     verifyMeasures(SUB_SUBVIEW_1_REF, 3, 3, entryOf(metricKey, newMeasureBuilder().create(16)));
     verifyMeasures(SUB_SUBVIEW_2_REF, 3, 0);
-    verifyMeasures(SUB_SUBVIEW_3_REF, NO_FILE_METRIC, 4, entryOf(metricKey, newMeasureBuilder().create(3)));
+    verifyMeasures(SUB_SUBVIEW_3_REF, NO_METRIC, NO_METRIC, entryOf(metricKey, newMeasureBuilder().create(3)));
     verifyMeasures(SUBVIEW_1_REF, 6, 7, entryOf(metricKey, newMeasureBuilder().create(19)));
-    verifyMeasures(SUBVIEW_2_REF, NO_FILE_METRIC, 0);
+    verifyMeasures(SUBVIEW_2_REF, NO_METRIC, NO_METRIC);
     verifyMeasures(ROOT_REF, 11, 12, entryOf(metricKey, newMeasureBuilder().create(26)));
   }
 
@@ -202,16 +202,16 @@ public class ViewsSizeMeasuresStepTest {
     verifyMetricAggregation(CLASSES_KEY);
   }
 
-  private void verifyMeasures(int componentRef, @Nullable Integer fileCount, int directoryCount, MeasureRepoEntry... otherMeasures) {
+  private void verifyMeasures(int componentRef, @Nullable Integer fileCount, @Nullable Integer directoryCount, MeasureRepoEntry... otherMeasures) {
     assertThat(toEntries(measureRepository.getAddedRawMeasures(componentRef)))
         .containsOnly(
             concatIntoArray(otherMeasures, createFileAndDirectoryEntries(fileCount, directoryCount)));
   }
 
-  private static MeasureRepoEntry[] createFileAndDirectoryEntries(@Nullable Integer fileCount, int directoryCount) {
+  private static MeasureRepoEntry[] createFileAndDirectoryEntries(@Nullable Integer fileCount, @Nullable Integer directoryCount) {
     return new MeasureRepoEntry[] {
       fileCount == null ? null : entryOf(FILES_KEY, newMeasureBuilder().create(fileCount)),
-      entryOf(DIRECTORIES_KEY, newMeasureBuilder().create(directoryCount))
+      directoryCount == null ? null : entryOf(DIRECTORIES_KEY, newMeasureBuilder().create(directoryCount))
     };
   }