From 74c4ac9a4a5c9df13116862dd5dca982cc3f84bd Mon Sep 17 00:00:00 2001 From: Godin Date: Wed, 8 Dec 2010 13:45:25 +0000 Subject: [PATCH] Deprecate Rule.setPluginName() , Rule.getPluginName() and related stuff, because was replaced by repositoryKey --- .../core/sensors/ViolationsDecoratorTest.java | 6 +-- .../NewViolationsDecoratorTest.java | 6 +-- .../main/java/org/sonar/jpa/dao/RulesDao.java | 16 ++++--- .../org/sonar/api/profiles/RulesProfile.java | 19 ++++---- .../java/org/sonar/api/rules/ActiveRule.java | 11 ++--- .../main/java/org/sonar/api/rules/Rule.java | 43 +++++++++++-------- 6 files changed, 56 insertions(+), 45 deletions(-) diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ViolationsDecoratorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ViolationsDecoratorTest.java index 1abffdfb8f3..6670ae97e41 100644 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ViolationsDecoratorTest.java +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ViolationsDecoratorTest.java @@ -50,9 +50,9 @@ public class ViolationsDecoratorTest { @Before public void before() { - ruleA1 = Rule.create().setPluginName("ruleA1").setKey("ruleA1").setName("nameA1"); - ruleA2 = Rule.create().setPluginName("ruleA2").setKey("ruleA2").setName("nameA2"); - ruleB1 = Rule.create().setPluginName("ruleB1").setKey("ruleB1").setName("nameB1"); + ruleA1 = Rule.create().setRepositoryKey("ruleA1").setKey("ruleA1").setName("nameA1"); + ruleA2 = Rule.create().setRepositoryKey("ruleA2").setKey("ruleA2").setName("nameA2"); + ruleB1 = Rule.create().setRepositoryKey("ruleB1").setKey("ruleB1").setName("nameB1"); decorator = new ViolationsDecorator(); resource = mock(Resource.class); diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/NewViolationsDecoratorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/NewViolationsDecoratorTest.java index 84bd2b100eb..34e6963a642 100644 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/NewViolationsDecoratorTest.java +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/NewViolationsDecoratorTest.java @@ -82,9 +82,9 @@ public class NewViolationsDecoratorTest { decorator = new NewViolationsDecorator(timeMachineConfiguration); - rule1 = Rule.create().setPluginName("rule1").setKey("rule1").setName("name1"); - rule2 = Rule.create().setPluginName("rule2").setKey("rule2").setName("name2"); - rule3 = Rule.create().setPluginName("rule3").setKey("rule3").setName("name3"); + rule1 = Rule.create().setRepositoryKey("rule1").setKey("rule1").setName("name1"); + rule2 = Rule.create().setRepositoryKey("rule2").setKey("rule2").setName("name2"); + rule3 = Rule.create().setRepositoryKey("rule3").setKey("rule3").setName("name3"); } @Test diff --git a/sonar-core/src/main/java/org/sonar/jpa/dao/RulesDao.java b/sonar-core/src/main/java/org/sonar/jpa/dao/RulesDao.java index 736d977ac30..8cb5151c7f5 100644 --- a/sonar-core/src/main/java/org/sonar/jpa/dao/RulesDao.java +++ b/sonar-core/src/main/java/org/sonar/jpa/dao/RulesDao.java @@ -41,13 +41,20 @@ public class RulesDao extends BaseDao { return getSession().getResults(Rule.class, "enabled", true); } - public List getRulesByPlugin(String pluginKey) { - return getSession().getResults(Rule.class, "pluginName", pluginKey, "enabled", true); + public List getRulesByRepository(String repositoryKey) { + return getSession().getResults(Rule.class, "pluginName", repositoryKey, "enabled", true); } + /** + * @deprecated since 2.5 use {@link #getRulesByRepository(String)} instead. + */ + @Deprecated + public List getRulesByPlugin(String pluginKey) { + return getRulesByRepository(pluginKey); + } - public Rule getRuleByKey(String pluginKey, String ruleKey) { - return getSession().getSingleResult(Rule.class, "key", ruleKey, "pluginName", pluginKey, "enabled", true); + public Rule getRuleByKey(String repositoryKey, String ruleKey) { + return getSession().getSingleResult(Rule.class, "key", ruleKey, "pluginName", repositoryKey, "enabled", true); } public Long countRules(List plugins) { @@ -57,7 +64,6 @@ public class RulesDao extends BaseDao { getSingleResult(); } - public List getRuleParams() { return getSession().getResults(RuleParam.class); } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/profiles/RulesProfile.java b/sonar-plugin-api/src/main/java/org/sonar/api/profiles/RulesProfile.java index 01d91243bbb..895bea88eba 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/profiles/RulesProfile.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/profiles/RulesProfile.java @@ -29,14 +29,13 @@ import org.sonar.api.rules.ActiveRule; import org.sonar.api.rules.Rule; import org.sonar.api.rules.RulePriority; -import javax.persistence.*; - import java.util.ArrayList; import java.util.List; +import javax.persistence.*; + /** - * This class is badly named. It should be "QualityProfile". Indeed it does not relate only to rules but to metric - * thresholds too. + * This class is badly named. It should be "QualityProfile". Indeed it does not relate only to rules but to metric thresholds too. */ @Entity @Table(name = "rules_profiles") @@ -153,16 +152,16 @@ public class RulesProfile implements Cloneable { } /** - * Set whether this is the default profile for the language. The default profile is used when none is explicitly - * defined when auditing a project. + * Set whether this is the default profile for the language. The default profile is used when none is explicitly defined when auditing a + * project. */ public void setDefaultProfile(Boolean b) { this.defaultProfile = b; } /** - * @return whether the profile is defined in a plugin. Provided profiles are automatically restored during - * server startup and can not be updated by end users. + * @return whether the profile is defined in a plugin. Provided profiles are automatically restored during server startup and can not be + * updated by end users. */ public Boolean getProvided() { return provided; @@ -232,7 +231,7 @@ public class RulesProfile implements Cloneable { } /** - * @deprecated since 2.3. Use getActiveRulesByRepository(). + * @deprecated since 2.3 use {@link #getActiveRulesByRepository()} instead. */ @Deprecated public List getActiveRulesByPlugin(String repositoryKey) { @@ -242,7 +241,7 @@ public class RulesProfile implements Cloneable { public List getActiveRulesByRepository(String repositoryKey) { List result = new ArrayList(); for (ActiveRule activeRule : getActiveRules()) { - if (repositoryKey.equals(activeRule.getPluginName())) { + if (repositoryKey.equals(activeRule.getRepositoryKey())) { result.add(activeRule); } } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/rules/ActiveRule.java b/sonar-plugin-api/src/main/java/org/sonar/api/rules/ActiveRule.java index a57bc3c21bb..de5db8d61a8 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/rules/ActiveRule.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/rules/ActiveRule.java @@ -25,11 +25,11 @@ import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.builder.ToStringBuilder; import org.sonar.api.profiles.RulesProfile; -import javax.persistence.*; - import java.util.ArrayList; import java.util.List; +import javax.persistence.*; + /** * A class to map an ActiveRule to the hibernate model */ @@ -175,11 +175,11 @@ public class ActiveRule implements Cloneable { } /** - * @deprecated use getRepositoryKey() + * @deprecated since 2.3 use {@link #getRepositoryKey()} instead */ @Deprecated public String getPluginName() { - return rule.getPluginName(); + return rule.getRepositoryKey(); } public String getRepositoryKey() { @@ -230,7 +230,8 @@ public class ActiveRule implements Cloneable { @Override public String toString() { - return new ToStringBuilder(this).append("id", getId()).append("rule", rule).append("priority", severity).append("params", activeRuleParams).toString(); + return new ToStringBuilder(this).append("id", getId()).append("rule", rule).append("priority", severity) + .append("params", activeRuleParams).toString(); } @Override diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/rules/Rule.java b/sonar-plugin-api/src/main/java/org/sonar/api/rules/Rule.java index 618d0e6fb46..6a33cb6c5f6 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/rules/Rule.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/rules/Rule.java @@ -26,11 +26,11 @@ import org.apache.commons.lang.builder.ToStringBuilder; import org.sonar.api.database.DatabaseProperties; import org.sonar.check.Cardinality; -import javax.persistence.*; - import java.util.ArrayList; import java.util.List; +import javax.persistence.*; + @Entity @Table(name = "rules") public final class Rule { @@ -92,8 +92,8 @@ public final class Rule { * Creates rule with minimum set of info * * @param pluginName the plugin name indicates which plugin the rule belongs to - * @param key the key should be unique within a plugin, but it is even more careful for the time being that it is unique - * across the application + * @param key the key should be unique within a plugin, but it is even more careful for the time being that it is unique across the + * application * @deprecated since 2.3. Use the factory method {@link #create()} */ @Deprecated @@ -107,8 +107,8 @@ public final class Rule { * Creates a fully qualified rule * * @param pluginKey the plugin the rule belongs to - * @param key the key should be unique within a plugin, but it is even more careful for the time being that it is unique - * across the application + * @param key the key should be unique within a plugin, but it is even more careful for the time being that it is unique across the + * application * @param name the name displayed in the UI * @param rulesCategory the ISO category the rule belongs to * @param severity this is the severity associated to the rule @@ -201,13 +201,18 @@ public final class Rule { return this; } + /** + * @deprecated since 2.5 use {@link #getRepositoryKey()} instead + */ + @Deprecated public String getPluginName() { return pluginName; } /** - * Sets the plugin name the rule belongs to + * @deprecated since 2.5 use {@link #setRepositoryKey(String)} instead */ + @Deprecated public Rule setPluginName(String pluginName) { this.pluginName = pluginName; return this; @@ -229,6 +234,14 @@ public final class Rule { return description; } + /** + * Sets the rule description + */ + public Rule setDescription(String description) { + this.description = StringUtils.strip(description); + return this; + } + public Boolean isEnabled() { return enabled; } @@ -241,14 +254,6 @@ public final class Rule { return this; } - /** - * Sets the rule description - */ - public Rule setDescription(String description) { - this.description = StringUtils.strip(description); - return this; - } - public List getParams() { return params; } @@ -276,15 +281,15 @@ public final class Rule { public RuleParam createParameter() { RuleParam parameter = new RuleParam() - .setRule(this); + .setRule(this); params.add(parameter); return parameter; } public RuleParam createParameter(String key) { RuleParam parameter = new RuleParam() - .setKey(key) - .setRule(this); + .setKey(key) + .setRule(this); params.add(parameter); return parameter; } @@ -376,7 +381,7 @@ public final class Rule { } Rule other = (Rule) obj; return new EqualsBuilder() - .append(pluginName, other.getPluginName()) + .append(pluginName, other.getRepositoryKey()) .append(key, other.getKey()) .isEquals(); } -- 2.39.5