diff options
author | Godin <mandrikov@gmail.com> | 2010-12-07 16:02:48 +0000 |
---|---|---|
committer | Godin <mandrikov@gmail.com> | 2010-12-07 16:02:48 +0000 |
commit | b09f170fa5cd8980019d6cf91251ab11970b1cc6 (patch) | |
tree | 4fbf596dfeb13b56fec587d49c404de977264642 | |
parent | 8e9d7ff89a66bf987d7fcb7c298a53a992625375 (diff) | |
download | sonarqube-b09f170fa5cd8980019d6cf91251ab11970b1cc6.tar.gz sonarqube-b09f170fa5cd8980019d6cf91251ab11970b1cc6.zip |
SONAR-1829: Use severity instead of priority
20 files changed, 124 insertions, 131 deletions
diff --git a/plugins/sonar-checkstyle-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleProfileImporterTest.java b/plugins/sonar-checkstyle-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleProfileImporterTest.java index 8a50acae1c9..330698acc3a 100644 --- a/plugins/sonar-checkstyle-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleProfileImporterTest.java +++ b/plugins/sonar-checkstyle-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleProfileImporterTest.java @@ -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"); } diff --git a/plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/PmdProfileImporterTest.java b/plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/PmdProfileImporterTest.java index fd386c398ab..41064bec012 100644 --- a/plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/PmdProfileImporterTest.java +++ b/plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/PmdProfileImporterTest.java @@ -19,31 +19,27 @@ */ 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"); } diff --git a/plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/SonarWayProfileTest.java b/plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/SonarWayProfileTest.java index 844dfa9100e..ba5abe42307 100644 --- a/plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/SonarWayProfileTest.java +++ b/plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/SonarWayProfileTest.java @@ -19,13 +19,6 @@ */ 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; } }); diff --git a/plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/SonarWayWithFindbugsProfileTest.java b/plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/SonarWayWithFindbugsProfileTest.java index 7f0aa81c969..9e0ab0018f3 100644 --- a/plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/SonarWayWithFindbugsProfileTest.java +++ b/plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/SonarWayWithFindbugsProfileTest.java @@ -19,13 +19,6 @@ */ 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; } }); diff --git a/plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/SunConventionsProfileTest.java b/plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/SunConventionsProfileTest.java index cdd9f1e396d..b55a44b773f 100644 --- a/plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/SunConventionsProfileTest.java +++ b/plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/SunConventionsProfileTest.java @@ -19,13 +19,6 @@ */ 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; } }); diff --git a/sonar-deprecated/src/main/java/org/sonar/api/checks/templates/CheckTemplateRepository.java b/sonar-deprecated/src/main/java/org/sonar/api/checks/templates/CheckTemplateRepository.java index 3ebc5a99c0f..eade8969a01 100644 --- a/sonar-deprecated/src/main/java/org/sonar/api/checks/templates/CheckTemplateRepository.java +++ b/sonar-deprecated/src/main/java/org/sonar/api/checks/templates/CheckTemplateRepository.java @@ -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)); diff --git a/sonar-deprecated/src/main/java/org/sonar/api/checks/templates/XmlCheckTemplateFactory.java b/sonar-deprecated/src/main/java/org/sonar/api/checks/templates/XmlCheckTemplateFactory.java index 1de8a616a0c..b08b584c3c5 100644 --- a/sonar-deprecated/src/main/java/org/sonar/api/checks/templates/XmlCheckTemplateFactory.java +++ b/sonar-deprecated/src/main/java/org/sonar/api/checks/templates/XmlCheckTemplateFactory.java @@ -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 +} diff --git a/sonar-deprecated/src/main/java/org/sonar/api/rules/StandardRulesXmlParser.java b/sonar-deprecated/src/main/java/org/sonar/api/rules/StandardRulesXmlParser.java index 58b8c69abbc..82889c80c66 100644 --- a/sonar-deprecated/src/main/java/org/sonar/api/rules/StandardRulesXmlParser.java +++ b/sonar-deprecated/src/main/java/org/sonar/api/rules/StandardRulesXmlParser.java @@ -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; diff --git a/sonar-deprecated/src/test/java/org/sonar/api/rules/StandardRulesXmlParserTest.java b/sonar-deprecated/src/test/java/org/sonar/api/rules/StandardRulesXmlParserTest.java index cdccbf1875b..25a408ce089 100644 --- a/sonar-deprecated/src/test/java/org/sonar/api/rules/StandardRulesXmlParserTest.java +++ b/sonar-deprecated/src/test/java/org/sonar/api/rules/StandardRulesXmlParserTest.java @@ -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 diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/rules/AnnotationRuleParser.java b/sonar-plugin-api/src/main/java/org/sonar/api/rules/AnnotationRuleParser.java index d40dc943553..619a01c3c7e 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/rules/AnnotationRuleParser.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/rules/AnnotationRuleParser.java @@ -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) { 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 d257ef39a2f..618d0e6fb46 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 @@ -124,7 +124,7 @@ public final class Rule { }
/**
- * @deprecated Use the factory method {@link #create()}
+ * @deprecated since 2.3. Use the factory method {@link #create()}
*/
@Deprecated
public Rule(String name, String key, RulesCategory rulesCategory, String pluginName, String description) {
@@ -154,7 +154,7 @@ public final class Rule { }
/**
- * @deprecated visibility should be decreased to protected or package
+ * @deprecated since 2.3. visibility should be decreased to protected or package
*/
@Deprecated
public void setId(Integer id) {
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/rules/XMLRuleParser.java b/sonar-plugin-api/src/main/java/org/sonar/api/rules/XMLRuleParser.java index adc70ff30e5..8eadd746680 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/rules/XMLRuleParser.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/rules/XMLRuleParser.java @@ -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)))); diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/profiles/RulesProfileTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/profiles/RulesProfileTest.java index 3f36241a437..0e54a3a824d 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/profiles/RulesProfileTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/profiles/RulesProfileTest.java @@ -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)); } } diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/rules/AnnotationRuleParserTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/rules/AnnotationRuleParserTest.java index 6493581677b..c48445bfbec 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/rules/AnnotationRuleParserTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/rules/AnnotationRuleParserTest.java @@ -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) { diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/rules/RuleTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/rules/RuleTest.java index c0767fda0ad..56285ed10f2 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/rules/RuleTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/rules/RuleTest.java @@ -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"); } - } diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/rules/XMLRuleParserTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/rules/XMLRuleParserTest.java index 02027741ceb..dab65bfc564 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/rules/XMLRuleParserTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/rules/XMLRuleParserTest.java @@ -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())); } diff --git a/sonar-server/src/main/java/org/sonar/server/rules/DeprecatedRuleRepositories.java b/sonar-server/src/main/java/org/sonar/server/rules/DeprecatedRuleRepositories.java index b3bc7f1a9c7..55de2e4efb5 100644 --- a/sonar-server/src/main/java/org/sonar/server/rules/DeprecatedRuleRepositories.java +++ b/sonar-server/src/main/java/org/sonar/server/rules/DeprecatedRuleRepositories.java @@ -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) { diff --git a/sonar-server/src/main/java/org/sonar/server/startup/RegisterRules.java b/sonar-server/src/main/java/org/sonar/server/startup/RegisterRules.java index 6526d1d04fd..c222152667c 100644 --- a/sonar-server/src/main/java/org/sonar/server/startup/RegisterRules.java +++ b/sonar-server/src/main/java/org/sonar/server/startup/RegisterRules.java @@ -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()); diff --git a/sonar-server/src/test/java/org/sonar/server/rules/DeprecatedProfilesTest.java b/sonar-server/src/test/java/org/sonar/server/rules/DeprecatedProfilesTest.java index 187a3ed8e1f..7ae3f3bcda0 100644 --- a/sonar-server/src/test/java/org/sonar/server/rules/DeprecatedProfilesTest.java +++ b/sonar-server/src/test/java/org/sonar/server/rules/DeprecatedProfilesTest.java @@ -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)); } } diff --git a/sonar-server/src/test/java/org/sonar/server/startup/RegisterRulesTest.java b/sonar-server/src/test/java/org/sonar/server/startup/RegisterRulesTest.java index 2f76ab1d3bd..a43aa3403b1 100644 --- a/sonar-server/src/test/java/org/sonar/server/startup/RegisterRulesTest.java +++ b/sonar-server/src/test/java/org/sonar/server/startup/RegisterRulesTest.java @@ -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 +} |