]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-1829: Use severity instead of priority
authorGodin <mandrikov@gmail.com>
Tue, 7 Dec 2010 16:12:03 +0000 (16:12 +0000)
committerGodin <mandrikov@gmail.com>
Tue, 7 Dec 2010 16:12:03 +0000 (16:12 +0000)
19 files changed:
plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleProfileExporter.java
plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleProfileImporter.java
plugins/sonar-checkstyle-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleProfileImporterTest.java
plugins/sonar-pmd-plugin/src/main/java/org/sonar/plugins/pmd/PmdProfileExporter.java
plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/PmdProfileImporterTest.java
sonar-batch/src/main/java/org/sonar/batch/CheckProfileProvider.java
sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java
sonar-deprecated/src/test/java/org/sonar/api/rules/StandardProfileXmlParserTest.java
sonar-plugin-api/src/main/java/org/sonar/api/profiles/RulesProfile.java
sonar-plugin-api/src/main/java/org/sonar/api/profiles/XMLProfileSerializer.java
sonar-plugin-api/src/test/java/org/sonar/api/profiles/AnnotationProfileParserTest.java
sonar-plugin-api/src/test/java/org/sonar/api/profiles/XMLProfileParserTest.java
sonar-server/src/main/java/org/sonar/server/configuration/ProfilesBackup.java
sonar-server/src/main/java/org/sonar/server/rules/DeprecatedProfiles.java
sonar-server/src/main/java/org/sonar/server/rules/ProfilesConsole.java
sonar-server/src/main/java/org/sonar/server/startup/RegisterMetrics.java
sonar-server/src/main/java/org/sonar/server/startup/RegisterProvidedProfiles.java
sonar-server/src/main/java/org/sonar/server/ui/CodeColorizers.java
sonar-server/src/test/java/org/sonar/server/configuration/BackupTest.java

index 3be0002210620d6bde7b1a7da4ad6680060c155d..a44b578c769e98fa9ff3db429f03750b29556fd1 100644 (file)
@@ -139,7 +139,7 @@ public class CheckstyleProfileExporter extends ProfileExporter {
     if (activeRule.getRule().getParent() != null) {
       appendModuleProperty(writer, "id", activeRule.getRuleKey());
     }
-    appendModuleProperty(writer, "severity", CheckstyleSeverityUtils.toSeverity(activeRule.getPriority()));
+    appendModuleProperty(writer, "severity", CheckstyleSeverityUtils.toSeverity(activeRule.getSeverity()));
     appendRuleParameters(writer, activeRule);
     writer.append("</module>");
   }
@@ -163,5 +163,4 @@ public class CheckstyleProfileExporter extends ProfileExporter {
     }
   }
 
-
 }
index 1766e0fb79e91a789a787f23500d678a451aec64..0fef160a0f24a20974a256a7fe9aa82f0a533630 100644 (file)
@@ -36,6 +36,7 @@ import org.sonar.api.utils.ValidationMessages;
 
 import javax.xml.stream.XMLInputFactory;
 import javax.xml.stream.XMLStreamException;
+
 import java.io.Reader;
 import java.util.Map;
 
