diff options
author | Duarte Meneses <duarte.meneses@sonarsource.com> | 2021-06-09 16:26:56 -0500 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2021-06-17 20:03:08 +0000 |
commit | 2754feca4e5fa8fdd804c827783250f48676296c (patch) | |
tree | 1ed9522bbc9eff9444fae6bf0a951d976da2b859 /server/sonar-webserver-auth | |
parent | 97f2c01fdd4ae863134d4aa1bf32b7dcd512b10c (diff) | |
download | sonarqube-2754feca4e5fa8fdd804c827783250f48676296c.tar.gz sonarqube-2754feca4e5fa8fdd804c827783250f48676296c.zip |
SONAR-14925 Remove code deprecated before 7.0 in the Plugin API
Diffstat (limited to 'server/sonar-webserver-auth')
2 files changed, 0 insertions, 197 deletions
diff --git a/server/sonar-webserver-auth/src/main/java/org/sonar/server/qualityprofile/BuiltInQProfileDefinitionsBridge.java b/server/sonar-webserver-auth/src/main/java/org/sonar/server/qualityprofile/BuiltInQProfileDefinitionsBridge.java deleted file mode 100644 index 525b1cbefc6..00000000000 --- a/server/sonar-webserver-auth/src/main/java/org/sonar/server/qualityprofile/BuiltInQProfileDefinitionsBridge.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2021 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.qualityprofile; - -import com.google.common.collect.ImmutableList; -import java.util.List; -import org.sonar.api.profiles.ProfileDefinition; -import org.sonar.api.profiles.RulesProfile; -import org.sonar.api.rules.ActiveRuleParam; -import org.sonar.api.rules.RulePriority; -import org.sonar.api.server.profile.BuiltInQualityProfilesDefinition; -import org.sonar.api.utils.ValidationMessages; -import org.sonar.api.utils.log.Logger; -import org.sonar.api.utils.log.Loggers; -import org.sonar.api.utils.log.Profiler; - -import static java.lang.String.format; - -/** - * Bridge between deprecated {@link ProfileDefinition} API and new {@link BuiltInQualityProfilesDefinition} - */ -public class BuiltInQProfileDefinitionsBridge implements BuiltInQualityProfilesDefinition { - private static final Logger LOGGER = Loggers.get(BuiltInQProfileDefinitionsBridge.class); - - private final List<ProfileDefinition> definitions; - - /** - * Requires for pico container when no {@link ProfileDefinition} is defined at all - */ - public BuiltInQProfileDefinitionsBridge() { - this(new ProfileDefinition[0]); - } - - public BuiltInQProfileDefinitionsBridge(ProfileDefinition... definitions) { - this.definitions = ImmutableList.copyOf(definitions); - } - - @Override - public void define(Context context) { - Profiler profiler = Profiler.create(Loggers.get(getClass())); - for (ProfileDefinition definition : definitions) { - profiler.start(); - ValidationMessages validation = ValidationMessages.create(); - RulesProfile profile = definition.createProfile(validation); - validation.log(LOGGER); - if (profile == null) { - profiler.stopDebug(format("Loaded definition %s that return no profile", definition)); - } else { - if (!validation.hasErrors()) { - define(context, profile); - } - profiler.stopDebug(format("Loaded deprecated profile definition %s for language %s", profile.getName(), profile.getLanguage())); - } - } - } - - private static void define(Context context, RulesProfile profile) { - NewBuiltInQualityProfile newQp = context.createBuiltInQualityProfile(profile.getName(), profile.getLanguage()) - .setDefault(profile.getDefaultProfile()); - - for (org.sonar.api.rules.ActiveRule ar : profile.getActiveRules()) { - NewBuiltInActiveRule newActiveRule = newQp.activateRule(ar.getRepositoryKey(), ar.getRuleKey()); - RulePriority overriddenSeverity = ar.getOverriddenSeverity(); - if (overriddenSeverity != null) { - newActiveRule.overrideSeverity(overriddenSeverity.name()); - } - for (ActiveRuleParam param : ar.getActiveRuleParams()) { - newActiveRule.overrideParam(param.getKey(), param.getValue()); - } - } - newQp.done(); - } - -} diff --git a/server/sonar-webserver-auth/src/test/java/org/sonar/server/qualityprofile/BuiltInQProfileDefinitionsBridgeTest.java b/server/sonar-webserver-auth/src/test/java/org/sonar/server/qualityprofile/BuiltInQProfileDefinitionsBridgeTest.java deleted file mode 100644 index 476fcb45c07..00000000000 --- a/server/sonar-webserver-auth/src/test/java/org/sonar/server/qualityprofile/BuiltInQProfileDefinitionsBridgeTest.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2021 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.qualityprofile; - -import java.util.Arrays; -import org.junit.Test; -import org.sonar.api.profiles.ProfileDefinition; -import org.sonar.api.profiles.RulesProfile; -import org.sonar.api.rule.RuleKey; -import org.sonar.api.rule.Severity; -import org.sonar.api.rules.ActiveRule; -import org.sonar.api.rules.Rule; -import org.sonar.api.rules.RuleParam; -import org.sonar.api.rules.RulePriority; -import org.sonar.api.server.profile.BuiltInQualityProfilesDefinition; -import org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.BuiltInActiveRule; -import org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.BuiltInQualityProfile; -import org.sonar.api.utils.ValidationMessages; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.groups.Tuple.tuple; - -public class BuiltInQProfileDefinitionsBridgeTest { - - @Test - public void noProfileDefinitions() { - BuiltInQProfileDefinitionsBridge bridge = new BuiltInQProfileDefinitionsBridge(); - - BuiltInQualityProfilesDefinition.Context context = new BuiltInQualityProfilesDefinition.Context(); - bridge.define(context); - - assertThat(context.profilesByLanguageAndName()).isEmpty(); - } - - @Test - public void bridgeProfileDefinitions() { - BuiltInQProfileDefinitionsBridge bridge = new BuiltInQProfileDefinitionsBridge(new Profile1(), new NullProfile(), new ProfileWithError()); - - BuiltInQualityProfilesDefinition.Context context = new BuiltInQualityProfilesDefinition.Context(); - bridge.define(context); - - assertThat(context.profilesByLanguageAndName()).hasSize(1); - assertThat(context.profilesByLanguageAndName().get("xoo")).hasSize(1); - - BuiltInQualityProfile profile1 = context.profile("xoo", "Profile 1"); - assertThat(profile1).isNotNull(); - assertThat(profile1.rules()).hasSize(3); - BuiltInActiveRule defaultSeverity = profile1.rule(RuleKey.of("repo1", "defaultSeverity")); - assertThat(defaultSeverity).isNotNull(); - assertThat(defaultSeverity.overriddenSeverity()).isNull(); - assertThat(defaultSeverity.overriddenParams()).isEmpty(); - - assertThat(profile1.rule(RuleKey.of("repo1", "overrideSeverity")).overriddenSeverity()).isEqualTo(Severity.CRITICAL); - - assertThat(profile1.rule(RuleKey.of("repo1", "overrideParam")).overriddenParams()) - .extracting(BuiltInQualityProfilesDefinition.OverriddenParam::key, BuiltInQualityProfilesDefinition.OverriddenParam::overriddenValue).containsOnly(tuple("param", "value")); - } - - private static class Profile1 extends ProfileDefinition { - @Override - public RulesProfile createProfile(ValidationMessages validation) { - RulesProfile profile1 = RulesProfile.create("Profile 1", "xoo"); - - profile1.activateRule(Rule.create("repo1", "defaultSeverity"), null); - profile1.activateRule(Rule.create("repo1", "overrideSeverity"), RulePriority.CRITICAL); - Rule ruleWithParam = Rule.create("repo1", "overrideParam"); - ruleWithParam.setParams(Arrays.asList(new RuleParam(ruleWithParam, "param", "", ""))); - ActiveRule arWithParam = profile1.activateRule(ruleWithParam, null); - arWithParam.setParameter("param", "value"); - - return profile1; - } - } - - private static class NullProfile extends ProfileDefinition { - @Override - public RulesProfile createProfile(ValidationMessages validation) { - return null; - } - } - - private static class ProfileWithError extends ProfileDefinition { - @Override - public RulesProfile createProfile(ValidationMessages validation) { - validation.addErrorText("Foo"); - return RulesProfile.create("Profile with errors", "xoo"); - } - } -} |