]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-11077 display nb of analyzed components in CE logs
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Fri, 3 Aug 2018 09:38:58 +0000 (11:38 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Sun, 5 Aug 2018 21:17:30 +0000 (23:17 +0200)
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/component/TreeRootHolder.java
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/component/TreeRootHolderImpl.java
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/BuildComponentTreeStep.java
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/component/TreeRootHolderImplTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/component/TreeRootHolderRule.java

index f9ae8404effc8260d31e5480dc219609a1da6ac7..b8166c86daf2182720b1b6805bf383e37aaeff43 100644 (file)
@@ -39,4 +39,10 @@ public interface TreeRootHolder {
    */
   Component getComponentByRef(int ref);
 
+  /**
+   * Number of components, including root.
+   *
+   * @throws IllegalStateException if the holder is empty (ie. there is no root yet)
+   */
+  int getSize();
 }
index ea12670158bccadd4fe92964ed98877d9b6191b7..ab5b2cec0ac340de1d81a5c192c9998e59bd0537 100644 (file)
@@ -59,6 +59,13 @@ public class TreeRootHolderImpl implements MutableTreeRootHolder {
     return component;
   }
 
+  @Override
+  public int getSize() {
+    checkInitialized();
+    ensureComponentByRefIsPopulated();
+    return componentsByRef.size();
+  }
+
   private void ensureComponentByRefIsPopulated() {
     if (componentsByRef != null) {
       return;
index fffb6cb5db0f784c4f9b13515bbddaeb2e847120..cddc65268afe31ff2e9f8b78a87178f62b4b4333 100644 (file)
@@ -21,6 +21,7 @@ package org.sonar.server.computation.task.projectanalysis.step;
 
 import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
+import org.sonar.api.utils.log.Loggers;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.component.SnapshotDto;
@@ -86,6 +87,8 @@ public class BuildComponentTreeStep implements ComputationStep {
 
       treeRootHolder.setRoot(project);
       analysisMetadataHolder.setBaseAnalysis(toAnalysis(baseAnalysis));
+
+      Loggers.get(getClass()).debug("components={}", treeRootHolder.getSize());
     }
   }
 
index f9d16b0e15771a0f0a3940545b17df6597e89976..89c26966d8347c02dc6e2392c7e91f2993346ccf 100644 (file)
@@ -125,6 +125,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 ea4ed8a60980123b980ae858877a5d8e0b5ad624..cf8c0510cc8d24d83e66620b3398f536ceff514e 100644 (file)
@@ -44,4 +44,9 @@ public class TreeRootHolderRule extends ExternalResource implements TreeRootHold
   public Component getComponentByRef(int ref) {
     return delegate.getComponentByRef(ref);
   }
+
+  @Override
+  public int getSize() {
+    return delegate.getSize();
+  }
 }