diff options
author | alain <108417558+alain-kermis-sonarsource@users.noreply.github.com> | 2023-01-11 15:29:35 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2023-01-11 20:02:58 +0000 |
commit | 4955c9ec4f08234d1bce4cb8f57b90d8e3085b41 (patch) | |
tree | e7e9e468a896db1b7960f92af677431c8860040e /server | |
parent | 7ed9f7881eb8b53fa6343609267aaca8e0f0e970 (diff) | |
download | sonarqube-4955c9ec4f08234d1bce4cb8f57b90d8e3085b41.tar.gz sonarqube-4955c9ec4f08234d1bce4cb8f57b90d8e3085b41.zip |
SONAR-18164 Deprecate language specific parameters
Diffstat (limited to 'server')
3 files changed, 139 insertions, 0 deletions
diff --git a/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/db/CheckLanguageSpecificParamsAtStartup.java b/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/db/CheckLanguageSpecificParamsAtStartup.java new file mode 100644 index 00000000000..a3daa848af5 --- /dev/null +++ b/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/db/CheckLanguageSpecificParamsAtStartup.java @@ -0,0 +1,57 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.db; + +import org.sonar.api.Startable; +import org.sonar.api.config.Configuration; +import org.sonar.api.utils.log.Logger; +import org.sonar.api.utils.log.Loggers; + +import static org.sonar.api.CoreProperties.LANGUAGE_SPECIFIC_PARAMETERS; + +/** + * Checks if there are any language specific parameters set for calculating technical debt as functionality is deprecated from 9.9. + * If found, it is logged as a warning. This requires to be defined in platform level 4 ({@link org.sonar.server.platform.platformlevel.PlatformLevel4}). + */ +public class CheckLanguageSpecificParamsAtStartup implements Startable { + + private static final Logger LOG = Loggers.get(CheckLanguageSpecificParamsAtStartup.class); + + private final Configuration config; + + public CheckLanguageSpecificParamsAtStartup(Configuration config) { + this.config = config; + } + + @Override + public void start() { + String[] languageSpecificParams = config.getStringArray(LANGUAGE_SPECIFIC_PARAMETERS); + if (languageSpecificParams.length > 0) { + LOG.warn("The development cost used for calculating the technical debt is currently configured with {} language specific parameters [Key: languageSpecificParameters]. " + + "Please be aware that this functionality is deprecated, and will be removed in a future version.", languageSpecificParams.length); + } + } + + @Override + public void stop() { + // do nothing + } + +} diff --git a/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/db/CheckLanguageSpecificParamsAtStartupTest.java b/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/db/CheckLanguageSpecificParamsAtStartupTest.java new file mode 100644 index 00000000000..24fc0b08b38 --- /dev/null +++ b/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/db/CheckLanguageSpecificParamsAtStartupTest.java @@ -0,0 +1,80 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.db; + +import org.junit.After; +import org.junit.ClassRule; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.api.CoreProperties; +import org.sonar.api.config.internal.MapSettings; +import org.sonar.api.measures.CoreMetrics; +import org.sonar.api.utils.System2; +import org.sonar.api.utils.log.LogTester; +import org.sonar.api.utils.log.LoggerLevel; +import org.sonar.db.DbTester; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.sonar.api.CoreProperties.LANGUAGE_SPECIFIC_PARAMETERS; +import static org.sonar.api.CoreProperties.LANGUAGE_SPECIFIC_PARAMETERS_LANGUAGE_KEY; +import static org.sonar.api.CoreProperties.LANGUAGE_SPECIFIC_PARAMETERS_MAN_DAYS_KEY; + +public class CheckLanguageSpecificParamsAtStartupTest { + + @ClassRule + public static LogTester logTester = new LogTester().setLevel(LoggerLevel.WARN); + @Rule + public final DbTester dbTester = DbTester.create(System2.INSTANCE); + private final MapSettings settings = new MapSettings(); + private final CheckLanguageSpecificParamsAtStartup underTest = new CheckLanguageSpecificParamsAtStartup(settings.asConfig()); + + @After + public void tearDown() { + logTester.clear(); + underTest.stop(); + } + + @Test + public void log_shows_when_language_specific_params_used() { + String aLanguage = "aLanguage"; + String anotherLanguage = "anotherLanguage"; + settings.setProperty(LANGUAGE_SPECIFIC_PARAMETERS, "0,1"); + settings.setProperty(LANGUAGE_SPECIFIC_PARAMETERS + "." + "0" + "." + LANGUAGE_SPECIFIC_PARAMETERS_LANGUAGE_KEY, aLanguage); + settings.setProperty(LANGUAGE_SPECIFIC_PARAMETERS + "." + "0" + "." + LANGUAGE_SPECIFIC_PARAMETERS_MAN_DAYS_KEY, "30"); + settings.setProperty(LANGUAGE_SPECIFIC_PARAMETERS + "." + "0" + "." + CoreProperties.LANGUAGE_SPECIFIC_PARAMETERS_SIZE_METRIC_KEY, CoreMetrics.NCLOC_KEY); + settings.setProperty(LANGUAGE_SPECIFIC_PARAMETERS + "." + "1" + "." + LANGUAGE_SPECIFIC_PARAMETERS_LANGUAGE_KEY, anotherLanguage); + settings.setProperty(LANGUAGE_SPECIFIC_PARAMETERS + "." + "1" + "." + LANGUAGE_SPECIFIC_PARAMETERS_MAN_DAYS_KEY, "40"); + settings.setProperty(LANGUAGE_SPECIFIC_PARAMETERS + "." + "1" + "." + CoreProperties.LANGUAGE_SPECIFIC_PARAMETERS_SIZE_METRIC_KEY, CoreMetrics.COMPLEXITY_KEY); + + underTest.start(); + assertThat(logTester.logs(LoggerLevel.WARN)) + .contains("The development cost used for calculating the technical debt is currently configured with 2 language specific parameters [Key: languageSpecificParameters]. " + + "Please be aware that this functionality is deprecated, and will be removed in a future version."); + } + + @Test + public void log_does_not_show_when_language_specific_params_used() { + underTest.start(); + boolean noneMatch = logTester.logs(LoggerLevel.WARN).stream() + .noneMatch(s -> s.startsWith("The development cost used for calculating the technical debt is currently configured with")); + assertThat(noneMatch).isTrue(); + } + +} 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 8a869609e7a..907d46b4533 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 @@ -157,6 +157,7 @@ import org.sonar.server.platform.PersistentSettings; import org.sonar.server.platform.SystemInfoWriterModule; import org.sonar.server.platform.WebCoreExtensionsInstaller; import org.sonar.server.platform.db.CheckAnyonePermissionsAtStartup; +import org.sonar.server.platform.db.CheckLanguageSpecificParamsAtStartup; import org.sonar.server.platform.web.SonarLintConnectionFilter; import org.sonar.server.platform.web.WebServiceFilter; import org.sonar.server.platform.web.WebServiceReroutingFilter; @@ -416,6 +417,7 @@ public class PlatformLevel4 extends PlatformLevel { UserPermissionChanger.class, GroupPermissionChanger.class, CheckAnyonePermissionsAtStartup.class, + CheckLanguageSpecificParamsAtStartup.class, // components new BranchWsModule(), |