]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-1829: Use severity instead of priority
authorGodin <mandrikov@gmail.com>
Tue, 7 Dec 2010 16:02:48 +0000 (16:02 +0000)
committerGodin <mandrikov@gmail.com>
Tue, 7 Dec 2010 16:02:48 +0000 (16:02 +0000)
20 files changed:
plugins/sonar-checkstyle-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleProfileImporterTest.java
plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/PmdProfileImporterTest.java
plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/SonarWayProfileTest.java
plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/SonarWayWithFindbugsProfileTest.java
plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/SunConventionsProfileTest.java
sonar-deprecated/src/main/java/org/sonar/api/checks/templates/CheckTemplateRepository.java
sonar-deprecated/src/main/java/org/sonar/api/checks/templates/XmlCheckTemplateFactory.java
sonar-deprecated/src/main/java/org/sonar/api/rules/StandardRulesXmlParser.java
sonar-deprecated/src/test/java/org/sonar/api/rules/StandardRulesXmlParserTest.java
sonar-plugin-api/src/main/java/org/sonar/api/rules/AnnotationRuleParser.java
sonar-plugin-api/src/main/java/org/sonar/api/rules/Rule.java
sonar-plugin-api/src/main/java/org/sonar/api/rules/XMLRuleParser.java
sonar-plugin-api/src/test/java/org/sonar/api/profiles/RulesProfileTest.java
sonar-plugin-api/src/test/java/org/sonar/api/rules/AnnotationRuleParserTest.java
sonar-plugin-api/src/test/java/org/sonar/api/rules/RuleTest.java
sonar-plugin-api/src/test/java/org/sonar/api/rules/XMLRuleParserTest.java
sonar-server/src/main/java/org/sonar/server/rules/DeprecatedRuleRepositories.java
sonar-server/src/main/java/org/sonar/server/startup/RegisterRules.java
sonar-server/src/test/java/org/sonar/server/rules/DeprecatedProfilesTest.java
sonar-server/src/test/java/org/sonar/server/startup/RegisterRulesTest.java

index 8a50acae1c9f417a6431d98736c92c75d293af1b..330698acc3a5da64977eae36cce9d4bfb00b2861 100644 (file)
@@ -34,7 +34,9 @@ import java.io.StringReader;
 
 import static org.hamcrest.core.Is.is;
 import static org.hamcrest.core.IsNull.nullValue;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
 import static org.mockito.Matchers.anyObject;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
@@ -49,12 +51,10 @@ public class CheckstyleProfileImporterTest {
     messages = ValidationMessages.create();
 
     /*
-
-    The mocked rule finder defines 2 rules :
-
-    - JavadocCheck with 2 paramters format and ignore, default priority is MAJOR
-    - EqualsHashCodeCheck without parameters, default priority is BLOCKER
-
+     * The mocked rule finder defines 2 rules :
+     * 
+     * - JavadocCheck with 2 paramters format and ignore, default priority is MAJOR
+     * - EqualsHashCodeCheck without parameters, default priority is BLOCKER
      */
     importer = new CheckstyleProfileImporter(newRuleFinder());
   }
