testImplementation 'com.github.spotbugs:spotbugs-annotations'
testImplementation 'com.tngtech.java:junit-dataprovider'
testImplementation 'org.junit.jupiter:junit-jupiter-api'
+ testImplementation 'org.junit.jupiter:junit-jupiter-params'
testImplementation 'org.mockito:mockito-core'
testImplementation 'org.eclipse.jetty:jetty-server'
testImplementation 'org.eclipse.jetty:jetty-servlet'
import org.sonar.core.documentation.DefaultDocumentationLinkGenerator;
import org.sonar.core.extension.CoreExtensionsInstaller;
import org.sonar.core.language.LanguagesProvider;
+import org.sonar.core.metric.SoftwareQualitiesMetrics;
import org.sonar.core.platform.PlatformEditionProvider;
import org.sonar.core.platform.SpringComponentContainer;
import org.sonar.server.almintegration.ws.AlmIntegrationsWSModule;
import org.sonar.server.measure.live.LiveMeasureModule;
import org.sonar.server.measure.ws.MeasuresWsModule;
import org.sonar.server.metric.IssueCountMetrics;
-import org.sonar.core.metric.SoftwareQualitiesMetrics;
import org.sonar.server.metric.UnanalyzedLanguageMetrics;
import org.sonar.server.metric.ws.MetricsWsModule;
import org.sonar.server.monitoring.ComputeEngineMetricStatusTask;
import org.sonar.server.platform.WebCoreExtensionsInstaller;
import org.sonar.server.platform.db.CheckAnyonePermissionsAtStartup;
import org.sonar.server.platform.telemetry.ProjectCppAutoconfigTelemetryProvider;
-import org.sonar.server.platform.telemetry.TelemetryFipsEnabledProvider;
+import org.sonar.server.platform.telemetry.TelemetryLegacyModePropertyProvider;
import org.sonar.server.platform.telemetry.TelemetryNclocProvider;
import org.sonar.server.platform.telemetry.TelemetryUserEnabledProvider;
import org.sonar.server.platform.telemetry.TelemetryVersionProvider;
// new telemetry metrics
ProjectCppAutoconfigTelemetryProvider.class,
TelemetryVersionProvider.class,
+ TelemetryLegacyModePropertyProvider.class,
TelemetryNclocProvider.class,
TelemetryUserEnabledProvider.class,
TelemetryFipsEnabledProvider.class,
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2024 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.server.platform.telemetry;
+
+import java.util.Optional;
+import org.sonar.db.DbClient;
+import org.sonar.db.property.PropertyDto;
+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 org.sonar.core.config.LegacyRatingConstants.LEGACY_RATING_MODE_ENABLED;
+import static org.sonar.telemetry.core.Dimension.INSTALLATION;
+import static org.sonar.telemetry.core.Granularity.WEEKLY;
+import static org.sonar.telemetry.core.TelemetryDataType.BOOLEAN;
+
+public class TelemetryLegacyModePropertyProvider implements TelemetryDataProvider<Boolean> {
+ private final DbClient dbClient;
+
+ public TelemetryLegacyModePropertyProvider(DbClient dbClient) {
+ this.dbClient = dbClient;
+ }
+
+ @Override
+ public String getMetricKey() {
+ return "legacy_rating_mode_enabled";
+ }
+
+ @Override
+ public Dimension getDimension() {
+ return INSTALLATION;
+ }
+
+ @Override
+ public Granularity getGranularity() {
+ return WEEKLY;
+ }
+
+ @Override
+ public TelemetryDataType getType() {
+ return BOOLEAN;
+ }
+
+ @Override
+ public Optional<Boolean> getValue() {
+ PropertyDto property = dbClient.propertiesDao().selectGlobalProperty(LEGACY_RATING_MODE_ENABLED);
+ return property == null ? Optional.of(false) : Optional.of(Boolean.valueOf(property.getValue()));
+ }
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2024 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.server.platform.telemetry;
+
+import java.util.Optional;
+import java.util.stream.Stream;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+import org.sonar.db.DbClient;
+import org.sonar.db.property.PropertiesDao;
+import org.sonar.db.property.PropertyDto;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import static org.sonar.core.config.LegacyRatingConstants.LEGACY_RATING_MODE_ENABLED;
+import static org.sonar.telemetry.core.Dimension.INSTALLATION;
+import static org.sonar.telemetry.core.Granularity.WEEKLY;
+import static org.sonar.telemetry.core.TelemetryDataType.BOOLEAN;
+
+class TelemetryLegacyModePropertyProviderTest {
+ private final DbClient dbClient = mock();
+ private final PropertiesDao propertiesDao = mock();
+ private final TelemetryLegacyModePropertyProvider underTest = new TelemetryLegacyModePropertyProvider(dbClient);
+
+ @ParameterizedTest
+ @MethodSource("getValues")
+ void getter_should_return_correct_values(Boolean value, Boolean expected) {
+ when(dbClient.propertiesDao()).thenReturn(propertiesDao);
+ if (value == null) {
+ when(dbClient.propertiesDao().selectGlobalProperty(LEGACY_RATING_MODE_ENABLED))
+ .thenReturn(null);
+ } else {
+ when(dbClient.propertiesDao().selectGlobalProperty(LEGACY_RATING_MODE_ENABLED))
+ .thenReturn(new PropertyDto().setValue(value.toString()));
+ }
+
+ assertEquals("legacy_rating_mode_enabled", underTest.getMetricKey());
+ assertEquals(INSTALLATION, underTest.getDimension());
+ assertEquals(WEEKLY, underTest.getGranularity());
+ assertEquals(BOOLEAN, underTest.getType());
+ assertEquals(Optional.of(expected), underTest.getValue());
+ }
+
+ public static Stream<Arguments> getValues() {
+ return Stream.of(
+ Arguments.of(true, true),
+ Arguments.of(false, false),
+ Arguments.of(null, false)
+ );
+ }
+
+}