aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-webserver/src/main/java/org/sonar
diff options
context:
space:
mode:
authorEric Giffon <eric.giffon@sonarsource.com>2024-09-17 16:25:13 +0200
committersonartech <sonartech@sonarsource.com>2024-10-09 20:02:46 +0000
commit82225b439672af6d35d463b48001452321459ff4 (patch)
tree3036731e7a7adee7901856a0f453d2d942a5dce4 /server/sonar-webserver/src/main/java/org/sonar
parent0ff9b7313c17474a867f744aa63afd94795a134b (diff)
downloadsonarqube-82225b439672af6d35d463b48001452321459ff4.tar.gz
sonarqube-82225b439672af6d35d463b48001452321459ff4.zip
SONAR-22873 Read JSON measures (#11683)
Co-authored-by: Claire Villard <claire.villard@sonarsource.com>
Diffstat (limited to 'server/sonar-webserver/src/main/java/org/sonar')
-rw-r--r--server/sonar-webserver/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java2
-rw-r--r--server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/TelemetryNclocProvider.java22
2 files changed, 7 insertions, 17 deletions
diff --git a/server/sonar-webserver/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java b/server/sonar-webserver/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java
index 3d0d5cfd82c..95e617507d1 100644
--- a/server/sonar-webserver/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java
+++ b/server/sonar-webserver/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java
@@ -294,6 +294,7 @@ import org.sonar.server.ws.ws.WebServicesWsModule;
import org.sonar.telemetry.TelemetryClient;
import org.sonar.telemetry.TelemetryDaemon;
import org.sonar.telemetry.legacy.CloudUsageDataProvider;
+import org.sonar.telemetry.legacy.ProjectLocDistributionDataProvider;
import org.sonar.telemetry.legacy.QualityProfileDataProvider;
import org.sonar.telemetry.legacy.TelemetryDataJsonWriter;
import org.sonar.telemetry.legacy.TelemetryDataLoaderImpl;
@@ -687,6 +688,7 @@ public class PlatformLevel4 extends PlatformLevel {
TelemetryClient.class,
CloudUsageDataProvider.class,
QualityProfileDataProvider.class,
+ ProjectLocDistributionDataProvider.class,
// monitoring
ServerMonitoringMetrics.class,
diff --git a/server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/TelemetryNclocProvider.java b/server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/TelemetryNclocProvider.java
index 0d93c951d08..d06d2f18bb3 100644
--- a/server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/TelemetryNclocProvider.java
+++ b/server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/TelemetryNclocProvider.java
@@ -26,25 +26,22 @@ import java.util.Map;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.measure.ProjectLocDistributionDto;
-import org.sonar.db.metric.MetricDto;
import org.sonar.telemetry.core.Dimension;
import org.sonar.telemetry.core.Granularity;
import org.sonar.telemetry.core.TelemetryDataProvider;
import org.sonar.telemetry.core.TelemetryDataType;
-
-import static java.util.Arrays.asList;
-import static java.util.stream.Collectors.toMap;
-import static org.sonar.api.measures.CoreMetrics.NCLOC_KEY;
-import static org.sonar.api.measures.CoreMetrics.NCLOC_LANGUAGE_DISTRIBUTION_KEY;
+import org.sonar.telemetry.legacy.ProjectLocDistributionDataProvider;
public class TelemetryNclocProvider implements TelemetryDataProvider<Long> {
public static final String METRIC_KEY = "ncloc_per_language";
private final DbClient dbClient;
+ private final ProjectLocDistributionDataProvider projectLocDistributionDataProvider;
- public TelemetryNclocProvider(DbClient dbClient) {
+ public TelemetryNclocProvider(DbClient dbClient, ProjectLocDistributionDataProvider projectLocDistributionDataProvider) {
this.dbClient = dbClient;
+ this.projectLocDistributionDataProvider = projectLocDistributionDataProvider;
}
@Override
@@ -75,20 +72,11 @@ public class TelemetryNclocProvider implements TelemetryDataProvider<Long> {
}
private Map<String, Long> getNclocDistribution(DbSession dbSession) {
- Map<String, String> metricUuidMap = getNclocMetricUuidMap(dbSession);
- String nclocUuid = metricUuidMap.get(NCLOC_KEY);
- String nclocDistributionUuid = metricUuidMap.get(NCLOC_LANGUAGE_DISTRIBUTION_KEY);
- List<ProjectLocDistributionDto> branchesWithLargestNcloc = dbClient.liveMeasureDao().selectLargestBranchesLocDistribution(dbSession, nclocUuid, nclocDistributionUuid);
+ List<ProjectLocDistributionDto> branchesWithLargestNcloc = projectLocDistributionDataProvider.getProjectLocDistribution(dbSession);
List<LanguageDistribution> languageDistributions = getLanguageDistributionList(branchesWithLargestNcloc);
return getNclocDistributionPerLanguage(languageDistributions);
}
- private Map<String, String> getNclocMetricUuidMap(DbSession dbSession) {
- return dbClient.metricDao().selectByKeys(dbSession, asList(NCLOC_KEY, NCLOC_LANGUAGE_DISTRIBUTION_KEY))
- .stream()
- .collect(toMap(MetricDto::getKey, MetricDto::getUuid));
- }
-
private static List<LanguageDistribution> getLanguageDistributionList(List<ProjectLocDistributionDto> branchesWithLargestNcloc) {
return branchesWithLargestNcloc.stream()
.flatMap(measure -> Arrays.stream(measure.locDistribution().split(";"))