aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2019-10-15 14:17:57 -0500
committerSonarTech <sonartech@sonarsource.com>2019-10-21 20:21:12 +0200
commitc7a8da830b3c080e6c6234a462b9fac3a04c4363 (patch)
treefef805ff81e0c91a65dfbfd082578a70620d6b46 /sonar-plugin-api
parent7bf35a666c4c577bc8fa72a07b0e06ee7153dc08 (diff)
downloadsonarqube-c7a8da830b3c080e6c6234a462b9fac3a04c4363.tar.gz
sonarqube-c7a8da830b3c080e6c6234a462b9fac3a04c4363.zip
SONAR-12508 Remove RuleRepository and RuleI18n APIs deprecated since 4.2
Diffstat (limited to 'sonar-plugin-api')
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/i18n/RuleI18n.java152
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/rules/RuleRepository.java83
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinitionI18nLoader.java69
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/server/rule/RulesDefinitionI18nLoaderTest.java100
4 files changed, 0 insertions, 404 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/i18n/RuleI18n.java b/sonar-plugin-api/src/main/java/org/sonar/api/i18n/RuleI18n.java
deleted file mode 100644
index c3a9d565659..00000000000
--- a/sonar-plugin-api/src/main/java/org/sonar/api/i18n/RuleI18n.java
+++ /dev/null
@@ -1,152 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2019 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.api.i18n;
-
-import java.util.Locale;
-import javax.annotation.CheckForNull;
-import org.sonar.api.ce.ComputeEngineSide;
-import org.sonar.api.rules.Rule;
-import org.sonar.api.server.ServerSide;
-
-/**
- * {@link I18n}-companion component that provides translation facilities for rule names, descriptions and parameter names.
- *
- * @since 3.2
- * @deprecated in 4.1. Rules are not localized anymore. See http://jira.sonarsource.com/browse/SONAR-4885
- */
-@Deprecated
-@ServerSide
-@ComputeEngineSide
-public interface RuleI18n {
-
- /**
- * Returns the localized name of the rule identified by its repository key and rule key.
- * <br>
- * If the name is not found in the given locale, then the default name is returned (the English one).
- * This method could return null if no default name found. This is the cause for instance the copies rules.
- *
- * @param repositoryKey the repository key
- * @param ruleKey the rule key
- * @param locale not used
- * @return the translated name of the rule, or the default English one if the given locale is not supported, or null
- * @deprecated since 4.1. Rules are not localized anymore. See http://jira.sonarsource.com/browse/SONAR-4885
- */
- @Deprecated
- @CheckForNull
- String getName(String repositoryKey, String ruleKey, Locale locale);
-
- /**
- * Returns the name of the rule identified by its repository key and rule key.
- * <br>
- * This method could return null if no default name found. This is the cause for instance the copies rules.
- *
- * @param repositoryKey the repository key
- * @param ruleKey the rule key
- * @return the nullable name of the rule
- * @since 4.1
- */
- @CheckForNull
- String getName(String repositoryKey, String ruleKey);
-
- /**
- * Returns the localized name or the name of the rule.
- * <br>
- * If the name is not found in the given locale, then the default name is returned (the English one).
- * It the default name is not found, then the rule name is returned.
- *
- * @param rule the rule
- * @param locale the locale to translate into
- * @return the translated name of the rule, or the default English one if the given locale is not supported, or the rule name.
- * @deprecated since 4.1. Rules are not localized anymore. See http://jira.sonarsource.com/browse/SONAR-4885
- */
- @Deprecated
- @CheckForNull
- String getName(Rule rule, Locale locale);
-
- /**
- * Returns the name of the rule.
- * <br>
- * It the default name is not found, then the rule name is returned.
- *
- * @param rule the rule
- * @return the nullable name of the rule
- * @since 4.1
- */
- @CheckForNull
- String getName(Rule rule);
-
- /**
- * Returns the localized description of the rule identified by its repository key and rule key.
- * <br>
- * If the description is not found in the given locale, then the default description is returned (the English one).
- * As a rule must have a description (this is a constraint in Sonar), this method never returns null.
- *
- * @param repositoryKey the repository key
- * @param ruleKey the rule key
- * @param locale the locale to translate into
- * @return the translated description of the rule, or the default English one if the given locale is not supported
- * @deprecated since 4.1. Rules are not localized anymore. See http://jira.sonarsource.com/browse/SONAR-4885
- */
- @Deprecated
- String getDescription(String repositoryKey, String ruleKey, Locale locale);
-
- /**
- * Returns the description of the rule identified by its repository key and rule key.
- * <br>
- * As a rule must have a description (this is a constraint in SonarQube), this method never returns null.
- *
- * @param repositoryKey the repository key
- * @param ruleKey the rule key
- * @return the description of the rule
- * @since 4.1
- */
- String getDescription(String repositoryKey, String ruleKey);
-
- /**
- * Returns the localized name of the rule parameter identified by the rules's key and repository key, and by the parameter key.
- * <br>
- * If the name is not found in the given locale, then the English translation is searched and return if found. Otherwise,
- * this method returns null (= if no translation can be found).
- *
- * @param repositoryKey the repository key
- * @param ruleKey the rule key
- * @param paramKey the parameter key
- * @param locale the locale to translate into
- * @return the translated name of the rule parameter, or the default English one if the given locale is not supported, or null if
- * no translation can be found.
- * @deprecated since 4.1. Rules are not localized anymore. See http://jira.sonarsource.com/browse/SONAR-4885
- */
- @Deprecated
- @CheckForNull
- String getParamDescription(String repositoryKey, String ruleKey, String paramKey, Locale locale);
-
- /**
- * Returns the name of the rule parameter identified by the rules's key and repository key, and by the parameter key.
- *
- * @param repositoryKey the repository key
- * @param ruleKey the rule key
- * @param paramKey the parameter key
- * @return the nullable name of the rule parameter
- * @since 4.1
- */
- @CheckForNull
- String getParamDescription(String repositoryKey, String ruleKey, String paramKey);
-
-}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/rules/RuleRepository.java b/sonar-plugin-api/src/main/java/org/sonar/api/rules/RuleRepository.java
deleted file mode 100644
index d8f35a606c6..00000000000
--- a/sonar-plugin-api/src/main/java/org/sonar/api/rules/RuleRepository.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2019 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.api.rules;
-
-import java.util.List;
-import org.apache.commons.lang.StringUtils;
-import org.apache.commons.lang.builder.ToStringBuilder;
-import org.apache.commons.lang.builder.ToStringStyle;
-import org.sonar.api.ExtensionPoint;
-import org.sonar.api.ce.ComputeEngineSide;
-import org.sonar.api.server.ServerSide;
-
-/**
- * @since 2.3
- * @deprecated in 4.2. Replaced by org.sonar.api.server.rule.RulesDefinition
- */
-@Deprecated
-@ServerSide
-@ComputeEngineSide
-@ExtensionPoint
-public abstract class RuleRepository {
-
- private String key;
- private String language;
- private String name;
-
- protected RuleRepository(String key, String language) {
- this.key = key;
- this.language = language;
- }
-
- public final String getKey() {
- return key;
- }
-
- public final String getLanguage() {
- return language;
- }
-
- public final String getName() {
- return name;
- }
-
- public final String getName(boolean useKeyIfEmpty) {
- if (useKeyIfEmpty) {
- return StringUtils.defaultIfEmpty(name, key);
- }
- return name;
- }
-
- public final RuleRepository setName(String s) {
- this.name = s;
- return this;
- }
-
- public abstract List<Rule> createRules();
-
- @Override
- public String toString() {
- return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
- .append("key", key)
- .append("language", language)
- .append("name", name)
- .toString();
- }
-}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinitionI18nLoader.java b/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinitionI18nLoader.java
deleted file mode 100644
index 6dd1e479d7d..00000000000
--- a/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinitionI18nLoader.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2019 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.api.server.rule;
-
-import org.apache.commons.lang.StringUtils;
-import org.sonar.api.i18n.RuleI18n;
-
-/**
- * Loads the English bundles of rules (name, description and parameters) that are
- * deprecated since 4.2. It can be useful when loading existing XML files that
- * do not contain rule names and descriptions.
- * <br>
- * This class must be executed after declaring rules on {@link RulesDefinition.NewRepository}.
- * <br>
- * Note that localization of rules was dropped in version 4.2. All texts are English.
- *
- * @see org.sonar.api.server.rule.RulesDefinition for an example
- * @since 4.3
- */
-public class RulesDefinitionI18nLoader {
-
- private final RuleI18n i18n;
-
- public RulesDefinitionI18nLoader(RuleI18n i18n) {
- this.i18n = i18n;
- }
-
- /**
- * Loads descriptions of rules and related rule parameters. Existing descriptions
- * are overridden if English labels exist in bundles.
- */
- public void load(RulesDefinition.NewRepository repo) {
- for (RulesDefinition.NewRule rule : repo.rules()) {
- String name = i18n.getName(repo.key(), rule.key());
- if (StringUtils.isNotBlank(name)) {
- rule.setName(name);
- }
-
- String desc = i18n.getDescription(repo.key(), rule.key());
- if (StringUtils.isNotBlank(desc)) {
- rule.setHtmlDescription(desc);
- }
-
- for (RulesDefinition.NewParam param : rule.params()) {
- String paramDesc = i18n.getParamDescription(repo.key(), rule.key(), param.key());
- if (StringUtils.isNotBlank(paramDesc)) {
- param.setDescription(paramDesc);
- }
- }
- }
- }
-}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/server/rule/RulesDefinitionI18nLoaderTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/server/rule/RulesDefinitionI18nLoaderTest.java
deleted file mode 100644
index b92052b19af..00000000000
--- a/sonar-plugin-api/src/test/java/org/sonar/api/server/rule/RulesDefinitionI18nLoaderTest.java
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2019 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.api.server.rule;
-
-import org.junit.Test;
-import org.sonar.api.i18n.RuleI18n;
-import org.sonar.api.impl.server.RulesDefinitionContext;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public class RulesDefinitionI18nLoaderTest {
-
- RuleI18n i18n = mock(RuleI18n.class);
- RulesDefinitionI18nLoader loader = new RulesDefinitionI18nLoader(i18n);
-
- @Test
- public void complete_rule_name_and_description() {
- when(i18n.getName("squid", "S0001")).thenReturn("SOne");
- when(i18n.getDescription("squid", "S0001")).thenReturn("S One");
-
- RulesDefinition.Context context = new RulesDefinitionContext();
- RulesDefinition.NewRepository repo = context.createRepository("squid", "java");
- // rule without description
- repo.createRule("S0001");
-
- loader.load(repo);
- repo.done();
-
- RulesDefinition.Rule rule = context.repository("squid").rule("S0001");
- assertThat(rule.name()).isEqualTo("SOne");
- assertThat(rule.htmlDescription()).isEqualTo("S One");
- }
-
- @Test
- public void do_not_override_if_no_bundle() {
- // i18n returns null values
-
- RulesDefinition.Context context = new RulesDefinitionContext();
- RulesDefinition.NewRepository repo = context.createRepository("squid", "java");
- repo.createRule("S0001").setName("SOne").setHtmlDescription("S One");
-
- loader.load(repo);
- repo.done();
-
- RulesDefinition.Rule rule = context.repository("squid").rule("S0001");
- assertThat(rule.name()).isEqualTo("SOne");
- assertThat(rule.htmlDescription()).isEqualTo("S One");
- }
-
- @Test
- public void override_existing() {
- when(i18n.getName("squid", "S0001")).thenReturn("SOne");
- when(i18n.getDescription("squid", "S0001")).thenReturn("S One");
-
- RulesDefinition.Context context = new RulesDefinitionContext();
- RulesDefinition.NewRepository repo = context.createRepository("squid", "java");
- repo.createRule("S0001").setName("Bad").setHtmlDescription("Bad");
-
- loader.load(repo);
- repo.done();
-
- RulesDefinition.Rule rule = context.repository("squid").rule("S0001");
- assertThat(rule.name()).isEqualTo("SOne");
- assertThat(rule.htmlDescription()).isEqualTo("S One");
- }
-
- @Test
- public void complete_param_description() {
- when(i18n.getParamDescription("squid", "S0001", "max")).thenReturn("Maximum");
-
- RulesDefinition.Context context = new RulesDefinitionContext();
- RulesDefinition.NewRepository repo = context.createRepository("squid", "java");
- repo.createRule("S0001").setName("SOne").setHtmlDescription("S One").createParam("max");
-
- loader.load(repo);
- repo.done();
-
- RulesDefinition.Rule rule = context.repository("squid").rule("S0001");
- assertThat(rule.param("max").description()).isEqualTo("Maximum");
- }
-}