]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-11077 display nb of analyzed components in CE logs
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Mon, 30 Jul 2018 15:30:21 +0000 (17:30 +0200)
committerSonarTech <sonartech@sonarsource.com>
Thu, 2 Aug 2018 18:21:36 +0000 (20:21 +0200)
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/TreeRootHolder.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/TreeRootHolderImpl.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/BuildComponentTreeStep.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/TreeRootHolderImplTest.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/TreeRootHolderRule.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/BuildComponentTreeStepTest.java

index a1d6e7b321ddc47afa1ab408b549d25503f4a4c1..85785ed633204fb2e8ef7dd651049652530949e9 100644 (file)
@@ -48,9 +48,15 @@ public interface TreeRootHolder {
    *
    * @throws IllegalStateException if the holder is empty (ie. there is no root yet)
    * @deprecated This method was introduced as a quick fix for SONAR-10781. Ultimately one should never manipulate component
-   * ref that doesn't exists in the scanner report
+   * ref that doesn't exist in the scanner report
    */
   @Deprecated
   Optional<Component> getOptionalComponentByRef(int ref);
 
+  /**
+   * Number of components, including root.
+   *
+   * @throws IllegalStateException if the holder is empty (ie. there is no root yet)
+   */
+  int getSize();
 }
index e4cf576fdb78fee3875b3d97dd49baef6ba0d3ea..9598d93aabaf86553f4f660f8b9b0f8195091c88 100644 (file)
@@ -63,6 +63,13 @@ public class TreeRootHolderImpl implements MutableTreeRootHolder {
     return Optional.ofNullable(componentsByRef.get(ref));
   }
 
+  @Override
+  public int getSize() {
+    checkInitialized();
+    ensureComponentByRefIsPopulated();
+    return componentsByRef.size();
+  }
+
   private void ensureComponentByRefIsPopulated() {
     if (componentsByRef != null) {
       return;
index 6d8174954bc79c9eba245879fc09cb4e2f7f1a16..fee73596d1457edae4e29610951880194414b4c5 100644 (file)
@@ -88,6 +88,8 @@ public class BuildComponentTreeStep implements ComputationStep {
 
       treeRootHolder.setRoot(project);
       analysisMetadataHolder.setBaseAnalysis(toAnalysis(baseAnalysis));
+
+      context.getStatistics().add("components", treeRootHolder.getSize());
     }
   }
 
index ca8f50854f14c673ebc7b5a933f6c151b3d92aaa..18c313064642c3aa4b79e3a231b3ab0ef02e4653 100644 (file)
@@ -138,6 +138,19 @@ public class TreeRootHolderImplTest {
     assertThat(underTest.getRoot()).isSameAs(DUMB_PROJECT);
   }
 
+  @Test
+  public void getSize_throws_ISE_if_not_initialized() {
+    expectNotInitialized_ISE();
+
+    underTest.getSize();
+  }
+
+  @Test
+  public void getSize_counts_number_of_components() {
+    underTest.setRoot(SOME_REPORT_COMPONENT_TREE);
+    assertThat(underTest.getSize()).isEqualTo(4);
+  }
+
   private void expectNotInitialized_ISE() {
     expectedException.expect(IllegalStateException.class);
     expectedException.expectMessage("Holder has not been initialized yet");
index 2bec414a8b381a90d3da6d518008cb0e5e1c4c4a..49b3adc167471b7f55614f5d31ddfba838465a8a 100644 (file)
@@ -50,4 +50,11 @@ public class TreeRootHolderRule extends ExternalResource implements TreeRootHold
   public Optional<Component> getOptionalComponentByRef(int ref) {
     return delegate.getOptionalComponentByRef(ref);
   }
+
+  @Override
+  public int getSize() {
+    return delegate.getSize();
+  }
+
+
 }
index f5b0b78d7070b59a4582ecec3454484996a4234c..2ac9cdbab6dc42fb33beddfbba19af8e0d559dc3 100644 (file)
@@ -147,7 +147,8 @@ public class BuildComponentTreeStepTest {
     reportReader.putComponent(component(DIR_REF_2, DIRECTORY, FILE_3_REF));
     reportReader.putComponent(component(FILE_3_REF, FILE));
 
-    underTest.execute(new TestComputationStepContext());
+    TestComputationStepContext context = new TestComputationStepContext();
+    underTest.execute(context);
 
     Component root = treeRootHolder.getRoot();
     assertThat(root).isNotNull();
@@ -161,6 +162,8 @@ public class BuildComponentTreeStepTest {
     Component dir2 = module.getChildren().get(1);
     verifyComponent(dir2, Component.Type.DIRECTORY, DIR_REF_2, 1);
     verifyComponent(dir2.getChildren().iterator().next(), Component.Type.FILE, FILE_3_REF, 0);
+
+    context.getStatistics().assertValue("components", 7);
   }
 
   @Test