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>");
}
}
}
-
}
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
+
import java.io.Reader;
import java.util.Map;
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());
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
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
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()) {
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
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
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;
}
}
} else {
- violation.setPriority(activeRule.getPriority());
+ violation.setPriority(activeRule.getSeverity());
doAddViolation(violation, bucket);
}
}
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;
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
return rules;
}
-
private List<ActiveRule> buildActiveRulesFixture(List<Rule> rules) {
List<ActiveRule> activeRules = new ArrayList<ActiveRule>();
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++) {
}
}
-}
\ No newline at end of file
+}
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);
}
}
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);
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;
});
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));
}
});
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"));
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
});
return ruleFinder;
}
-}
\ No newline at end of file
+}
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.*;
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");
this.deprecatedCheckProfiles = new CheckProfile[0];
this.deprecatedCheckProfileProviders = new CheckProfileProvider[0];
}
-
+
public DeprecatedProfiles(Plugins plugins, RuleFinder ruleFinder) {
this.deprecatedRepositories = new RulesRepository[0];
this.plugins = plugins;
}
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());
}
return profile.getActiveRules();
}
-
public List<ActiveRule> getRulesByRepositoryKey(String repositoryKey) {
return profile.getActiveRulesByRepository(repositoryKey);
}
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;
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());
}
*/\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
profiler.stop();
}
-
void saveProvidedProfiles(List<RulesProfile> profiles, DatabaseSession session) {
for (RulesProfile profile : profiles) {
TimeProfiler profiler = new TimeProfiler().start("Save profile " + profile);
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) {
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()));
}
}
*/
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;
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());