@@ -146,19 +146,19 @@ public class CheckstyleProfileImporterTest {
         if (StringUtils.equals(query.getConfigKey(), "Checker/JavadocPackage")) {
           rule = Rule.create(query.getRepositoryKey(), "com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocPackageCheck", "Javadoc Package")
               .setConfigKey("Checker/JavadocPackage")
-              .setPriority(RulePriority.MAJOR);
+              .setSeverity(RulePriority.MAJOR);
           rule.createParameter("format");
           rule.createParameter("ignore");
 
         } else if (StringUtils.equals(query.getConfigKey(), "Checker/TreeWalker/EqualsHashCode")) {
           rule = Rule.create(query.getRepositoryKey(), "com.puppycrawl.tools.checkstyle.checks.coding.EqualsHashCodeCheck", "Equals HashCode")
               .setConfigKey("Checker/TreeWalker/EqualsHashCode")
-              .setPriority(RulePriority.BLOCKER);
+              .setSeverity(RulePriority.BLOCKER);
 
         } else if (StringUtils.equals(query.getKey(), "com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocPackageCheck_12345")) {
           rule = Rule.create(query.getRepositoryKey(), "com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocPackageCheck_12345", "Javadoc Package")
               .setConfigKey("Checker/JavadocPackage")
-              .setPriority(RulePriority.MAJOR);
+              .setSeverity(RulePriority.MAJOR);
           rule.createParameter("format");
           rule.createParameter("ignore");
         }
index fd386c398aba13f97f81e62b016f39ce7512bfe4..41064bec01289ba5399bebb9edef049de14e66b5 100644 (file)
  */
 package org.sonar.plugins.pmd;
 
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.nullValue;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertThat;
-import static org.mockito.Matchers.anyObject;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-import java.io.Reader;
-import java.io.StringReader;
-
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.invocation.InvocationOnMock;
 import org.mockito.stubbing.Answer;
 import org.sonar.api.profiles.RulesProfile;
-import org.sonar.api.rules.ActiveRule;
-import org.sonar.api.rules.Rule;
-import org.sonar.api.rules.RuleFinder;
-import org.sonar.api.rules.RulePriority;
-import org.sonar.api.rules.RuleQuery;
+import org.sonar.api.rules.*;
 import org.sonar.api.utils.ValidationMessages;
 import org.sonar.plugins.pmd.xml.PmdRuleset;
 import org.sonar.test.TestUtils;
 
+import java.io.Reader;
+import java.io.StringReader;
+
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.nullValue;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Matchers.anyObject;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
 public class PmdProfileImporterTest {
 
   private PmdProfileImporter importer;
@@ -156,7 +152,7 @@ public class PmdProfileImporterTest {
       public Rule answer(InvocationOnMock iom) throws Throwable {
         RuleQuery query = (RuleQuery) iom.getArguments()[0];
         Rule rule = Rule.create(query.getRepositoryKey(), query.getConfigKey(), "Rule name - " + query.getConfigKey())
-            .setConfigKey(query.getConfigKey()).setPriority(RulePriority.BLOCKER);
+            .setConfigKey(query.getConfigKey()).setSeverity(RulePriority.BLOCKER);
         if (rule.getConfigKey().equals("rulesets/coupling.xml/ExcessiveImports")) {
           rule.createParameter("max");
         }
index 844dfa9100e6cf2deea627b1a76d5f13ec190deb..ba5abe42307c81c0354587182a8a38ee65314a56 100644 (file)
  */
 package org.sonar.plugins.pmd;
 
-import static org.hamcrest.core.Is.is;
-import static org.hamcrest.number.OrderingComparisons.greaterThan;
-import static org.junit.Assert.assertThat;
-import static org.mockito.Matchers.anyObject;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
 import org.junit.Test;
 import org.mockito.invocation.InvocationOnMock;
 import org.mockito.stubbing.Answer;
@@ -37,6 +30,13 @@ import org.sonar.api.rules.RulePriority;
 import org.sonar.api.rules.RuleQuery;
 import org.sonar.api.utils.ValidationMessages;
 
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.number.OrderingComparisons.greaterThan;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Matchers.anyObject;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
 public class SonarWayProfileTest {
 
   @Test
@@ -56,7 +56,7 @@ public class SonarWayProfileTest {
       public Rule answer(InvocationOnMock iom) throws Throwable {
         RuleQuery query = (RuleQuery) iom.getArguments()[0];
         Rule rule = Rule.create(query.getRepositoryKey(), query.getConfigKey(), "Rule name - " + query.getConfigKey())
-            .setConfigKey(query.getConfigKey()).setPriority(RulePriority.BLOCKER);
+            .setConfigKey(query.getConfigKey()).setSeverity(RulePriority.BLOCKER);
         return rule;
       }
     });
index 7f0aa81c9698dd17557e8cebbd3b7497c199f031..9e0ab0018f3f6289f64f376ee0c48bd3f78d0b6f 100644 (file)
  */
 package org.sonar.plugins.pmd;
 
-import static org.hamcrest.core.Is.is;
-import static org.hamcrest.number.OrderingComparisons.greaterThan;
-import static org.junit.Assert.assertThat;
-import static org.mockito.Matchers.anyObject;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
 import org.junit.Test;
 import org.mockito.invocation.InvocationOnMock;
 import org.mockito.stubbing.Answer;
@@ -36,6 +29,13 @@ import org.sonar.api.rules.RulePriority;
 import org.sonar.api.rules.RuleQuery;
 import org.sonar.api.utils.ValidationMessages;
 
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.number.OrderingComparisons.greaterThan;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Matchers.anyObject;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
 public class SonarWayWithFindbugsProfileTest {
 
   @Test
@@ -55,7 +55,7 @@ public class SonarWayWithFindbugsProfileTest {
       public Rule answer(InvocationOnMock iom) throws Throwable {
         RuleQuery query = (RuleQuery) iom.getArguments()[0];
         Rule rule = Rule.create(query.getRepositoryKey(), query.getConfigKey(), "Rule name - " + query.getConfigKey())
-            .setConfigKey(query.getConfigKey()).setPriority(RulePriority.BLOCKER);
+            .setConfigKey(query.getConfigKey()).setSeverity(RulePriority.BLOCKER);
         return rule;
       }
     });
index cdd9f1e396d383f6490caf73518c973ed94a6a77..b55a44b773fab02b26decc0ad66c1954dd7f9067 100644 (file)
  */
 package org.sonar.plugins.pmd;
 
-import static org.hamcrest.core.Is.is;
-import static org.hamcrest.number.OrderingComparisons.greaterThan;
-import static org.junit.Assert.assertThat;
-import static org.mockito.Matchers.anyObject;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
 import org.junit.Test;
 import org.mockito.invocation.InvocationOnMock;
 import org.mockito.stubbing.Answer;
@@ -36,6 +29,13 @@ import org.sonar.api.rules.RulePriority;
 import org.sonar.api.rules.RuleQuery;
 import org.sonar.api.utils.ValidationMessages;
 
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.number.OrderingComparisons.greaterThan;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Matchers.anyObject;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
 public class SunConventionsProfileTest {
   @Test
   public void shouldCreateProfile() {
@@ -54,7 +54,7 @@ public class SunConventionsProfileTest {
       public Rule answer(InvocationOnMock iom) throws Throwable {
         RuleQuery query = (RuleQuery) iom.getArguments()[0];
         Rule rule = Rule.create(query.getRepositoryKey(), query.getConfigKey(), "Rule name - " + query.getConfigKey())
-            .setConfigKey(query.getConfigKey()).setPriority(RulePriority.BLOCKER);
+            .setConfigKey(query.getConfigKey()).setSeverity(RulePriority.BLOCKER);
         return rule;
       }
     });
index 3ebc5a99c0f858527278e3f265e259464af411ec..eade8969a014fd1d402fceeba5b68de6663f8730 100644 (file)
@@ -42,7 +42,6 @@ public class CheckTemplateRepository implements RulesRepository {
   private List<CheckTemplate> templates;
   private Map<String, CheckTemplate> templatesByKey;
 
-
   public CheckTemplateRepository() {
   }
 
@@ -112,7 +111,6 @@ public class CheckTemplateRepository implements RulesRepository {
     return key.hashCode();
   }
 
-
   public static CheckTemplateRepository createFromXml(String repositoryKey, Language language, String pathToXml) {
     InputStream input = CheckTemplateRepository.class.getResourceAsStream(pathToXml);
     try {
@@ -135,14 +133,10 @@ public class CheckTemplateRepository implements RulesRepository {
     return repository;
   }
 
-
   /*
-
-   CODE FOR BACKWARD COMPATIBLITY
-   This class should not extend RulesRepository in next versions
-
-  */
-
+   * CODE FOR BACKWARD COMPATIBLITY
+   * This class should not extend RulesRepository in next versions
+   */
 
   public List<Rule> getInitialReferential() {
     List<Rule> rules = new ArrayList<Rule>();
@@ -156,7 +150,7 @@ public class CheckTemplateRepository implements RulesRepository {
     Rule rule = new Rule(getKey(), checkTemplate.getKey());
     rule.setDescription(checkTemplate.getDescription(Locale.ENGLISH));
     rule.setName(checkTemplate.getTitle(Locale.ENGLISH));
-    rule.setPriority(RulePriority.fromCheckPriority(checkTemplate.getPriority()));
+    rule.setSeverity(RulePriority.fromCheckPriority(checkTemplate.getPriority()));
     for (CheckTemplateProperty checkTemplateProperty : checkTemplate.getProperties()) {
       RuleParam param = rule.createParameter(checkTemplateProperty.getKey());
       param.setDescription(checkTemplateProperty.getDescription(Locale.ENGLISH));
index 1de8a616a0c997b4a28161f27c45fda3e43db361..b08b584c3c5784b6a36a8db7c09e28e420bd5584 100644 (file)
@@ -34,6 +34,7 @@ import java.util.List;
 
 /**
  * EXPERIMENTAL - will be used in version 2.2
+ * 
  * @since 2.1
  */
 public class XmlCheckTemplateFactory {
@@ -75,7 +76,7 @@ public class XmlCheckTemplateFactory {
 
         template.setConfigKey(rule.getConfigKey());
         template.setDescription(rule.getDescription());
-        template.setPriority(rule.getPriority().toCheckPriority());
+        template.setPriority(rule.getSeverity().toCheckPriority());
         template.setTitle(rule.getName());
 
         if (rule.getParams() != null) {
@@ -96,4 +97,4 @@ public class XmlCheckTemplateFactory {
     return property;
   }
 
-}
\ No newline at end of file
+}
index 58b8c69abbc04a2fa89cc121a829a0cf103ef0f3..82889c80c66a4de237ac564e621f77cf6b9ef9b7 100644 (file)
@@ -44,7 +44,7 @@ public class StandardRulesXmlParser {
     InputStream inputStream = null;
     try {
       inputStream = IOUtils.toInputStream(xml, CharEncoding.UTF_8);
-      return setDefaultRulePriorities((List<Rule>) getXStream().fromXML(inputStream));
+      return setDefaultRuleSeverities((List<Rule>) getXStream().fromXML(inputStream));
 
     } catch (IOException e) {
       throw new SonarException("Can't parse xml file", e);
@@ -55,22 +55,22 @@ public class StandardRulesXmlParser {
   }
 
   public List<Rule> parse(Reader reader) {
-    return setDefaultRulePriorities((List<Rule>) getXStream().fromXML(reader));
+    return setDefaultRuleSeverities((List<Rule>) getXStream().fromXML(reader));
   }
 
   public List<Rule> parse(InputStream input) {
     try {
-      return setDefaultRulePriorities((List<Rule>) getXStream().fromXML(new InputStreamReader(input, CharEncoding.UTF_8)));
+      return setDefaultRuleSeverities((List<Rule>) getXStream().fromXML(new InputStreamReader(input, CharEncoding.UTF_8)));
 
     } catch (UnsupportedEncodingException e) {
       throw new SonarException("Can't parse xml file", e);
     }
   }
 
-  private List<Rule> setDefaultRulePriorities(List<Rule> rules) {
+  private List<Rule> setDefaultRuleSeverities(List<Rule> rules) {
     for (Rule rule : rules) {
-      if (rule.getPriority() == null) {
-        rule.setPriority(RulePriority.MAJOR);
+      if (rule.getSeverity() == null) {
+        rule.setSeverity(RulePriority.MAJOR);
       }
     }
     return rules;
index cdccbf1875b8d70eff3abe690e34286768c0a76c..25a408ce0898d1d15b863a4674933b752372f65c 100644 (file)
@@ -27,7 +27,8 @@ import java.util.List;
 
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
 
 public class StandardRulesXmlParserTest {
   @Test
@@ -53,7 +54,7 @@ public class StandardRulesXmlParserTest {
     StandardRulesXmlParser parser = new StandardRulesXmlParser();
     String xml = "<rules><rule key='1' priority='CRITICAL'><category name='cat1'/></rule></rules>";
     List<Rule> rules = parser.parse(xml);
-    Assert.assertEquals(RulePriority.CRITICAL, rules.get(0).getPriority());
+    Assert.assertEquals(RulePriority.CRITICAL, rules.get(0).getSeverity());
   }
 
   @Test
@@ -61,7 +62,7 @@ public class StandardRulesXmlParserTest {
     StandardRulesXmlParser parser = new StandardRulesXmlParser();
     String xml = "<rules><rule key='1'><category name='cat1'/></rule></rules>";
     List<Rule> rules = parser.parse(xml);
-    Assert.assertEquals(RulePriority.MAJOR, rules.get(0).getPriority());
+    Assert.assertEquals(RulePriority.MAJOR, rules.get(0).getSeverity());
   }
 
   @Test
index d40dc943553e2e70a152d979162e5bd73e88e72f..619a01c3c7e78d3599da1317aae3fbf5a92e7600 100644 (file)
@@ -64,7 +64,7 @@ public final class AnnotationRuleParser implements ServerComponent {
     String ruleName = StringUtils.defaultIfEmpty(ruleAnnotation.name(), ruleKey);
     Rule rule = Rule.create(repositoryKey, ruleKey, ruleName);
     rule.setDescription(ruleAnnotation.description());
-    rule.setPriority(RulePriority.fromCheckPriority(ruleAnnotation.priority()));
+    rule.setSeverity(RulePriority.fromCheckPriority(ruleAnnotation.priority()));
     rule.setCardinality(ruleAnnotation.cardinality());
 
     Field[] fields = clazz.getDeclaredFields();
@@ -82,7 +82,7 @@ public final class AnnotationRuleParser implements ServerComponent {
     String ruleName = StringUtils.defaultIfEmpty(checkAnnotation.title(), ruleKey);
     Rule rule = Rule.create(repositoryKey, ruleKey, ruleName);
     rule.setDescription(checkAnnotation.description());
-    rule.setPriority(RulePriority.fromCheckPriority(checkAnnotation.priority()));
+    rule.setSeverity(RulePriority.fromCheckPriority(checkAnnotation.priority()));
 
     Field[] fields = clazz.getDeclaredFields();
     if (fields != null) {
index d257ef39a2fbb99384c1330d2cc914fd1eae417f..618d0e6fb4695cffc7f1cfac3a3327c306e048e2 100644 (file)
@@ -124,7 +124,7 @@ public final class Rule {
   }\r
 \r
   /**\r
-   * @deprecated Use the factory method {@link #create()}\r
+   * @deprecated since 2.3. Use the factory method {@link #create()}\r
    */\r
   @Deprecated\r
   public Rule(String name, String key, RulesCategory rulesCategory, String pluginName, String description) {\r
@@ -154,7 +154,7 @@ public final class Rule {
   }\r
 \r
   /**\r
-   * @deprecated visibility should be decreased to protected or package\r
+   * @deprecated since 2.3. visibility should be decreased to protected or package\r
    */\r
   @Deprecated\r
   public void setId(Integer id) {\r
index adc70ff30e53bca01398766f08d5605b46f7c4f0..8eadd746680e52d9d880b4e1dc7c33b84ca43cab 100644 (file)
@@ -33,6 +33,7 @@ import org.sonar.check.Cardinality;
 
 import javax.xml.stream.XMLInputFactory;
 import javax.xml.stream.XMLStreamException;
+
 import java.io.*;
 import java.util.ArrayList;
 import java.util.List;
@@ -111,7 +112,7 @@ public final class XMLRuleParser implements ServerComponent {
     /* BACKWARD COMPATIBILITY WITH DEPRECATED FORMAT */
     String priorityAttribute = ruleC.getAttrValue("priority");
     if (StringUtils.isNotBlank(priorityAttribute)) {
-      rule.setPriority(RulePriority.valueOf(StringUtils.trim(priorityAttribute)));
+      rule.setSeverity(RulePriority.valueOf(StringUtils.trim(priorityAttribute)));
     }
 
     SMInputCursor cursor = ruleC.childElementCursor();
@@ -132,7 +133,7 @@ public final class XMLRuleParser implements ServerComponent {
         rule.setConfigKey(StringUtils.trim(cursor.collectDescendantText(false)));
 
       } else if (StringUtils.equalsIgnoreCase("priority", nodeName)) {
-        rule.setPriority(RulePriority.valueOf(StringUtils.trim(cursor.collectDescendantText(false))));
+        rule.setSeverity(RulePriority.valueOf(StringUtils.trim(cursor.collectDescendantText(false))));
 
       } else if (StringUtils.equalsIgnoreCase("cardinality", nodeName)) {
         rule.setCardinality(Cardinality.valueOf(StringUtils.trim(cursor.collectDescendantText(false))));
index 3f36241a437aaf91c835894b9119911f01d41343..0e54a3a824d361430de1754f7484bd4feb2d6387 100644 (file)
@@ -42,16 +42,16 @@ public class RulesProfileTest {
   @Test
   public void activateRuleWithDefaultPriority() {
     RulesProfile profile = RulesProfile.create();
-    Rule rule = Rule.create("repo", "key1", "name1").setPriority(RulePriority.CRITICAL);
+    Rule rule = Rule.create("repo", "key1", "name1").setSeverity(RulePriority.CRITICAL);
     profile.activateRule(rule, null);
-    assertThat(profile.getActiveRule("repo", "key1").getPriority(), is(RulePriority.CRITICAL));
+    assertThat(profile.getActiveRule("repo", "key1").getSeverity(), is(RulePriority.CRITICAL));
   }
 
   @Test
   public void activateRuleWithSpecificPriority() {
     RulesProfile profile = RulesProfile.create();
-    Rule rule = Rule.create("repo", "key1", "name1").setPriority(RulePriority.CRITICAL);
+    Rule rule = Rule.create("repo", "key1", "name1").setSeverity(RulePriority.CRITICAL);
     profile.activateRule(rule, RulePriority.MINOR);
-    assertThat(profile.getActiveRule("repo", "key1").getPriority(), is(RulePriority.MINOR));
+    assertThat(profile.getActiveRule("repo", "key1").getSeverity(), is(RulePriority.MINOR));
   }
 }
index 6493581677b13e6662aa6aafd355e77f8095de5e..c48445bfbec858dd457f8de8bef801a240253981 100644 (file)
@@ -19,7 +19,7 @@ public class AnnotationRuleParserTest {
     Rule rule = rules.get(0);
     assertThat(rule.getKey(), is("foo"));
     assertThat(rule.getName(), is("bar"));
-    assertThat(rule.getPriority(), is(RulePriority.BLOCKER));
+    assertThat(rule.getSeverity(), is(RulePriority.BLOCKER));
     assertThat(rule.getParams().size(), is(1));
     RuleParam prop = rule.getParam("property");
     assertThat(prop.getKey(), is("property"));
@@ -34,7 +34,7 @@ public class AnnotationRuleParserTest {
     Rule rule = rules.get(0);
     assertThat(rule.getKey(), is("foo"));
     assertThat(rule.getName(), is("foo"));
-    assertThat(rule.getPriority(), is(RulePriority.MAJOR));
+    assertThat(rule.getSeverity(), is(RulePriority.MAJOR));
   }
 
   @Test
@@ -44,7 +44,7 @@ public class AnnotationRuleParserTest {
     Rule rule = rules.get(0);
     assertThat(rule.getKey(), is(RuleWithoutKey.class.getCanonicalName()));
     assertThat(rule.getName(), is("foo"));
-    assertThat(rule.getPriority(), is(RulePriority.MAJOR));
+    assertThat(rule.getSeverity(), is(RulePriority.MAJOR));
   }
 
   @Test
@@ -55,7 +55,7 @@ public class AnnotationRuleParserTest {
     assertThat(rule.getKey(), is(Check.class.getCanonicalName()));
     assertThat(rule.getName(), is(Check.class.getCanonicalName()));
     assertThat(rule.getDescription(), is("Deprecated check"));
-    assertThat(rule.getPriority(), is(RulePriority.BLOCKER));
+    assertThat(rule.getSeverity(), is(RulePriority.BLOCKER));
   }
 
   private List<Rule> parseAnnotatedClass(Class annotatedClass) {
index c0767fda0adae1cd79bf371cd339dd697ecf8794..56285ed10f20acab4e860d8edaacfb633ff34a17 100644 (file)
@@ -19,9 +19,6 @@
  */
 package org.sonar.api.rules;
 
-import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.*;
-
 import org.hamcrest.core.Is;
 import org.junit.Assert;
 import org.junit.Test;
@@ -29,6 +26,10 @@ import org.junit.Test;
 import java.util.Arrays;
 import java.util.List;
 
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
+
 public class RuleTest {
 
   @Test
@@ -63,7 +64,7 @@ public class RuleTest {
   public void shouldRemoveNewLineCharactersInNameWithSecondConstructor() {
     Rule rule;
     for (String example : getExamplesContainingNewLineCharacter()) {
-      rule = new Rule(null, null, example, (RulesCategory)null, null);
+      rule = new Rule(null, null, example, (RulesCategory) null, null);
       assertThat(rule.getName(), is("test"));
     }
   }
@@ -71,25 +72,23 @@ public class RuleTest {
   @Test
   public void defaultPriorityIsMajor() {
     Rule rule = new Rule();
-    assertThat(rule.getPriority(), Is.is(RulePriority.MAJOR));
+    assertThat(rule.getSeverity(), Is.is(RulePriority.MAJOR));
 
     rule = new Rule("name", "key");
-    assertThat(rule.getPriority(), Is.is(RulePriority.MAJOR));
+    assertThat(rule.getSeverity(), Is.is(RulePriority.MAJOR));
 
     rule = new Rule("pkey", "key", "name", Iso9126RulesCategories.EFFICIENCY, null, null);
-    assertThat(rule.getPriority(), Is.is(RulePriority.MAJOR));
+    assertThat(rule.getSeverity(), Is.is(RulePriority.MAJOR));
 
-    rule.setPriority(RulePriority.BLOCKER);
-    assertThat(rule.getPriority(), Is.is(RulePriority.BLOCKER));
+    rule.setSeverity(RulePriority.BLOCKER);
+    assertThat(rule.getSeverity(), Is.is(RulePriority.BLOCKER));
 
-    rule.setPriority(null);
-    assertThat(rule.getPriority(), Is.is(RulePriority.MAJOR));
+    rule.setSeverity(null);
+    assertThat(rule.getSeverity(), Is.is(RulePriority.MAJOR));
   }
 
-
   private List<String> getExamplesContainingNewLineCharacter() {
     return Arrays.asList("te\nst", "te\ns\nt", "te\rst", "te\n\rst", "te\r\nst");
   }
 
-
 }
index 02027741ceb15dc05e2e8b79e0dc17ef5cc5a78e..dab65bfc56457e766760b854ab436e7a700b06ce 100644 (file)
@@ -44,7 +44,7 @@ public class XMLRuleParserTest {
     Rule rule = rules.get(0);
     assertThat(rule.getName(), is("Local Variable Name"));
     assertThat(rule.getDescription(), is("Checks that local, non-final variable names conform to a format specified by the format property."));
-    assertThat(rule.getPriority(), Is.is(RulePriority.BLOCKER));
+    assertThat(rule.getSeverity(), Is.is(RulePriority.BLOCKER));
     assertThat(rule.getCardinality(), Is.is(Cardinality.MULTIPLE));
     assertThat(rule.getConfigKey(), is("Checker/TreeWalker/LocalVariableName"));
 
@@ -93,7 +93,7 @@ public class XMLRuleParserTest {
     List<Rule> rules = new XMLRuleParser().parse(getClass().getResourceAsStream("/org/sonar/api/rules/XMLRuleParserTest/deprecated.xml"));
     assertThat(rules.size(), is(1));
     Rule rule = rules.get(0);
-    assertThat(rule.getPriority(), Is.is(RulePriority.CRITICAL));
+    assertThat(rule.getSeverity(), Is.is(RulePriority.CRITICAL));
     assertThat(rule.getKey(), is("org.sonar.it.checkstyle.MethodsCountCheck"));
     assertThat(rule.getParam("minMethodsCount"), not(nullValue()));
   }
index b3bc7f1a9c796ef901f01fba7288033ff986b0a3..55de2e4efb5b113b6465192b86f0ad385691f2c8 100644 (file)
@@ -67,7 +67,6 @@ public final class DeprecatedRuleRepositories {
   }
 }
 
-
 class DeprecatedRuleRepository extends RuleRepository {
 
   private RulesRepository deprecatedRepository;
@@ -116,7 +115,7 @@ class DeprecatedRuleRepository extends RuleRepository {
   private Rule cloneRule(Rule deprecatedRule) {
     Rule rule = Rule.create(getKey(), deprecatedRule.getKey(), deprecatedRule.getName());
     rule.setConfigKey(deprecatedRule.getConfigKey());
-    rule.setPriority(deprecatedRule.getPriority());
+    rule.setSeverity(deprecatedRule.getSeverity());
     rule.setDescription(deprecatedRule.getDescription());
     rule.setEnabled(true);
     if (deprecatedRule.getParams() != null) {
index 6526d1d04fdfced2f6d6a18c1807e274f7c18d7d..c222152667c9318c79c7ba1d401ba0b014cb75a8 100644 (file)
@@ -70,11 +70,11 @@ public final class RegisterRules {
     List<Integer> deprecatedUserRuleIds = new ArrayList<Integer>();
     deprecatedUserRuleIds.addAll(session.createQuery(
         "SELECT r.id FROM " + Rule.class.getSimpleName() +
-        " r WHERE r.parent IS NOT NULL AND NOT EXISTS(FROM " + Rule.class.getSimpleName() + " p WHERE r.parent=p)").getResultList());
+            " r WHERE r.parent IS NOT NULL AND NOT EXISTS(FROM " + Rule.class.getSimpleName() + " p WHERE r.parent=p)").getResultList());
 
     deprecatedUserRuleIds.addAll(session.createQuery(
         "SELECT r.id FROM " + Rule.class.getSimpleName() +
-        " r WHERE r.parent IS NOT NULL AND EXISTS(FROM " + Rule.class.getSimpleName() + " p WHERE r.parent=p and p.enabled=false)").getResultList());
+            " r WHERE r.parent IS NOT NULL AND EXISTS(FROM " + Rule.class.getSimpleName() + " p WHERE r.parent=p and p.enabled=false)").getResultList());
 
     for (Integer deprecatedUserRuleId : deprecatedUserRuleIds) {
       Rule rule = session.getSingleResult(Rule.class, "id", deprecatedUserRuleId);
@@ -127,7 +127,7 @@ public final class RegisterRules {
     persistedRule.setName(rule.getName());
     persistedRule.setConfigKey(rule.getConfigKey());
     persistedRule.setDescription(rule.getDescription());
-    persistedRule.setPriority(rule.getPriority());
+    persistedRule.setSeverity(rule.getSeverity());
     persistedRule.setEnabled(true);
     persistedRule.setCardinality(rule.getCardinality());
 
index 187a3ed8e1f6b39b54fbe80e180f005f270576d2..7ae3f3bcda04551edf94f0293e6c164be7a8fe3a 100644 (file)
@@ -25,7 +25,6 @@ import org.sonar.api.rules.RulePriority;
 import org.sonar.api.utils.ValidationMessages;
 
 import static org.hamcrest.Matchers.is;
-import static org.hamcrest.core.IsNull.nullValue;
 import static org.junit.Assert.assertThat;
 
 public class DeprecatedProfilesTest {
@@ -44,13 +43,13 @@ public class DeprecatedProfilesTest {
 
     assertThat(def.getRules().size(), is(2));
     assertThat(def.getRulesByRepositoryKey("checkstyle").size(), is(1));
-    assertThat(def.getRulesByRepositoryKey("checkstyle").get(0).getPriority(), is(RulePriority.BLOCKER));
+    assertThat(def.getRulesByRepositoryKey("checkstyle").get(0).getSeverity(), is(RulePriority.BLOCKER));
   }
 
   @Test
   public void priorityIsOptional() {
     DeprecatedProfiles.DefaultProfileDefinition def = DeprecatedProfiles.DefaultProfileDefinition.create("sonar way", "java");
-    def.activateRule(Rule.create("checkstyle", "IllegalRegexp", "Illegal regexp").setPriority(RulePriority.BLOCKER), null);
-    assertThat(def.getRules().get(0).getPriority(), is(RulePriority.BLOCKER));
+    def.activateRule(Rule.create("checkstyle", "IllegalRegexp", "Illegal regexp").setSeverity(RulePriority.BLOCKER), null);
+    assertThat(def.getRules().get(0).getSeverity(), is(RulePriority.BLOCKER));
   }
 }
index 2f76ab1d3bd209bc0836fc1a5b9bcef443eb4f81..a43aa3403b1f79f0353615c4890165726e4ffd35 100644 (file)
@@ -23,18 +23,22 @@ import org.junit.Test;
 import org.sonar.api.rules.*;
 import org.sonar.jpa.test.AbstractDbUnitTestCase;
 
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
 
 import static org.hamcrest.Matchers.is;
 import static org.hamcrest.number.OrderingComparisons.greaterThan;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
 
 public class RegisterRulesTest extends AbstractDbUnitTestCase {
 
   @Test
   public void saveNewRepositories() {
     setupData("shared");
-    RegisterRules task = new RegisterRules(getSessionFactory(), null, new RuleRepository[]{new FakeRepository()});
+    RegisterRules task = new RegisterRules(getSessionFactory(), null, new RuleRepository[] { new FakeRepository() });
     task.start();
 
     List<Rule> result = getSession().getResults(Rule.class, "pluginName", "fake");
@@ -50,7 +54,7 @@ public class RegisterRulesTest extends AbstractDbUnitTestCase {
   @Test
   public void disableDeprecatedRepositories() {
     setupData("shared");
-    RegisterRules task = new RegisterRules(getSessionFactory(), null, new RuleRepository[]{new FakeRepository()});
+    RegisterRules task = new RegisterRules(getSessionFactory(), null, new RuleRepository[] { new FakeRepository() });
     task.start();
 
     List<Rule> rules = (List<Rule>) getSession()
@@ -65,7 +69,7 @@ public class RegisterRulesTest extends AbstractDbUnitTestCase {
   @Test
   public void disableDeprecatedActiveRules() {
     setupData("disableDeprecatedActiveRules");
-    RegisterRules task = new RegisterRules(getSessionFactory(), null, new RuleRepository[]{new FakeRepository()});
+    RegisterRules task = new RegisterRules(getSessionFactory(), null, new RuleRepository[] { new FakeRepository() });
     task.start();
 
     List<Rule> result = getSession().getResults(Rule.class, "pluginName", "fake");
@@ -82,10 +86,10 @@ public class RegisterRulesTest extends AbstractDbUnitTestCase {
   @Test
   public void disableDeprecatedActiveRuleParameters() {
     setupData("disableDeprecatedActiveRuleParameters");
-    RegisterRules task = new RegisterRules(getSessionFactory(), null, new RuleRepository[]{new FakeRepository()});
+    RegisterRules task = new RegisterRules(getSessionFactory(), null, new RuleRepository[] { new FakeRepository() });
     task.start();
 
-    ActiveRule arule= getSession().getSingleResult(ActiveRule.class, "id", 1);
+    ActiveRule arule = getSession().getSingleResult(ActiveRule.class, "id", 1);
     assertThat(arule.getActiveRuleParams().size(), is(2));
     assertNull(getSession().getSingleResult(ActiveRuleParam.class, "id", 3));
   }
@@ -93,7 +97,7 @@ public class RegisterRulesTest extends AbstractDbUnitTestCase {
   @Test
   public void disableDeprecatedRules() {
     setupData("disableDeprecatedRules");
-    RegisterRules task = new RegisterRules(getSessionFactory(), null, new RuleRepository[]{new FakeRepository()});
+    RegisterRules task = new RegisterRules(getSessionFactory(), null, new RuleRepository[] { new FakeRepository() });
     task.start();
 
     Rule rule = getSession().getSingleResult(Rule.class, "id", 1);
@@ -106,21 +110,21 @@ public class RegisterRulesTest extends AbstractDbUnitTestCase {
   @Test
   public void updateRuleFields() {
     setupData("updadeRuleFields");
-    RegisterRules task = new RegisterRules(getSessionFactory(), null, new RuleRepository[]{new FakeRepository()});
+    RegisterRules task = new RegisterRules(getSessionFactory(), null, new RuleRepository[] { new FakeRepository() });
     task.start();
 
     // fields have been updated with new values
     Rule rule = getSession().getSingleResult(Rule.class, "id", 1);
     assertThat(rule.getName(), is("One"));
     assertThat(rule.getDescription(), is("Description of One"));
-    assertThat(rule.getPriority(), is(RulePriority.BLOCKER));
+    assertThat(rule.getSeverity(), is(RulePriority.BLOCKER));
     assertThat(rule.getConfigKey(), is("config1"));
   }
 
   @Test
   public void updateRuleParameters() {
     setupData("updateRuleParameters");
-    RegisterRules task = new RegisterRules(getSessionFactory(), null, new RuleRepository[]{new FakeRepository()});
+    RegisterRules task = new RegisterRules(getSessionFactory(), null, new RuleRepository[] { new FakeRepository() });
     task.start();
 
     Rule rule = getSession().getSingleResult(Rule.class, "id", 1);
@@ -140,7 +144,7 @@ public class RegisterRulesTest extends AbstractDbUnitTestCase {
   @Test
   public void doNotDisableUserRulesIfParentIsEnabled() {
     setupData("doNotDisableUserRulesIfParentIsEnabled");
-    RegisterRules task = new RegisterRules(getSessionFactory(), null, new RuleRepository[]{new FakeRepository()});
+    RegisterRules task = new RegisterRules(getSessionFactory(), null, new RuleRepository[] { new FakeRepository() });
     task.start();
 
     Rule rule = getSession().getSingleResult(Rule.class, "id", 2);
@@ -150,7 +154,7 @@ public class RegisterRulesTest extends AbstractDbUnitTestCase {
   @Test
   public void disableUserRulesIfParentIsDisabled() {
     setupData("disableUserRulesIfParentIsDisabled");
-    RegisterRules task = new RegisterRules(getSessionFactory(), null, new RuleRepository[]{new FakeRepository()});
+    RegisterRules task = new RegisterRules(getSessionFactory(), null, new RuleRepository[] { new FakeRepository() });
     task.start();
 
     Rule rule = getSession().getSingleResult(Rule.class, "id", 2);
@@ -160,7 +164,7 @@ public class RegisterRulesTest extends AbstractDbUnitTestCase {
   @Test
   public void volumeTesting() {
     setupData("shared");
-    RegisterRules task = new RegisterRules(getSessionFactory(), null, new RuleRepository[]{new VolumeRepository()});
+    RegisterRules task = new RegisterRules(getSessionFactory(), null, new RuleRepository[] { new VolumeRepository() });
     task.start();
 
     List<Rule> result = getSession().getResults(Rule.class, "enabled", true);
@@ -176,14 +180,14 @@ class FakeRepository extends RuleRepository {
   public List<Rule> createRules() {
     Rule rule1 = Rule.create("fake", "rule1", "One");
     rule1.setDescription("Description of One");
-    rule1.setPriority(RulePriority.BLOCKER);
+    rule1.setSeverity(RulePriority.BLOCKER);
     rule1.setConfigKey("config1");
     rule1.createParameter("param1").setDescription("parameter one");
     rule1.createParameter("param2").setDescription("parameter two");
-    
+
     Rule rule2 = Rule.create("fake", "rule2", "Two");
-    rule2.setPriority(RulePriority.INFO);
-    
+    rule2.setSeverity(RulePriority.INFO);
+
     return Arrays.asList(rule1, rule2);
   }
 }
@@ -195,12 +199,11 @@ class VolumeRepository extends RuleRepository {
     super("volume", "java");
   }
 
-
   public List<Rule> createRules() {
     List<Rule> rules = new ArrayList<Rule>();
     for (int i = 0; i < SIZE; i++) {
       Rule rule = Rule.create("volume", "rule" + i, "description of " + i);
-      rule.setPriority(RulePriority.BLOCKER);
+      rule.setSeverity(RulePriority.BLOCKER);
       for (int j = 0; j < 20; j++) {
         rule.createParameter("param" + j);
       }
@@ -208,4 +211,4 @@ class VolumeRepository extends RuleRepository {
     }
     return rules;
   }
-}
\ No newline at end of file
+}