]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-17195 Move unanalyzed language flags to project level for telemetry
authoralain <108417558+alain-kermis-sonarsource@users.noreply.github.com>
Wed, 28 Sep 2022 12:29:30 +0000 (14:29 +0200)
committersonartech <sonartech@sonarsource.com>
Wed, 28 Sep 2022 20:04:08 +0000 (20:04 +0000)
12 files changed:
server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java
server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchDao.java
server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchMapper.java
server/sonar-db-dao/src/main/java/org/sonar/db/component/PrAndBranchCountByProjectDto.java [deleted file]
server/sonar-db-dao/src/main/java/org/sonar/db/component/PrBranchAnalyzedLanguageCountByProjectDto.java [new file with mode: 0644]
server/sonar-db-dao/src/main/resources/org/sonar/db/component/BranchMapper.xml
server/sonar-db-dao/src/test/java/org/sonar/db/component/BranchDaoTest.java
server/sonar-server-common/src/main/java/org/sonar/server/telemetry/TelemetryData.java
server/sonar-server-common/src/main/java/org/sonar/server/telemetry/TelemetryDataJsonWriter.java
server/sonar-server-common/src/test/java/org/sonar/server/telemetry/TelemetryDataJsonWriterTest.java
server/sonar-webserver-core/src/main/java/org/sonar/server/telemetry/TelemetryDataLoaderImpl.java
server/sonar-webserver-core/src/test/java/org/sonar/server/telemetry/TelemetryDataLoaderImplTest.java

index 02a2576417d5f63a01caec08a9197eb83263d021..14da008f50eb956f179bdb6337b737cbb5a33207 100644 (file)
@@ -56,7 +56,7 @@ import org.sonar.db.component.ComponentMapper;
 import org.sonar.db.component.ComponentWithModuleUuidDto;
 import org.sonar.db.component.FilePathWithHashDto;
 import org.sonar.db.component.KeyWithUuidDto;
-import org.sonar.db.component.PrAndBranchCountByProjectDto;
+import org.sonar.db.component.PrBranchAnalyzedLanguageCountByProjectDto;
 import org.sonar.db.component.ProjectLinkMapper;
 import org.sonar.db.component.ResourceDto;
 import org.sonar.db.component.ScrapAnalysisPropertyDto;
