aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-webserver-core
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2020-09-23 12:12:44 +0200
committersonartech <sonartech@sonarsource.com>2020-09-29 20:07:42 +0000
commitbc413ee3db73258a22059816bd4766bcea66a9ca (patch)
treeecddd838b51eb476390852e62d50ddd16fcf562b /server/sonar-webserver-core
parent27282ea04940d30eb33c20a02989a79d88dec4a0 (diff)
downloadsonarqube-bc413ee3db73258a22059816bd4766bcea66a9ca.tar.gz
sonarqube-bc413ee3db73258a22059816bd4766bcea66a9ca.zip
SONAR-13869 Add a flag in telemetry to know if there's some c/c++ unanalyzed code
* SONAR-13869 Compute number of unanalyzed C and C++ files measures * SONAR-13869 Send unanalyzed C and C++ flags in Telemetry
Diffstat (limited to 'server/sonar-webserver-core')
-rw-r--r--server/sonar-webserver-core/src/main/java/org/sonar/server/telemetry/TelemetryDataLoaderImpl.java16
-rw-r--r--server/sonar-webserver-core/src/test/java/org/sonar/server/platform/StandaloneSystemInfoWriterTest.java4
-rw-r--r--server/sonar-webserver-core/src/test/java/org/sonar/server/telemetry/TelemetryDataLoaderImplTest.java46
3 files changed, 60 insertions, 6 deletions
diff --git a/server/sonar-webserver-core/src/main/java/org/sonar/server/telemetry/TelemetryDataLoaderImpl.java b/server/sonar-webserver-core/src/main/java/org/sonar/server/telemetry/TelemetryDataLoaderImpl.java
index f96c101fcd5..0eda7898f94 100644
--- a/server/sonar-webserver-core/src/main/java/org/sonar/server/telemetry/TelemetryDataLoaderImpl.java
+++ b/server/sonar-webserver-core/src/main/java/org/sonar/server/telemetry/TelemetryDataLoaderImpl.java
@@ -46,6 +46,9 @@ import org.sonar.server.user.index.UserIndex;
import org.sonar.server.user.index.UserQuery;
import static java.util.Optional.ofNullable;
+import static org.sonar.core.platform.EditionProvider.Edition.COMMUNITY;
+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 {
@@ -115,12 +118,17 @@ public class TelemetryDataLoaderImpl implements TelemetryDataLoader {
.setOrganizationUuid(defaultOrganizationProvider.get().getUuid())
.build();
data.setNcloc(dbClient.liveMeasureDao().sumNclocOfBiggestBranch(dbSession, query));
+ 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);
+ });
}
-
Optional<String> installationDateProperty = internalProperties.read(InternalProperties.INSTALLATION_DATE);
- if (installationDateProperty.isPresent()) {
- data.setInstallationDate(Long.valueOf(installationDateProperty.get()));
- }
+ installationDateProperty.ifPresent(s -> data.setInstallationDate(Long.valueOf(s)));
Optional<String> installationVersionProperty = internalProperties.read(InternalProperties.INSTALLATION_VERSION);
data.setInstallationVersion(installationVersionProperty.orElse(null));
data.setInDocker(dockerSupport.isRunningInDocker());
diff --git a/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/StandaloneSystemInfoWriterTest.java b/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/StandaloneSystemInfoWriterTest.java
index 76c98042a86..d16fde70ce3 100644
--- a/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/StandaloneSystemInfoWriterTest.java
+++ b/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/StandaloneSystemInfoWriterTest.java
@@ -26,10 +26,10 @@ import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.mockito.Mockito;
import org.sonar.api.utils.text.JsonWriter;
-import org.sonar.server.ce.http.CeHttpClient;
-import org.sonar.server.ce.http.CeHttpClientImpl;
import org.sonar.process.systeminfo.SystemInfoSection;
import org.sonar.process.systeminfo.protobuf.ProtobufSystemInfo;
+import org.sonar.server.ce.http.CeHttpClient;
+import org.sonar.server.ce.http.CeHttpClientImpl;
import org.sonar.server.health.TestStandaloneHealthChecker;
import org.sonar.server.telemetry.TelemetryDataJsonWriter;
import org.sonar.server.telemetry.TelemetryDataLoader;
diff --git a/server/sonar-webserver-core/src/test/java/org/sonar/server/telemetry/TelemetryDataLoaderImplTest.java b/server/sonar-webserver-core/src/test/java/org/sonar/server/telemetry/TelemetryDataLoaderImplTest.java
index d753969dd6f..6d62af2a617 100644
--- a/server/sonar-webserver-core/src/test/java/org/sonar/server/telemetry/TelemetryDataLoaderImplTest.java
+++ b/server/sonar-webserver-core/src/test/java/org/sonar/server/telemetry/TelemetryDataLoaderImplTest.java
@@ -58,9 +58,12 @@ import static org.sonar.api.measures.CoreMetrics.COVERAGE_KEY;
import static org.sonar.api.measures.CoreMetrics.LINES_KEY;
import static org.sonar.api.measures.CoreMetrics.NCLOC_KEY;
import static org.sonar.api.measures.CoreMetrics.NCLOC_LANGUAGE_DISTRIBUTION_KEY;
+import static org.sonar.core.platform.EditionProvider.Edition.COMMUNITY;
import static org.sonar.core.platform.EditionProvider.Edition.DEVELOPER;
import static org.sonar.db.component.BranchType.BRANCH;
import static org.sonar.db.component.BranchType.PULL_REQUEST;
+import static org.sonar.server.metric.UnanalyzedLanguageMetrics.UNANALYZED_CPP_KEY;
+import static org.sonar.server.metric.UnanalyzedLanguageMetrics.UNANALYZED_C_KEY;
public class TelemetryDataLoaderImplTest {
@Rule
@@ -229,6 +232,49 @@ public class TelemetryDataLoaderImplTest {
assertThat(data.getInstallationVersion()).isNull();
}
+ @Test
+ public void send_unanalyzed_languages_flags_when_edition_is_community() {
+ when(editionProvider.get()).thenReturn(Optional.of(COMMUNITY));
+ MetricDto unanalyzedC = db.measures().insertMetric(m -> m.setKey(UNANALYZED_C_KEY));
+ MetricDto unanalyzedCpp = db.measures().insertMetric(m -> m.setKey(UNANALYZED_CPP_KEY));
+ ComponentDto project1 = db.components().insertPublicProject();
+ ComponentDto project2 = db.components().insertPublicProject();
+ db.measures().insertLiveMeasure(project1, unanalyzedC);
+ db.measures().insertLiveMeasure(project2, unanalyzedC);
+ db.measures().insertLiveMeasure(project2, unanalyzedCpp);
+
+ TelemetryData data = communityUnderTest.load();
+
+ assertThat(data.hasUnanalyzedC().get()).isTrue();
+ assertThat(data.hasUnanalyzedCpp().get()).isTrue();
+ }
+
+ @Test
+ public void do_not_send_unanalyzed_languages_flags_when_edition_is_not_community() {
+ when(editionProvider.get()).thenReturn(Optional.of(DEVELOPER));
+ MetricDto unanalyzedC = db.measures().insertMetric(m -> m.setKey(UNANALYZED_C_KEY));
+ MetricDto unanalyzedCpp = db.measures().insertMetric(m -> m.setKey(UNANALYZED_CPP_KEY));
+ ComponentDto project1 = db.components().insertPublicProject();
+ ComponentDto project2 = db.components().insertPublicProject();
+ db.measures().insertLiveMeasure(project1, unanalyzedC);
+ db.measures().insertLiveMeasure(project2, unanalyzedCpp);
+
+ 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();
+ }
+
private PluginInfo newPlugin(String key, String version) {
return new PluginInfo(key)
.setVersion(Version.create(version));