diff options
author | alain <108417558+alain-kermis-sonarsource@users.noreply.github.com> | 2022-09-28 14:29:30 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2022-09-28 20:04:08 +0000 |
commit | 98aa88962583e2e8f59a5dd110aaa980282e6fe5 (patch) | |
tree | 05debe672be885aa58a100ace56162c4fc68a89a /server/sonar-server-common | |
parent | bb10a3475add71296daadd37480798d7f961e6ec (diff) | |
download | sonarqube-98aa88962583e2e8f59a5dd110aaa980282e6fe5.tar.gz sonarqube-98aa88962583e2e8f59a5dd110aaa980282e6fe5.zip |
SONAR-17195 Move unanalyzed language flags to project level for telemetry
Diffstat (limited to 'server/sonar-server-common')
3 files changed, 39 insertions, 50 deletions
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/telemetry/TelemetryData.java b/server/sonar-server-common/src/main/java/org/sonar/server/telemetry/TelemetryData.java index 09b2c1ee5a1..d8caa44576c 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/telemetry/TelemetryData.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/telemetry/TelemetryData.java @@ -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); + } } } diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/telemetry/TelemetryDataJsonWriter.java b/server/sonar-server-common/src/main/java/org/sonar/server/telemetry/TelemetryDataJsonWriter.java index c6ab6177ff8..8af18b0e16e 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/telemetry/TelemetryDataJsonWriter.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/telemetry/TelemetryDataJsonWriter.java @@ -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(); diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/telemetry/TelemetryDataJsonWriterTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/telemetry/TelemetryDataJsonWriterTest.java index 4d6d482f62d..6bc9a0c35fe 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/telemetry/TelemetryDataJsonWriterTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/telemetry/TelemetryDataJsonWriterTest.java @@ -230,21 +230,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 .setCustomSecurityConfigs(Arrays.asList("php", "java")) @@ -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()); } |