@@ -147,7 +148,7 @@ public class CheckstyleProfileImporter extends ProfileImporter {
   private void activateProperties(ActiveRule activeRule, Map<String, String> properties) {
     for (Map.Entry<String, String> property : properties.entrySet()) {
       if (StringUtils.equals("severity", property.getKey())) {
-        activeRule.setPriority(CheckstyleSeverityUtils.fromSeverity(property.getValue()));
+        activeRule.setSeverity(CheckstyleSeverityUtils.fromSeverity(property.getValue()));
 
       } else if (!StringUtils.equals("id", property.getKey())) {
         activeRule.setParameter(property.getKey(), property.getValue());
index 330698acc3a5da64977eae36cce9d4bfb00b2861..f3d4a41c1ffc8d905f17762a9dbd794f445eec0b 100644 (file)
@@ -88,7 +88,7 @@ public class CheckstyleProfileImporterTest {
     RulesProfile profile = importer.importProfile(reader, messages);
 
     ActiveRule javadocCheck = profile.getActiveRuleByConfigKey("checkstyle", "Checker/JavadocPackage");
-    assertThat(javadocCheck.getPriority(), is(RulePriority.BLOCKER));
+    assertThat(javadocCheck.getSeverity(), is(RulePriority.BLOCKER));
   }
 
   @Test
@@ -97,7 +97,7 @@ public class CheckstyleProfileImporterTest {
     RulesProfile profile = importer.importProfile(reader, messages);
 
     ActiveRule activeRule = profile.getActiveRuleByConfigKey("checkstyle", "Checker/TreeWalker/EqualsHashCode");
-    assertThat(activeRule.getPriority(), is(RulePriority.BLOCKER)); // reuse the rule default priority
+    assertThat(activeRule.getSeverity(), is(RulePriority.BLOCKER)); // reuse the rule default priority
   }
 
   @Test
index b2dc55984a6e8a7c17d2623c0cde5730955a866a..dd72f846a1c35c0f91abf21a07f686e312b31c02 100644 (file)
@@ -65,7 +65,7 @@ public class PmdProfileExporter extends ProfileExporter {
     for (ActiveRule activeRule : activeRules) {
       if (activeRule.getRule().getPluginName().equals(CoreProperties.PMD_PLUGIN)) {
         String configKey = activeRule.getRule().getConfigKey();
-        PmdRule rule = new PmdRule(configKey, PmdLevelUtils.toLevel(activeRule.getPriority()));
+        PmdRule rule = new PmdRule(configKey, PmdLevelUtils.toLevel(activeRule.getSeverity()));
         if (activeRule.getActiveRuleParams() != null && !activeRule.getActiveRuleParams().isEmpty()) {
           List<PmdProperty> properties = new ArrayList<PmdProperty>();
           for (ActiveRuleParam activeRuleParam : activeRule.getActiveRuleParams()) {
index 41064bec01289ba5399bebb9edef049de14e66b5..5a73f5014489190545dd694f5ec65c1c2abc3565 100644 (file)
@@ -95,7 +95,7 @@ public class PmdProfileImporterTest {
     RulesProfile profile = importer.importProfile(reader, messages);
 
     ActiveRule activeRule = profile.getActiveRuleByConfigKey("pmd", "rulesets/coupling.xml/ExcessiveImports");
-    assertThat(activeRule.getPriority(), is(RulePriority.BLOCKER)); // reuse the rule default priority
+    assertThat(activeRule.getSeverity(), is(RulePriority.BLOCKER)); // reuse the rule default priority
   }
 
   @Test
@@ -104,10 +104,10 @@ public class PmdProfileImporterTest {
     RulesProfile profile = importer.importProfile(reader, messages);
 
     ActiveRule activeRule = profile.getActiveRuleByConfigKey("pmd", "rulesets/design.xml/UseNotifyAllInsteadOfNotify");
-    assertThat(activeRule.getPriority(), is(RulePriority.MINOR));
+    assertThat(activeRule.getSeverity(), is(RulePriority.MINOR));
 
     activeRule = profile.getActiveRuleByConfigKey("pmd", "rulesets/coupling.xml/CouplingBetweenObjects");
-    assertThat(activeRule.getPriority(), is(RulePriority.CRITICAL));
+    assertThat(activeRule.getSeverity(), is(RulePriority.CRITICAL));
   }
 
   @Test
index 3ec7d8b522b127efd65993d7f3a87e334e1ab8ef..3046aa96eb44d019c1526c3ba7b4bfb06913023f 100644 (file)
@@ -47,7 +47,7 @@ public class CheckProfileProvider extends ProviderAdapter {
 
   private Check toCheck(ActiveRule activeRule) {
     Check check = new Check(activeRule.getPluginName(), activeRule.getRuleKey());
-    check.setPriority(activeRule.getPriority().toCheckPriority());
+    check.setPriority(activeRule.getSeverity().toCheckPriority());
     check.setProperties(toParameters(activeRule.getActiveRuleParams()));
     return check;
   }
index ce98655f0238c2997b98950e4acfe358e272f3cc..324f8f0f01b91a9581c650257e993df4d43eb215 100644 (file)
@@ -404,7 +404,7 @@ public final class DefaultIndex extends SonarIndex {
           }
 
         } else {
-          violation.setPriority(activeRule.getPriority());
+          violation.setPriority(activeRule.getSeverity());
           doAddViolation(violation, bucket);
         }
       }
index 2f20bd096ca22f4f2e9108310ffae820045bdf94..586961d0dcad1dc8b122464f75baf1e1667de465 100644 (file)
@@ -20,9 +20,6 @@
 package org.sonar.api.rules;
 
 import org.apache.commons.io.IOUtils;
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.*;
-
 import org.hamcrest.CoreMatchers;
 import org.junit.Assert;
 import org.junit.Test;
@@ -37,6 +34,12 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+
 public class StandardProfileXmlParserTest {
 
   @Test
@@ -136,7 +139,6 @@ public class StandardProfileXmlParserTest {
     return rules;
   }
 
-
   private List<ActiveRule> buildActiveRulesFixture(List<Rule> rules) {
     List<ActiveRule> activeRules = new ArrayList<ActiveRule>();
 
@@ -157,7 +159,7 @@ public class StandardProfileXmlParserTest {
     for (int i = 0; i < activeRules1.size(); i++) {
       ActiveRule activeRule1 = activeRules1.get(i);
       ActiveRule activeRule2 = activeRules2.get(i);
-      assertTrue(activeRule1.getRule().equals(activeRule2.getRule()) && activeRule1.getPriority().equals(activeRule2.getPriority()));
+      assertTrue(activeRule1.getRule().equals(activeRule2.getRule()) && activeRule1.getSeverity().equals(activeRule2.getSeverity()));
 
       Assert.assertEquals(activeRule1.getActiveRuleParams().size(), (activeRule2.getActiveRuleParams().size()));
       for (int j = 0; j < activeRule1.getActiveRuleParams().size(); j++) {
@@ -169,4 +171,4 @@ public class StandardProfileXmlParserTest {
     }
   }
 
-}
\ No newline at end of file
+}
index 3ed3125a2c138c25b4fa5258a1a9b531e7bb397b..01d91243bbb2b9304daf7ff99b0bfcb30f0c8883 100644 (file)
@@ -224,7 +224,7 @@ public class RulesProfile implements Cloneable {
   public List<ActiveRule> getActiveRules(RulePriority priority) {
     List<ActiveRule> result = new ArrayList<ActiveRule>();
     for (ActiveRule activeRule : getActiveRules()) {
-      if (activeRule.getPriority().equals(priority)) {
+      if (activeRule.getSeverity().equals(priority)) {
         result.add(activeRule);
       }
     }
index e670002e96834b714b79e335a10a9295fc33a7e4..263c8171f010f42594ea391de401d1c495ac89f8 100644 (file)
@@ -71,9 +71,9 @@ public final class XMLProfileSerializer implements ServerComponent {
     writer.append("</repositoryKey><key>");
     StringEscapeUtils.escapeXml(writer, activeRule.getRuleKey());
     writer.append("</key>");
-    if (activeRule.getPriority() != null) {
+    if (activeRule.getSeverity() != null) {
       writer.append("<priority>");
-      writer.append(activeRule.getPriority().name());
+      writer.append(activeRule.getSeverity().name());
       writer.append("</priority>");
     }
     appendRuleParameters(activeRule, writer);
index c30131645f262ea3f6a3af12fe80adf5fa75ce14..f80beac42c7c2c1d84fd237ba7d414fa13bf5efd 100644 (file)
@@ -31,7 +31,9 @@ import org.sonar.check.BelongsToProfile;
 import org.sonar.check.Priority;
 
 import static org.hamcrest.Matchers.is;
-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.anyString;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
@@ -48,11 +50,11 @@ public class AnnotationProfileParserTest {
     });
 
     ValidationMessages messages = ValidationMessages.create();
-    RulesProfile profile = new AnnotationProfileParser(ruleFinder).parse("squid", "Foo way", "java", Lists.<Class>newArrayList(FakeRule.class), messages);
+    RulesProfile profile = new AnnotationProfileParser(ruleFinder).parse("squid", "Foo way", "java", Lists.<Class> newArrayList(FakeRule.class), messages);
 
     assertThat(profile.getName(), is("Foo way"));
     assertThat(profile.getLanguage(), is("java"));
-    assertThat(profile.getActiveRule("squid", "fake").getPriority(), is(RulePriority.BLOCKER));
+    assertThat(profile.getActiveRule("squid", "fake").getSeverity(), is(RulePriority.BLOCKER));
     assertThat(messages.hasErrors(), is(false));
   }
 
@@ -66,7 +68,7 @@ public class AnnotationProfileParserTest {
     });
 
     ValidationMessages messages = ValidationMessages.create();
-    RulesProfile profile = new AnnotationProfileParser(ruleFinder).parse("squid", "Foo way", "java", Lists.<Class>newArrayList(FakeRule.class, RuleOnOtherProfile.class), messages);
+    RulesProfile profile = new AnnotationProfileParser(ruleFinder).parse("squid", "Foo way", "java", Lists.<Class> newArrayList(FakeRule.class, RuleOnOtherProfile.class), messages);
 
     assertNotNull(profile.getActiveRule("squid", "fake"));
     assertNull(profile.getActiveRule("squid", "other"));
index 3167cb941b402510b6123fcf8267084fbacb5484..6c31b9d268855cd6a249c5cb2d24eda2bcb50b9d 100644 (file)
@@ -51,7 +51,7 @@ public class XMLProfileParserTest {
     assertThat(profile.getName(), is("sonar way"));
     assertThat(validation.hasErrors(), is(false));
     assertNotNull(profile);
-    assertThat(profile.getActiveRule("checkstyle", "IllegalRegexp").getPriority(), is(RulePriority.CRITICAL));
+    assertThat(profile.getActiveRule("checkstyle", "IllegalRegexp").getSeverity(), is(RulePriority.CRITICAL));
   }
 
   @Test
@@ -101,4 +101,4 @@ public class XMLProfileParserTest {
     });
     return ruleFinder;
   }
-}
\ No newline at end of file
+}
index 4eb135493a3b0d72eeba5651634b7c419c39bd94..16f84aad30624f6c0f243e35c2d644d1e1cd696f 100644 (file)
@@ -28,12 +28,12 @@ import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
 import org.apache.commons.collections.CollectionUtils;
 import org.slf4j.LoggerFactory;
 import org.sonar.api.database.DatabaseSession;
-import org.sonar.jpa.dao.RulesDao;
-import org.sonar.jpa.dao.ProfilesDao;
 import org.sonar.api.measures.Metric;
 import org.sonar.api.profiles.Alert;
 import org.sonar.api.profiles.RulesProfile;
 import org.sonar.api.rules.*;
+import org.sonar.jpa.dao.ProfilesDao;
+import org.sonar.jpa.dao.RulesDao;
 
 import java.util.*;
 
@@ -164,7 +164,7 @@ public class ProfilesBackup implements Backupable {
         ActiveRule rule = (ActiveRule) source;
         writeNode(writer, "key", rule.getRule().getKey());
         writeNode(writer, "plugin", rule.getRule().getPluginName());
-        writeNode(writer, "level", rule.getPriority().name());
+        writeNode(writer, "level", rule.getSeverity().name());
 
         if (!rule.getActiveRuleParams().isEmpty()) {
           writer.startNode("params");
index 90cf7cb06519b5a2a441a0f2e0fe9a3ef5d36635..ee0628f76dc24ed452d3cd47d78f5fe21578edb3 100644 (file)
@@ -72,7 +72,7 @@ public final class DeprecatedProfiles {
     this.deprecatedCheckProfiles = new CheckProfile[0];
     this.deprecatedCheckProfileProviders = new CheckProfileProvider[0];
   }
-  
+
   public DeprecatedProfiles(Plugins plugins, RuleFinder ruleFinder) {
     this.deprecatedRepositories = new RulesRepository[0];
     this.plugins = plugins;
@@ -110,7 +110,7 @@ public final class DeprecatedProfiles {
         }
         Rule rule = ruleFinder.findByKey(repositoryKey, deprecatedActiveRule.getRuleKey());
         if (rule != null) {
-          ActiveRule activeRule = providedProfile.activateRule(rule, deprecatedActiveRule.getPriority());
+          ActiveRule activeRule = providedProfile.activateRule(rule, deprecatedActiveRule.getSeverity());
           for (ActiveRuleParam arp : deprecatedActiveRule.getActiveRuleParams()) {
             activeRule.setParameter(arp.getKey(), arp.getValue());
           }
@@ -164,7 +164,6 @@ public final class DeprecatedProfiles {
       return profile.getActiveRules();
     }
 
-
     public List<ActiveRule> getRulesByRepositoryKey(String repositoryKey) {
       return profile.getActiveRulesByRepository(repositoryKey);
     }
index 20b9605c86385bea812cc0d3363b29dddb5634f0..8217194761ab66243420565a393ff2d0a06b3b1a 100644 (file)
@@ -26,7 +26,6 @@ import org.sonar.api.database.DatabaseSession;
 import org.sonar.api.profiles.*;
 import org.sonar.api.rules.ActiveRule;
 import org.sonar.api.rules.ActiveRuleParam;
-import org.sonar.api.rules.RuleFinder;
 import org.sonar.api.utils.ValidationMessages;
 import org.sonar.jpa.session.DatabaseSessionFactory;
 
@@ -143,7 +142,7 @@ public final class ProfilesConsole implements ServerComponent {
       DatabaseSession session = sessionFactory.getSession();
       RulesProfile persistedProfile = session.getSingleResult(RulesProfile.class, "name", profileName, "language", language);
       for (ActiveRule activeRule : profile.getActiveRules()) {
-        ActiveRule persistedActiveRule = persistedProfile.activateRule(activeRule.getRule(), activeRule.getPriority());
+        ActiveRule persistedActiveRule = persistedProfile.activateRule(activeRule.getRule(), activeRule.getSeverity());
         for (ActiveRuleParam activeRuleParam : activeRule.getActiveRuleParams()) {
           persistedActiveRule.setParameter(activeRuleParam.getKey(), activeRuleParam.getValue());
         }
index 4e9ea3d96cadea11082519422a902cdaee85fd45..769371519e6b328490d4ac854389b181d0530273 100644 (file)
  */\r
 package org.sonar.server.startup;\r
 \r
+import com.google.common.collect.Lists;\r
+import com.google.common.collect.Maps;\r
 import org.sonar.api.database.DatabaseSession;\r
 import org.sonar.api.measures.CoreMetrics;\r
 import org.sonar.api.measures.Metric;\r
 import org.sonar.api.measures.Metrics;\r
-import org.sonar.api.platform.PluginRepository;\r
 import org.sonar.api.profiles.Alert;\r
 import org.sonar.api.utils.Logs;\r
 import org.sonar.api.utils.TimeProfiler;\r
 import org.sonar.jpa.dao.MeasuresDao;\r
 import org.sonar.server.platform.ServerStartException;\r
 \r
-import com.google.common.collect.Lists;\r
-import com.google.common.collect.Maps;\r
+import javax.persistence.Query;\r
 \r
-import java.util.ArrayList;\r
-import java.util.HashMap;\r
 import java.util.List;\r
 import java.util.Map;\r
 \r
-import javax.persistence.Query;\r
-\r
 public class RegisterMetrics {\r
 \r
   private MeasuresDao measuresDao;\r
index 82f0c94de889ad316555d64b229a3485a3e390b7..144e813f3709656be56961867951b02246575d35 100644 (file)
@@ -113,7 +113,6 @@ public final class RegisterProvidedProfiles {
     profiler.stop();
   }
 
-
   void saveProvidedProfiles(List<RulesProfile> profiles, DatabaseSession session) {
     for (RulesProfile profile : profiles) {
       TimeProfiler profiler = new TimeProfiler().start("Save profile " + profile);
@@ -121,7 +120,7 @@ public final class RegisterProvidedProfiles {
 
       for (ActiveRule activeRule : profile.getActiveRules()) {
         Rule rule = getPersistedRule(activeRule);
-        ActiveRule persistedRule = persistedProfile.activateRule(rule, activeRule.getPriority());
+        ActiveRule persistedRule = persistedProfile.activateRule(rule, activeRule.getSeverity());
         for (RuleParam param : rule.getParams()) {
           String value = StringUtils.defaultString(activeRule.getParameter(param.getKey()), param.getDefaultValue());
           if (value != null) {
@@ -139,11 +138,11 @@ public final class RegisterProvidedProfiles {
 
   Rule getPersistedRule(ActiveRule activeRule) {
     Rule rule = activeRule.getRule();
-    if (rule!=null && rule.getId()==null) {
-      if (rule.getKey()!=null) {
+    if (rule != null && rule.getId() == null) {
+      if (rule.getKey() != null) {
         rule = ruleFinder.findByKey(rule.getRepositoryKey(), rule.getKey());
 
-      } else if (rule.getConfigKey()!=null) {
+      } else if (rule.getConfigKey() != null) {
         rule = ruleFinder.find(RuleQuery.create().withRepositoryKey(rule.getRepositoryKey()).withConfigKey(rule.getConfigKey()));
       }
     }
index cb43e13accbe01d079464022356b82cda52f8cf2..87e5ca667ce1876e442ace6dd487451693eb5d26 100644 (file)
  */
 package org.sonar.server.ui;
 
-import java.io.StringReader;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
 import org.apache.commons.lang.StringUtils;
 import org.sonar.api.ServerExtension;
 import org.sonar.api.utils.Logs;
 import org.sonar.api.web.CodeColorizerFormat;
-import org.sonar.channel.Channel;
 import org.sonar.colorizer.CodeColorizer;
-import org.sonar.colorizer.HtmlCodeBuilder;
 import org.sonar.colorizer.HtmlOptions;
 import org.sonar.colorizer.Tokenizer;
 
+import java.io.StringReader;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
 public class CodeColorizers implements ServerExtension {
 
   private Map<String, CodeColorizerFormat> formatPerLanguage;
index 4bcc6d92584aff54a86374407f45dc77685810dd..0a9029e2334935456d59c622db5dee9e6eb0f46c 100644 (file)
@@ -118,7 +118,7 @@ public class BackupTest {
     assertEquals(1, testProfile.getActiveRules().size());
 
     ActiveRule testActiveRule = testProfile.getActiveRules().get(0);
-    assertEquals(RulePriority.MAJOR, testActiveRule.getPriority());
+    assertEquals(RulePriority.MAJOR, testActiveRule.getSeverity());
     assertNotNull(testActiveRule.getRule());
     assertEquals("test key", testActiveRule.getRule().getKey());
     assertEquals("test plugin", testActiveRule.getRule().getPluginName());