use of org.sonar.api.utils.ValidationMessages in project sonarqube by SonarSource.
the class FakeRule method shouldParseOnlyWantedProfile.
@Test
public void shouldParseOnlyWantedProfile() {
RuleFinder ruleFinder = mock(RuleFinder.class);
when(ruleFinder.findByKey(anyString(), anyString())).thenAnswer(new Answer<Rule>() {
public Rule answer(InvocationOnMock iom) throws Throwable {
return Rule.create((String) iom.getArguments()[0], (String) iom.getArguments()[1], (String) iom.getArguments()[1]);
}
});
ValidationMessages messages = ValidationMessages.create();
RulesProfile profile = new AnnotationProfileParser(ruleFinder).parse("squid", "Foo way", "java", Lists.<Class>newArrayList(FakeRule.class, RuleOnOtherProfile.class), messages);
assertThat(profile.getActiveRule("squid", "fake")).isNotNull();
assertThat(profile.getActiveRule("squid", "other")).isNull();
}
use of org.sonar.api.utils.ValidationMessages in project sonarqube by SonarSource.
the class FakeRule method shouldParseAnnotatedClasses.
@Test
public void shouldParseAnnotatedClasses() {
RuleFinder ruleFinder = mock(RuleFinder.class);
when(ruleFinder.findByKey(anyString(), anyString())).thenAnswer(new Answer<Rule>() {
public Rule answer(InvocationOnMock iom) throws Throwable {
return Rule.create((String) iom.getArguments()[0], (String) iom.getArguments()[1], (String) iom.getArguments()[1]);
}
});
ValidationMessages messages = ValidationMessages.create();
RulesProfile profile = new AnnotationProfileParser(ruleFinder).parse("squid", "Foo way", "java", Lists.<Class>newArrayList(FakeRule.class), messages);
assertThat(profile.getName()).isEqualTo("Foo way");
assertThat(profile.getLanguage()).isEqualTo("java");
assertThat(profile.getActiveRule("squid", "fake").getSeverity()).isEqualTo(RulePriority.BLOCKER);
assertThat(messages.hasErrors()).isFalse();
}
use of org.sonar.api.utils.ValidationMessages in project sonarqube by SonarSource.
the class DeprecatedRulesDefinitionLoader method loadRuleDebtsFromXml.
public List<RuleDebt> loadRuleDebtsFromXml(String pluginKey) {
Reader xmlFileReader = null;
try {
xmlFileReader = languageModelFinder.createReaderForXMLFile(pluginKey);
ValidationMessages validationMessages = ValidationMessages.create();
List<RuleDebt> rules = importer.importXML(xmlFileReader, validationMessages);
validationMessages.log(LOG);
return rules;
} finally {
IOUtils.closeQuietly(xmlFileReader);
}
}
use of org.sonar.api.utils.ValidationMessages in project sonarqube by SonarSource.
the class RegisterQualityProfiles method profilesByLanguage.
/**
* @return profiles by language
*/
private ListMultimap<String, RulesProfile> profilesByLanguage() {
ListMultimap<String, RulesProfile> byLang = ArrayListMultimap.create();
for (ProfileDefinition definition : definitions) {
ValidationMessages validation = ValidationMessages.create();
RulesProfile profile = definition.createProfile(validation);
validation.log(LOGGER);
if (profile != null && !validation.hasErrors()) {
byLang.put(StringUtils.lowerCase(profile.getLanguage()), profile);
}
}
return byLang;
}
use of org.sonar.api.utils.ValidationMessages in project sonarlint-core by SonarSource.
the class StandaloneActiveRulesProvider method profilesByLanguage.
private static ListMultimap<String, RulesProfile> profilesByLanguage(ProfileDefinition[] profileDefinitions) {
ListMultimap<String, RulesProfile> byLang = ArrayListMultimap.create();
for (ProfileDefinition definition : profileDefinitions) {
ValidationMessages validation = ValidationMessages.create();
RulesProfile profile = definition.createProfile(validation);
if (profile != null && !validation.hasErrors()) {
byLang.put(StringUtils.lowerCase(profile.getLanguage()), profile);
}
}
return byLang;
}
Aggregations