@@ -224,7 +224,7 @@ public class MyBatis {
     confBuilder.loadAlias("ProjectBadgeToken", ProjectBadgeTokenDto.class);
     confBuilder.loadAlias("AnalysisPropertyValuePerProject", AnalysisPropertyValuePerProject.class);
     confBuilder.loadAlias("ProjectAlmKeyAndProject", ProjectAlmKeyAndProject.class);
-    confBuilder.loadAlias("PrAndBranchCountByProjectDto", PrAndBranchCountByProjectDto.class);
+    confBuilder.loadAlias("PrAndBranchCountByProjectDto", PrBranchAnalyzedLanguageCountByProjectDto.class);
     confBuilder.loadAlias("ProjectMapping", ProjectMappingDto.class);
     confBuilder.loadAlias("ProjectMeasure", ProjectMeasureDto.class);
     confBuilder.loadAlias("PurgeableAnalysis", PurgeableAnalysisDto.class);
index 3ae1a2ce788b0eb5d4ee8d4bab12b975a6430828..38cca4e82014d96ad50fc7fe9f11ee24473fe343 100644 (file)
@@ -101,8 +101,8 @@ public class BranchDao implements Dao {
     return mapper(dbSession).selectByProjectUuid(project.getUuid());
   }
 
-  public List<PrAndBranchCountByProjectDto> countPrAndBranchByProjectUuid(DbSession dbSession){
-    return mapper(dbSession).countPrAndBranchByProjectUuid();
+  public List<PrBranchAnalyzedLanguageCountByProjectDto> countPrBranchAnalyzedLanguageByProjectUuid(DbSession dbSession){
+    return mapper(dbSession).countPrBranchAnalyzedLanguageByProjectUuid();
   }
 
   public List<BranchDto> selectByUuids(DbSession session, Collection<String> uuids) {
index 75159c2b668e0836f0310f0cd265bcf070be6ff3..9f19580941c27b45acf9e73edf441b7859fb0c10 100644 (file)
@@ -47,7 +47,7 @@ public interface BranchMapper {
 
   Collection<BranchDto> selectByProjectUuid(@Param("projectUuid") String projectUuid);
 
-  List<PrAndBranchCountByProjectDto> countPrAndBranchByProjectUuid();
+  List<PrBranchAnalyzedLanguageCountByProjectDto> countPrBranchAnalyzedLanguageByProjectUuid();
 
   List<BranchDto> selectByBranchKeys(@Param("branchKeyByProjectUuid") Map<String, String> branchKeyByProjectUuid);
 
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/PrAndBranchCountByProjectDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/PrAndBranchCountByProjectDto.java
deleted file mode 100644 (file)
index ef9149b..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2022 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.db.component;
-
-public class PrAndBranchCountByProjectDto {
-
-  private String projectUuid = null;
-  private Long pullRequest = null;
-  private Long branch = null;
-
-  public String getProjectUuid() {
-    return projectUuid;
-  }
-
-  public void setProjectUuid(String projectUuid) {
-    this.projectUuid = projectUuid;
-  }
-
-  public Long getPullRequest() {
-    return pullRequest;
-  }
-
-  public void setPullRequest(Long pullRequest) {
-    this.pullRequest = pullRequest;
-  }
-
-  public Long getBranch() {
-    return branch;
-  }
-
-  public void setBranch(Long branch) {
-    this.branch = branch;
-  }
-}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/PrBranchAnalyzedLanguageCountByProjectDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/PrBranchAnalyzedLanguageCountByProjectDto.java
new file mode 100644 (file)
index 0000000..c4aa693
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2022 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.db.component;
+
+public class PrBranchAnalyzedLanguageCountByProjectDto {
+
+  private String projectUuid = null;
+  private Long pullRequest = null;
+  private Long branch = null;
+  private Long unanalyzedCCount = null;
+  private Long unanalyzedCppCount = null;
+
+  public String getProjectUuid() {
+    return projectUuid;
+  }
+
+  public void setProjectUuid(String projectUuid) {
+    this.projectUuid = projectUuid;
+  }
+
+  public Long getPullRequest() {
+    return pullRequest;
+  }
+
+  public void setPullRequest(Long pullRequest) {
+    this.pullRequest = pullRequest;
+  }
+
+  public Long getBranch() {
+    return branch;
+  }
+
+  public void setBranch(Long branch) {
+    this.branch = branch;
+  }
+
+  public Long getUnanalyzedCCount() {
+    return unanalyzedCCount;
+  }
+
+  public void setUnanalyzedCCount(Long unanalyzedCCount) {
+    this.unanalyzedCCount = unanalyzedCCount;
+  }
+
+  public Long getUnanalyzedCppCount() {
+    return unanalyzedCppCount;
+  }
+
+  public void setUnanalyzedCppCount(Long unanalyzedCppCount) {
+    this.unanalyzedCppCount = unanalyzedCppCount;
+  }
+}
index 3b7c0abe6819aa58ebd1f4c0ec47cdd4217a6164..0cdef645451b06315bb196eacaaaf5e2610e3f57 100644 (file)
     pb.project_uuid = #{projectUuid, jdbcType=VARCHAR}
   </select>
 
-  <select id="countPrAndBranchByProjectUuid" resultType="org.sonar.db.component.PrAndBranchCountByProjectDto">
-    select project_uuid as projectUuid,
+  <select id="countPrBranchAnalyzedLanguageByProjectUuid" resultType="org.sonar.db.component.PrBranchAnalyzedLanguageCountByProjectDto">
+    select pb.project_uuid as projectUuid,
       sum(case when pb.branch_type = 'PULL_REQUEST' then 1 else 0 end) as pullRequest,
-      sum(case when pb.branch_type = 'BRANCH' then 1 else 0 end) as branch
-    from project_branches pb
+      sum(case when pb.branch_type = 'BRANCH' then 1 else 0 end) as branch,
+      (
+       select count(1) as counter from live_measures lm
+       inner join metrics m on m.uuid = lm.metric_uuid and m.name = 'unanalyzed_c'
+       where lm.project_uuid = pb.project_uuid) as unanalyzedCCount,
+      (
+       select count(1) as counter from live_measures lm
+       inner join metrics m on m.uuid = lm.metric_uuid and m.name = 'unanalyzed_cpp'
+       where lm.project_uuid = pb.project_uuid) as unanalyzedCppCount
+       from project_branches pb
     group by pb.project_uuid
   </select>
 
index b7bb8b9bdb832e89c9908dc33df1fcd5f697d38d..e58113a3212718f07a28c8bb8ecce80101127b71 100644 (file)
@@ -38,6 +38,7 @@ import org.sonar.api.impl.utils.TestSystem2;
 import org.sonar.api.utils.System2;
 import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
+import org.sonar.db.metric.MetricDto;
 import org.sonar.db.project.ProjectDto;
 import org.sonar.db.protobuf.DbProjectBranches;
 
@@ -562,12 +563,20 @@ public class BranchDaoTest {
     ComponentDto project3 = db.components().insertPrivateProject();
     db.components().insertProjectBranch(project3, b -> b.setBranchType(BRANCH).setKey("p3-branch-1"));
 
-    assertThat(underTest.countPrAndBranchByProjectUuid(db.getSession()))
-      .extracting(PrAndBranchCountByProjectDto::getProjectUuid, PrAndBranchCountByProjectDto::getBranch, PrAndBranchCountByProjectDto::getPullRequest)
+    MetricDto unanalyzedC = db.measures().insertMetric(m -> m.setKey("unanalyzed_c"));
+    MetricDto unanalyzedCpp = db.measures().insertMetric(m -> m.setKey("unanalyzed_cpp"));
+    db.measures().insertLiveMeasure(project1, unanalyzedC);
+    db.measures().insertLiveMeasure(project1, unanalyzedCpp);
+    db.measures().insertLiveMeasure(project2, unanalyzedCpp);
+    db.measures().insertLiveMeasure(project3, unanalyzedC);
+
+    assertThat(underTest.countPrBranchAnalyzedLanguageByProjectUuid(db.getSession()))
+      .extracting(PrBranchAnalyzedLanguageCountByProjectDto::getProjectUuid, PrBranchAnalyzedLanguageCountByProjectDto::getBranch, PrBranchAnalyzedLanguageCountByProjectDto::getPullRequest,
+        PrBranchAnalyzedLanguageCountByProjectDto::getUnanalyzedCCount, PrBranchAnalyzedLanguageCountByProjectDto::getUnanalyzedCppCount)
       .containsExactlyInAnyOrder(
-        tuple(project1.uuid(), 3L, 3L),
-        tuple(project2.uuid(), 1L, 1L),
-        tuple(project3.uuid(), 2L, 0L)
+        tuple(project1.uuid(), 3L, 3L, 1L, 1L),
+        tuple(project2.uuid(), 1L, 1L, 0L, 1L),
+        tuple(project3.uuid(), 2L, 0L, 1L, 0L)
       );
   }
 
index 09b2c1ee5a1f98d4d907aca1d9c224d375b1175a..d8caa44576c4a45fe97e53ecceac83695ca04a40 100644 (file)
@@ -41,8 +41,6 @@ public class TelemetryData {
   private final Long installationDate;
   private final String installationVersion;
   private final boolean inDocker;
-  private final Boolean hasUnanalyzedC;
-  private final Boolean hasUnanalyzedCpp;
   private final List<String> customSecurityConfigs;
   private final List<UserTelemetryDto> users;
   private final List<Project> projects;
@@ -58,8 +56,6 @@ public class TelemetryData {
     installationDate = builder.installationDate;
     installationVersion = builder.installationVersion;
     inDocker = builder.inDocker;
-    hasUnanalyzedC = builder.hasUnanalyzedC;
-    hasUnanalyzedCpp = builder.hasUnanalyzedCpp;
     customSecurityConfigs = builder.customSecurityConfigs == null ? emptyList() : builder.customSecurityConfigs;
     users = builder.users;
     projects = builder.projects;
@@ -102,14 +98,6 @@ public class TelemetryData {
     return inDocker;
   }
 
-  public Optional<Boolean> hasUnanalyzedC() {
-    return Optional.ofNullable(hasUnanalyzedC);
-  }
-
-  public Optional<Boolean> hasUnanalyzedCpp() {
-    return Optional.ofNullable(hasUnanalyzedCpp);
-  }
-
   public List<String> getCustomSecurityConfigs() {
     return customSecurityConfigs;
   }
@@ -140,8 +128,6 @@ public class TelemetryData {
     private Long installationDate;
     private String installationVersion;
     private boolean inDocker = false;
-    private Boolean hasUnanalyzedC;
-    private Boolean hasUnanalyzedCpp;
     private List<String> customSecurityConfigs;
     private List<UserTelemetryDto> users;
     private List<Project> projects;
@@ -196,16 +182,6 @@ public class TelemetryData {
       return this;
     }
 
-    Builder setHasUnanalyzedC(@Nullable Boolean hasUnanalyzedC) {
-      this.hasUnanalyzedC = hasUnanalyzedC;
-      return this;
-    }
-
-    Builder setHasUnanalyzedCpp(@Nullable Boolean hasUnanalyzedCpp) {
-      this.hasUnanalyzedCpp = hasUnanalyzedCpp;
-      return this;
-    }
-
     Builder setCustomSecurityConfigs(List<String> customSecurityConfigs) {
       this.customSecurityConfigs = customSecurityConfigs;
       return this;
@@ -288,14 +264,19 @@ public class TelemetryData {
     private final String projectUuid;
     private final Long branchCount;
     private final Long pullRequestCount;
+    private final Boolean hasUnanalyzedC;
+    private final Boolean hasUnanalyzedCpp;
     private final String scm;
     private final String ci;
     private final String devopsPlatform;
 
-    ProjectStatistics(String projectUuid, Long branchCount, Long pullRequestCount, @Nullable String scm, @Nullable String ci, @Nullable String devopsPlatform) {
+    ProjectStatistics(String projectUuid, Long branchCount, Long pullRequestCount, @Nullable Boolean hasUnanalyzedC, @Nullable Boolean hasUnanalyzedCpp,
+      @Nullable String scm, @Nullable String ci, @Nullable String devopsPlatform) {
       this.projectUuid = projectUuid;
       this.branchCount = branchCount;
       this.pullRequestCount = pullRequestCount;
+      this.hasUnanalyzedC = hasUnanalyzedC;
+      this.hasUnanalyzedCpp = hasUnanalyzedCpp;
       this.scm = scm;
       this.ci = ci;
       this.devopsPlatform = devopsPlatform;
@@ -327,5 +308,13 @@ public class TelemetryData {
     public String getDevopsPlatform() {
       return devopsPlatform;
     }
+
+    public Optional<Boolean> hasUnanalyzedC() {
+      return Optional.ofNullable(hasUnanalyzedC);
+    }
+
+    public Optional<Boolean> hasUnanalyzedCpp() {
+      return Optional.ofNullable(hasUnanalyzedCpp);
+    }
   }
 }
index c6ab6177ff83301231ec421db17d07c2b60735d4..8af18b0e16ea29d61ef45ffe33afd1dc13ea4aa1 100644 (file)
@@ -61,9 +61,6 @@ public class TelemetryDataJsonWriter {
       json.endArray();
     }
 
-    statistics.hasUnanalyzedC().ifPresent(hasUnanalyzedC -> json.prop("hasUnanalyzedC", hasUnanalyzedC));
-    statistics.hasUnanalyzedCpp().ifPresent(hasUnanalyzedCpp -> json.prop("hasUnanalyzedCpp", hasUnanalyzedCpp));
-
     if (statistics.getInstallationDate() != null) {
       json.prop("installationDate", toUtc(statistics.getInstallationDate()));
     }
@@ -132,6 +129,8 @@ public class TelemetryDataJsonWriter {
         json.prop("scm", project.getScm());
         json.prop("ci", project.getCi());
         json.prop("devopsPlatform", project.getDevopsPlatform());
+        project.hasUnanalyzedC().ifPresent(hasUnanalyzedC -> json.prop("hasUnanalyzedC", hasUnanalyzedC));
+        project.hasUnanalyzedCpp().ifPresent(hasUnanalyzedCpp -> json.prop("hasUnanalyzedCpp", hasUnanalyzedCpp));
         json.endObject();
       });
       json.endArray();
index 4d6d482f62d646e9d3027a750f59d900ea0c6815..6bc9a0c35fe0bfe1cf2c8eb46bb9515978cc996b 100644 (file)
@@ -229,21 +229,6 @@ public class TelemetryDataJsonWriterTest {
       "}");
   }
 
-  @Test
-  public void writes_has_unanalyzed_languages() {
-    TelemetryData data = SOME_TELEMETRY_DATA
-      .setHasUnanalyzedC(true)
-      .setHasUnanalyzedCpp(false)
-      .build();
-
-    String json = writeTelemetryData(data);
-
-    assertJson(json).isSimilarTo("{" +
-      "  \"hasUnanalyzedC\":true," +
-      "  \"hasUnanalyzedCpp\":false," +
-      "}");
-  }
-
   @Test
   public void writes_security_custom_config() {
     TelemetryData data = SOME_TELEMETRY_DATA
@@ -325,9 +310,9 @@ public class TelemetryDataJsonWriterTest {
   }
 
   @Test
-  public void writes_all_projects_stats() {
+  public void writes_all_projects_stats_with_analyzed_languages() {
     TelemetryData data = SOME_TELEMETRY_DATA
-      .setProjectStatistics(getProjectStats())
+      .setProjectStatistics(getProjectStats(true))
       .build();
 
     String json = writeTelemetryData(data);
@@ -340,7 +325,9 @@ public class TelemetryDataJsonWriterTest {
       "      \"pullRequestCount\": 2," +
       "      \"scm\": \"scm-0\"," +
       "      \"ci\": \"ci-0\"," +
-      "      \"devopsPlatform\": \"devops-0\"" +
+      "      \"devopsPlatform\": \"devops-0\"," +
+      "      \"hasUnanalyzedC\": true," +
+      "      \"hasUnanalyzedCpp\": false" +
       "    }," +
       "    {" +
       "      \"projectUuid\": \"uuid-1\"," +
@@ -348,7 +335,9 @@ public class TelemetryDataJsonWriterTest {
       "      \"pullRequestCount\": 4," +
       "      \"scm\": \"scm-1\"," +
       "      \"ci\": \"ci-1\"," +
-      "      \"devopsPlatform\": \"devops-1\"" +
+      "      \"devopsPlatform\": \"devops-1\"," +
+      "      \"hasUnanalyzedC\": false," +
+      "      \"hasUnanalyzedCpp\": true" +
       "    }," +
       "    {" +
       "      \"projectUuid\": \"uuid-2\"," +
@@ -356,12 +345,24 @@ public class TelemetryDataJsonWriterTest {
       "      \"pullRequestCount\": 6," +
       "      \"scm\": \"scm-2\"," +
       "      \"ci\": \"ci-2\"," +
-      "      \"devopsPlatform\": \"devops-2\"" +
+      "      \"devopsPlatform\": \"devops-2\"," +
+      "      \"hasUnanalyzedC\": true," +
+      "      \"hasUnanalyzedCpp\": false" +
       "    }" +
       "  ]" +
       "}");
   }
 
+  @Test
+  public void writes_all_projects_stats_with_unanalyzed_languages() {
+    TelemetryData data = SOME_TELEMETRY_DATA
+      .setProjectStatistics(getProjectStats(false))
+      .build();
+
+    String json = writeTelemetryData(data);
+    assertThat(json).doesNotContain("hasUnanalyzedC", "hasUnanalyzedCpp");
+  }
+
   @NotNull
   private static List<UserTelemetryDto> getUsers() {
     return IntStream.range(0, 3)
@@ -374,8 +375,8 @@ public class TelemetryDataJsonWriterTest {
     return IntStream.range(0, 3).mapToObj(i -> new TelemetryData.Project("uuid-" + i, 1L, "lang-" + i, (i + 1L) * 2L)).collect(Collectors.toList());
   }
 
-  private List<TelemetryData.ProjectStatistics> getProjectStats() {
-    return IntStream.range(0, 3).mapToObj(i -> new TelemetryData.ProjectStatistics("uuid-" + i, (i + 1L) * 2L, (i + 1L) * 2L, "scm-" + i, "ci-" + i, "devops-" + i))
+  private List<TelemetryData.ProjectStatistics> getProjectStats(boolean hasUnanalyzedLanguages) {
+    return IntStream.range(0, 3).mapToObj(i -> new TelemetryData.ProjectStatistics("uuid-" + i, (i + 1L) * 2L, (i + 1L) * 2L, hasUnanalyzedLanguages ? i % 2 == 0 : null, hasUnanalyzedLanguages ? i % 2 != 0 : null, "scm-" + i, "ci-" + i, "devops-" + i))
       .collect(Collectors.toList());
   }
 
index 4c6436847520796addbec37242d259d904ff5049..258e0128442cdc860710bf9e537e02e22f91faa3 100644 (file)
@@ -43,7 +43,7 @@ import org.sonar.db.DbSession;
 import org.sonar.db.alm.setting.ALM;
 import org.sonar.db.alm.setting.ProjectAlmKeyAndProject;
 import org.sonar.db.component.AnalysisPropertyValuePerProject;
-import org.sonar.db.component.PrAndBranchCountByProjectDto;
+import org.sonar.db.component.PrBranchAnalyzedLanguageCountByProjectDto;
 import org.sonar.db.measure.ProjectMeasureDto;
 import org.sonar.server.platform.DockerSupport;
 import org.sonar.server.property.InternalProperties;
@@ -58,8 +58,6 @@ import static org.sonar.core.config.CorePropertyDefinitions.SONAR_ANALYSIS_DETEC
 import static org.sonar.core.platform.EditionProvider.Edition.COMMUNITY;
 import static org.sonar.core.platform.EditionProvider.Edition.DATACENTER;
 import static org.sonar.core.platform.EditionProvider.Edition.ENTERPRISE;
-import static org.sonar.server.metric.UnanalyzedLanguageMetrics.UNANALYZED_CPP_KEY;
-import static org.sonar.server.metric.UnanalyzedLanguageMetrics.UNANALYZED_C_KEY;
 
 @ServerSide
 public class TelemetryDataLoaderImpl implements TelemetryDataLoader {
@@ -112,27 +110,30 @@ public class TelemetryDataLoaderImpl implements TelemetryDataLoader {
     data.setPlugins(plugins);
     try (DbSession dbSession = dbClient.openSession(false)) {
       data.setDatabase(loadDatabaseMetadata(dbSession));
-      long numberOfUnanalyzedCMeasures = dbClient.liveMeasureDao().countProjectsHavingMeasure(dbSession, UNANALYZED_C_KEY);
-      long numberOfUnanalyzedCppMeasures = dbClient.liveMeasureDao().countProjectsHavingMeasure(dbSession, UNANALYZED_CPP_KEY);
-      editionProvider.get()
-        .filter(edition -> edition.equals(COMMUNITY))
-        .ifPresent(edition -> {
-          data.setHasUnanalyzedC(numberOfUnanalyzedCMeasures > 0);
-          data.setHasUnanalyzedCpp(numberOfUnanalyzedCppMeasures > 0);
-        });
 
       Map<String, String> scmByProject = getAnalysisPropertyByProject(dbSession, SONAR_ANALYSIS_DETECTEDSCM);
       Map<String, String> ciByProject = getAnalysisPropertyByProject(dbSession, SONAR_ANALYSIS_DETECTEDCI);
       Map<String, ProjectAlmKeyAndProject> almAndUrlByProject = getAlmAndUrlByProject(dbSession);
       List<String> projectUuids = dbClient.projectDao().selectAllProjectUuids(dbSession);
 
-      Map<String, PrAndBranchCountByProjectDto> prAndBranchCountByProjects = dbClient.branchDao().countPrAndBranchByProjectUuid(dbSession)
-        .stream().collect(Collectors.toMap(PrAndBranchCountByProjectDto::getProjectUuid, Function.identity()));
+      Map<String, PrBranchAnalyzedLanguageCountByProjectDto> prAndBranchCountByProjects = dbClient.branchDao().countPrBranchAnalyzedLanguageByProjectUuid(dbSession)
+        .stream().collect(Collectors.toMap(PrBranchAnalyzedLanguageCountByProjectDto::getProjectUuid, Function.identity()));
 
+      boolean isCommunityEdition = editionProvider.get().filter(edition -> edition.equals(COMMUNITY)).isPresent();
       List<TelemetryData.ProjectStatistics> projectStatistics = new ArrayList<>();
       for (String projectUuid : projectUuids) {
-        Long branchCount = Optional.ofNullable(prAndBranchCountByProjects.get(projectUuid)).map(PrAndBranchCountByProjectDto::getBranch).orElse(0L);
-        Long pullRequestCount = Optional.ofNullable(prAndBranchCountByProjects.get(projectUuid)).map(PrAndBranchCountByProjectDto::getPullRequest).orElse(0L);
+        Optional<PrBranchAnalyzedLanguageCountByProjectDto> counts = ofNullable(prAndBranchCountByProjects.get(projectUuid));
+
+        Long branchCount = counts.map(PrBranchAnalyzedLanguageCountByProjectDto::getBranch).orElse(0L);
+        Long pullRequestCount = counts.map(PrBranchAnalyzedLanguageCountByProjectDto::getPullRequest).orElse(0L);
+
+        Boolean hasUnanalyzedCMeasures = null;
+        Boolean hasUnanalyzedCppMeasures = null;
+        if (isCommunityEdition) {
+          hasUnanalyzedCMeasures = counts.map(PrBranchAnalyzedLanguageCountByProjectDto::getUnanalyzedCCount).orElse(0L) > 0;
+          hasUnanalyzedCppMeasures = counts.map(PrBranchAnalyzedLanguageCountByProjectDto::getUnanalyzedCppCount).orElse(0L) > 0;
+        }
+
         String scm = Optional.ofNullable(scmByProject.get(projectUuid)).orElse(UNDETECTED);
         String ci = Optional.ofNullable(ciByProject.get(projectUuid)).orElse(UNDETECTED);
         String devopsPlatform = null;
@@ -142,7 +143,8 @@ public class TelemetryDataLoaderImpl implements TelemetryDataLoader {
         }
         devopsPlatform = Optional.ofNullable(devopsPlatform).orElse(UNDETECTED);
 
-        projectStatistics.add(new TelemetryData.ProjectStatistics(projectUuid, branchCount, pullRequestCount, scm, ci, devopsPlatform));
+        projectStatistics.add(
+          new TelemetryData.ProjectStatistics(projectUuid, branchCount, pullRequestCount, hasUnanalyzedCMeasures, hasUnanalyzedCppMeasures, scm, ci, devopsPlatform));
       }
       data.setProjectStatistics(projectStatistics);
 
index 1ef601422d5e547f3b60fb0820354df42bb09857..6af70b31a0b471cfe0cc881215f8a551a16d70b0 100644 (file)
@@ -322,8 +322,9 @@ public class TelemetryDataLoaderImplTest {
 
     TelemetryData data = communityUnderTest.load();
 
-    assertThat(data.hasUnanalyzedC().get()).isTrue();
-    assertThat(data.hasUnanalyzedCpp().get()).isTrue();
+    assertThat(data.getProjectStatistics())
+      .extracting(TelemetryData.ProjectStatistics::hasUnanalyzedC, TelemetryData.ProjectStatistics::hasUnanalyzedCpp)
+      .containsExactlyInAnyOrder(tuple(Optional.of(true), Optional.of(true)), tuple(Optional.of(true), Optional.of(false)));
   }
 
   @Test
@@ -338,18 +339,9 @@ public class TelemetryDataLoaderImplTest {
 
     TelemetryData data = communityUnderTest.load();
 
-    assertThat(data.hasUnanalyzedC()).isEmpty();
-    assertThat(data.hasUnanalyzedCpp()).isEmpty();
-  }
-
-  @Test
-  public void unanalyzed_languages_flags_are_set_to_false_when_no_unanalyzed_languages_and_edition_is_community() {
-    when(editionProvider.get()).thenReturn(Optional.of(COMMUNITY));
-
-    TelemetryData data = communityUnderTest.load();
-
-    assertThat(data.hasUnanalyzedC().get()).isFalse();
-    assertThat(data.hasUnanalyzedCpp().get()).isFalse();
+    assertThat(data.getProjectStatistics())
+      .extracting(TelemetryData.ProjectStatistics::hasUnanalyzedC, TelemetryData.ProjectStatistics::hasUnanalyzedCpp)
+      .containsExactlyInAnyOrder(tuple(Optional.empty(), Optional.empty()), tuple(Optional.empty(), Optional.empty()));
   }
 
   @Test